📄 keydef.java
字号:
package com.workingdogs.town;
import java.util.Vector;
/*
Town, a Java JDBC abstraction layer
Copyright (C) 1999 Serge Knystautas, Jon S. Stevens
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/**
A KeyDef is a way to define the key columns in a table. The KeyDef is
generally used in conjunction with a <a href="TableDataSet.html">TableDataSet</a>.
Essentially a KeyDef is what forms the WHERE clause for an UPDATE or DELETE.
<P>
In order to use the KeyDef, you simply use it like this:
<PRE>
KeyDef kd = new KeyDef().addAttrib("key_column_a");
TableDataSet tds = new TableDataSet ( connection, "table", kd );
Record rec = tds.getRecord(0);
rec.setValue("column_name", "new value" );
rec.save();
tds.close();
</PRE>
In the above example, Record 0 is retrieved from the database table
and the following update statement is generated:
<P>
UPDATE table SET column_name=? WHERE key_column_a=?
<P>
@author Jon S. Stevens <A HREF="mailto:jon@working-dogs.com">jon@working-dogs.com</A>
@author Serge Knystautas <a href="mailto:sergek@lokitech.com">sergek@lokitech.com</a>
@version 1.0
*/
public class KeyDef
{
Vector data = new Vector ();
public KeyDef()
{
super();
// KeyDef is 1 based.
data.addElement ("");
}
/**
Adds the named attribute to the KeyDef.
@returns a copy of itself
*/
public KeyDef addAttrib(String name)
{
data.addElement (name);
return this;
}
/**
Determines if the KeyDef contains the requested Attribute.
@returns true if the attribute has been defined. false otherwise.
*/
public boolean containsAttrib (String name)
{
return !(data.indexOf ((Object) name) == -1);
}
/**
getAttrib is 1 based. Setting pos to 0 will attempt to return pos 1.
@returns value of Attribute at pos as String. null if value is not found.
*/
public String getAttrib (int pos)
{
if (pos == 0)
pos = 1;
try
{
return (String) data.elementAt (pos);
}
catch (ArrayIndexOutOfBoundsException e)
{
return null;
}
}
/**
KeyDef's are 1 based, so this overrides the Vector.size() method and
returns size - 1;
@returns the number of elements in the KeyDef that were set by addAttrib()
@see #addAttrib(java.lang.String)
*/
public int size()
{
return data.size() - 1;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -