|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.gjt.tw.dbobjects.ObjectMapping
This class provides all necessary information for the mapping of all objects of a class. For each class to be mapped an object of this class has to be created and initialized. This typically happens inside a static .init() method of that class (see examples in test package).
Field Summary | |
static int |
AUTOINCREMENT_GENERIC
Description of the Field |
static int |
AUTOINCREMENT_MYSQL
Description of the Field |
static int |
AUTOINCREMENT_NONE
Description of the Field |
Constructor Summary | |
ObjectMapping()
ObjectMapping constructor. |
Method Summary | |
void |
addField(java.lang.String fieldName,
java.lang.Class fieldClass,
java.lang.String columnName)
This method adds one of the object's fields to the fields that are mapped. |
void |
prepareSQLStatements()
At the end of initialization this method has to be called. |
void |
setAutoIncrement(int autoIncrement)
Defines which kind of auto increment should be used. |
void |
setKeyField(java.lang.String keyFieldName)
Defines the field that is the key of an database entry. |
void |
setObjectClass(java.lang.Class newValue)
Sets the class of the object. |
void |
setTableName(java.lang.String newValue)
Sets the name of the database table in which objects are stored. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int AUTOINCREMENT_NONE
public static final int AUTOINCREMENT_MYSQL
public static final int AUTOINCREMENT_GENERIC
Constructor Detail |
public ObjectMapping()
Method Detail |
public void setAutoIncrement(int autoIncrement)
It is possible to use MySQL's auto_increment feature (AUTOINCREMENT_MYSQL). If it is used the org.gjt.mm.mysql jdbc drivers must be used, because the ResultSet retrieved from the database is casted to org.gjt.mm.mysql.ResultSet to get the automatically created ID. The statement to create the table has to include auto_increment as a parameter for the key value.
If you use AUTOINCREMENT_GENERIC new keys are created automatically by querying the maximal key used so far
The AUTOINCREMENT_GENERIC feature works fine as long as only a single application (even if multi-threaded) connects to the database at once. If multiple instances try to access the same table at the same time, the first one succeeds while the second one raises an exception. (The reason for this behavior is the use of the sql statement MAX that returns the highest id used to far. Several applications might get the same value for MAX returned from the database before the first application stores the next entry.) If this happens your code should catch the exception and try to save the object again.
Moreover, if auto increment is used the key must be an int or long field.
See the examples in the test packages on how to use this feature.
autoIncrement
- The new autoIncrement valuepublic void setKeyField(java.lang.String keyFieldName)
keyFieldName
- The new keyField valuepublic void setObjectClass(java.lang.Class newValue)
newValue
- java.lang.Classpublic void setTableName(java.lang.String newValue)
newValue
- java.lang.Stringpublic void addField(java.lang.String fieldName, java.lang.Class fieldClass, java.lang.String columnName) throws ObjectException
fieldName
- name of the fieldfieldClass
- class of the fieldcolumnName
- name of the corresponding database columnObjectException
- Description of Exceptionpublic void prepareSQLStatements() throws IncompleteDefinitionException
IncompleteDefinitionException
- Description of Exception
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |