diff --git a/projects/samskivert/src/java/com/samskivert/jdbc/jora/Table.java b/projects/samskivert/src/java/com/samskivert/jdbc/jora/Table.java
index c31ef44f..e80c100a 100644
--- a/projects/samskivert/src/java/com/samskivert/jdbc/jora/Table.java
+++ b/projects/samskivert/src/java/com/samskivert/jdbc/jora/Table.java
@@ -19,12 +19,12 @@ import com.samskivert.util.StringUtil;
/** Table class is used to establish mapping between corteges of database
* tables and Java classes. This class is responsible for constructing
* SQL statements for extracting, updating and deleting records of the
- * database table.
+ * database table.
*/
-public class Table {
- /** Constructor for table object. Make association between Java class
+public class Table {
+ /** Constructor for table object. Make association between Java class
* and database table.
- *
+ *
* @param tclassName name of Java class
* @param tableName name of database table mapped on this Java class
* @param s session, which should be opened before first access to the table
@@ -39,9 +39,9 @@ public class Table {
init(className, tableName, s, keys, mixedCaseConvert);
}
- /** Constructor for table object. Make association between Java class
+ /** Constructor for table object. Make association between Java class
* and database table.
- *
+ *
* @param tclassName name of Java class
* @param tableName name of database table mapped on this Java class
* @param key table's primary key. This parameter is used in UPDATE/DELETE
@@ -53,25 +53,25 @@ public class Table {
init(className, tableName, s, keys, false);
}
- /** Constructor for table object. Make association between Java class
+ /** Constructor for table object. Make association between Java class
* and database table.
- *
+ *
* @param tclassName name of Java class
* @param tableName name of database table mapped on this Java class
* @param keys table primary keys. This parameter is used in UPDATE/DELETE
* operations to locate record in the table.
* @param s session, which should be opened before first access to the table
*/
- public Table(String className, String tableName, Session s, String[] keys)
- {
+ public Table(String className, String tableName, Session s, String[] keys)
+ {
init(className, tableName, s, keys, false);
}
- /** Constructor for table object. Make association between Java class
- * and database table. Name of Java class should be the same as name of
+ /** Constructor for table object. Make association between Java class
+ * and database table. Name of Java class should be the same as name of
* the database table
- *
- * @param className name of Java class, which should be (without
+ *
+ * @param className name of Java class, which should be (without
* package prefix) be the same as the name of database table.
* @param keys table primary keys. This parameter is used in UPDATE/DELETE
* operations to locate record in the table.
@@ -82,11 +82,11 @@ public class Table {
s, keys, false);
}
- /** Constructor for table object. Make association between Java class
- * and database table. Name of Java class should be the same as name of
+ /** Constructor for table object. Make association between Java class
+ * and database table. Name of Java class should be the same as name of
* the database table
- *
- * @param className name of Java class, which should be (without
+ *
+ * @param className name of Java class, which should be (without
* package prefix) be the same as the name of database table.
* @param key table primary key. This parameter is used in UPDATE/DELETE
* operations to locate record in the table.
@@ -99,7 +99,7 @@ public class Table {
}
/** Constructor of table without explicit key specification.
- * Specification of key is necessary for update/remove operations.
+ * Specification of key is necessary for update/remove operations.
* If key is not specified, it is inherited from base table (if any).
*/
public Table(String className, Session s) {
@@ -107,8 +107,8 @@ public class Table {
s, null, false);
}
- /** Constructor of table with "key" and "session" parameters inherited
- * from base table.
+ /** Constructor of table with "key" and "session" parameters inherited
+ * from base table.
*/
public Table(String className) {
init(className, className.substring(className.lastIndexOf('.')+1),
@@ -116,11 +116,11 @@ public class Table {
}
/** Select records from database table according to search condition
- *
+ *
* @param condition valid SQL condition expression started with WHERE
* or empty string if all records should be fetched.
*/
- public final Cursor select(String condition) {
+ public final Cursor select(String condition) {
String query = "select " + listOfFields + " from " + name +
" " + condition;
return new Cursor(this, session, 1, query);
@@ -129,258 +129,258 @@ public class Table {
/** Select records from database table according to search condition
* including the specified (comma separated) extra tables into the
* SELECT clause to facilitate a join in determining the key.
- *
+ *
* @param tables the (comma separated) names of extra tables to
* include in the SELECT clause.
* @param condition valid SQL condition expression started with WHERE.
*/
- public final Cursor select(String tables, String condition) {
+ public final Cursor select(String tables, String condition) {
String query = "select " + qualifiedListOfFields +
" from " + name + "," + tables + " " + condition;
return new Cursor(this, session, 1, query);
}
/** Select records from database table according to search condition
- *
+ *
* @param condition valid SQL condition expression started with WHERE
* or empty string if all records should be fetched.
* @param session user database session
*/
- public final Cursor select(String condition, Session session) {
+ public final Cursor select(String condition, Session session) {
String query = "select " + listOfFields + " from " + name +
" " + condition;
return new Cursor(this, session, 1, query);
}
/** Select records from specified and derived database tables
- *
+ *
* @param condition valid SQL condition expression started with WHERE
* or empty string if all records should be fetched.
*/
- public final Cursor selectAll(String condition) {
+ public final Cursor selectAll(String condition) {
return new Cursor(this, session, nDerived+1, condition);
}
/** Select records from specified and derived database tables
- *
+ *
* @param condition valid SQL condition expression started with WHERE
* or empty string if all records should be fetched.
* @param session user database session
*/
- public final Cursor selectAll(String condition, Session session) {
+ public final Cursor selectAll(String condition, Session session) {
return new Cursor(this, session, nDerived+1, condition);
}
-
- /** Select records from database table using obj object as
+
+ /** Select records from database table using obj object as
* template for selection. All non-builtin fields of this object,
* which are not null, are compared with correspondent table values.
- *
+ *
* @param obj object for construction search condition: selected objects
* should match all non-null fields of specified object.
*/
- public final Cursor queryByExample(Object obj) {
+ public final Cursor queryByExample(Object obj) {
return new Cursor(this, session, 1, obj);
}
- /** Select records from database table using obj object as
+ /** Select records from database table using obj object as
* template for selection. All non-builtin fields of this object,
* which are not null, are compared with correspondent table values.
- *
+ *
* @param obj object for construction search condition: selected objects
* should match all non-null fields of specified object.
* @param session user database session
*/
- public final Cursor queryByExample(Object obj, Session session) {
+ public final Cursor queryByExample(Object obj, Session session) {
return new Cursor(this, session, 1, obj);
}
- /** Select records from specified and derived database tables using
- * obj object as template for selection.
+ /** Select records from specified and derived database tables using
+ * obj object as template for selection.
* All non-builtin fields of this object,
* which are not null, are compared with correspondent table values.
- *
+ *
* @param obj object for construction search condition: selected objects
* should match all non-null fields of specified object.
*/
- public final Cursor queryAllByExample(Object obj) {
+ public final Cursor queryAllByExample(Object obj) {
return new Cursor(this, session, nDerived+1, obj);
}
- /** Select records from specified and derived database tables using
- * obj object as template for selection.
+ /** Select records from specified and derived database tables using
+ * obj object as template for selection.
* All non-builtin fields of this object,
* which are not null, are compared with correspondent table values.
- *
+ *
* @param obj object for construction search condition: selected objects
* should match all non-null fields of specified object.
* @param session user database session
*/
- public final Cursor queryAllByExample(Object obj, Session session) {
+ public final Cursor queryAllByExample(Object obj, Session session) {
return new Cursor(this, session, nDerived+1, obj);
}
- /** Insert new record in the table. Values of inserted record fields
+ /** Insert new record in the table. Values of inserted record fields
* are taken from specifed object.
- *
+ *
* @param obj object specifing values of inserted record fields
*/
public void insert(Object obj)
throws SQLException
- {
+ {
insert(obj, session);
}
- /** Insert new record in the table using specified database session.
- * Values of inserted record fields
+ /** Insert new record in the table using specified database session.
+ * Values of inserted record fields
* are taken from specifed object.
- *
+ *
* @param obj object specifing values of inserted record fields
* @param session user database session
*/
public synchronized void insert(Object obj, Session session)
throws SQLException
- {
- if (session == null) {
+ {
+ if (session == null) {
session = ((SessionThread)Thread.currentThread()).session;
}
-// try {
+// try {
checkConnection(session);
- if (insertStmt == null) {
- String sql = "insert into " + name + " ("
+ if (insertStmt == null) {
+ String sql = "insert into " + name + " ("
+ listOfFields + ") values (?";
- for (int i = 1; i < nColumns; i++) {
+ for (int i = 1; i < nColumns; i++) {
sql += ",?";
}
sql += ")";
insertStmt = session.connection.prepareStatement(sql);
}
- bindUpdateVariables(insertStmt, obj);
+ bindUpdateVariables(insertStmt, obj);
insertStmt.executeUpdate();
insertStmt.clearParameters();
// } catch(SQLException ex) { session.handleSQLException(ex); }
}
- /** Insert several new records in the table. Values of inserted records
+ /** Insert several new records in the table. Values of inserted records
* fields are taken from objects of specified array.
- *
- * @param objects array with objects specifing values of inserted record
+ *
+ * @param objects array with objects specifing values of inserted record
* fields
*/
public void insert(Object[] objects)
throws SQLException
- {
+ {
insert(objects, session);
}
-
- /** Insert several new records in the table. Values of inserted records
+
+ /** Insert several new records in the table. Values of inserted records
* fields are taken from objects of specified array.
- *
- * @param objects array with objects specifing values of inserted record
+ *
+ * @param objects array with objects specifing values of inserted record
* fields
* @param session user database session
*/
public synchronized void insert(Object[] objects, Session session)
throws SQLException
- {
- if (session == null) {
+ {
+ if (session == null) {
session = ((SessionThread)Thread.currentThread()).session;
}
-// try {
+// try {
checkConnection(session);
- if (insertStmt == null) {
- String sql = "insert into " + name + " ("
+ if (insertStmt == null) {
+ String sql = "insert into " + name + " ("
+ listOfFields + ") values (?";
- for (int i = 1; i < nColumns; i++) {
+ for (int i = 1; i < nColumns; i++) {
sql += ",?";
}
sql += ")";
insertStmt = session.connection.prepareStatement(sql);
}
- for (int i = 0; i < objects.length; i++) {
- bindUpdateVariables(insertStmt, objects[i]);
+ for (int i = 0; i < objects.length; i++) {
+ bindUpdateVariables(insertStmt, objects[i]);
insertStmt.addBatch();
}
insertStmt.executeBatch();
insertStmt.clearParameters();
// } catch(SQLException ex) { session.handleSQLException(ex); }
}
-
- /** Update record in the table using table's primary key to locate
+
+ /** Update record in the table using table's primary key to locate
* record in the table and values of fields of specified object obj
* to alter record fields.
- *
- * @param obj object specifing value of primary key and new values of
+ *
+ * @param obj object specifing value of primary key and new values of
* updated record fields
- *
+ *
* @return number of objects actually updated
*/
public int update(Object obj)
throws SQLException
- {
+ {
return update(obj, session);
}
- /** Update record in the table using table's primary key to locate
+ /** Update record in the table using table's primary key to locate
* record in the table and values of fields of specified object obj
* to alter record fields.
- *
- * @param obj object specifing value of primary key and new values of
+ *
+ * @param obj object specifing value of primary key and new values of
* updated record fields
* @param session user database session
- *
+ *
* @return number of objects actually updated
*/
public synchronized int update(Object obj, Session session)
throws SQLException
- {
- if (primaryKeys == null) {
+ {
+ if (primaryKeys == null) {
throw new NoPrimaryKeyError(this);
}
- if (session == null) {
+ if (session == null) {
session = ((SessionThread)Thread.currentThread()).session;
}
int nUpdated = 0;
-// try {
+// try {
checkConnection(session);
- if (updateStmt == null) {
- String sql = "update " + name + " set " + listOfAssignments
- + " where " + primaryKeys[0] + " = ?";
- for (int i = 1; i < primaryKeys.length; i++) {
+ if (updateStmt == null) {
+ String sql = "update " + name + " set " + listOfAssignments
+ + " where " + primaryKeys[0] + " = ?";
+ for (int i = 1; i < primaryKeys.length; i++) {
sql += " and " + primaryKeys[i] + " = ?";
}
updateStmt = session.connection.prepareStatement(sql);
}
- for (int i = 0; i < primaryKeys.length; i++) {
- fields[primaryKeyIndices[i]].bindVariable(updateStmt, obj,
+ for (int i = 0; i < primaryKeys.length; i++) {
+ fields[primaryKeyIndices[i]].bindVariable(updateStmt, obj,
nColumns+i+1);
- }
- bindUpdateVariables(updateStmt, obj);
+ }
+ bindUpdateVariables(updateStmt, obj);
nUpdated = updateStmt.executeUpdate();
updateStmt.clearParameters();
// } catch(SQLException ex) { session.handleSQLException(ex); }
return nUpdated;
}
- /** Update set of records in the table using table's primary key to locate
+ /** Update set of records in the table using table's primary key to locate
* record in the table and values of fields of objects from sepecifed
* array objects to alter record fields.
- *
- * @param objects array of objects specifing primiray keys and and new
+ *
+ * @param objects array of objects specifing primiray keys and and new
* values of updated record fields
*
* @return number of objects actually updated
*/
public int update(Object[] objects)
throws SQLException
- {
+ {
return update(objects, session);
}
- /** Update set of records in the table using table's primary key to locate
+ /** Update set of records in the table using table's primary key to locate
* record in the table and values of fields of objects from sepecifed
* array objects to alter record fields.
- *
- * @param objects array of objects specifing primiray keys and and new
+ *
+ * @param objects array of objects specifing primiray keys and and new
* values of updated record fields
* @param session user database session
*
@@ -388,136 +388,135 @@ public class Table {
*/
public synchronized int update(Object[] objects, Session session)
throws SQLException
- {
- if (primaryKeys == null) {
+ {
+ if (primaryKeys == null) {
throw new NoPrimaryKeyError(this);
}
- if (session == null) {
+ if (session == null) {
session = ((SessionThread)Thread.currentThread()).session;
}
int nUpdated = 0;
-// try {
+// try {
checkConnection(session);
- if (updateStmt == null) {
- String sql = "update " + name + " set " + listOfAssignments
- + " where " + primaryKeys[0] + " = ?";
- for (int i = 1; i < primaryKeys.length; i++) {
+ if (updateStmt == null) {
+ String sql = "update " + name + " set " + listOfAssignments
+ + " where " + primaryKeys[0] + " = ?";
+ for (int i = 1; i < primaryKeys.length; i++) {
sql += " and " + primaryKeys[i] + " = ?";
}
updateStmt = session.connection.prepareStatement(sql);
}
- for (int i = 0; i < objects.length; i++) {
- for (int j = 0; j < primaryKeys.length; j++) {
+ for (int i = 0; i < objects.length; i++) {
+ for (int j = 0; j < primaryKeys.length; j++) {
fields[primaryKeyIndices[j]].bindVariable(updateStmt,
objects[i],
nColumns+1+j);
}
- bindUpdateVariables(updateStmt, objects[i]);
+ bindUpdateVariables(updateStmt, objects[i]);
updateStmt.addBatch();
}
int rc[] = updateStmt.executeBatch();
- for (int k = 0; k < rc.length; k++) {
+ for (int k = 0; k < rc.length; k++) {
nUpdated += rc[k];
}
updateStmt.clearParameters();
// } catch(SQLException ex) { session.handleSQLException(ex); }
return nUpdated;
}
-
- /** Delete record with specified value of primary key from the table.
- *
+
+ /** Delete record with specified value of primary key from the table.
+ *
* @param obj object containing value of primary key.
*
* @return number of objects actually deleted
*/
public int delete(Object obj)
throws SQLException
- {
+ {
return delete(obj, session);
}
- /** Delete record with specified value of primary key from the table.
- *
+ /** Delete record with specified value of primary key from the table.
+ *
* @param obj object containing value of primary key.
* @param session user database session
*/
public synchronized int delete(Object obj, Session session)
throws SQLException
- {
- if (primaryKeys == null) {
+ {
+ if (primaryKeys == null) {
throw new NoPrimaryKeyError(this);
}
- if (session == null) {
+ if (session == null) {
session = ((SessionThread)Thread.currentThread()).session;
}
int nDeleted = 0;
-// try {
+// try {
checkConnection(session);
- if (deleteStmt == null) {
- String sql = "delete from " + name +
+ if (deleteStmt == null) {
+ String sql = "delete from " + name +
" where " + primaryKeys[0] + " = ?";
- for (int i = 1; i < primaryKeys.length; i++) {
+ for (int i = 1; i < primaryKeys.length; i++) {
sql += " and " + primaryKeys[i] + " = ?";
}
deleteStmt = session.connection.prepareStatement(sql);
}
- for (int i = 0; i < primaryKeys.length; i++) {
+ for (int i = 0; i < primaryKeys.length; i++) {
fields[primaryKeyIndices[i]].bindVariable(deleteStmt, obj,i+1);
- }
+ }
nDeleted = deleteStmt.executeUpdate();
deleteStmt.clearParameters();
// } catch(SQLException ex) { session.handleSQLException(ex); }
return nDeleted;
}
-
- /** Delete records with specified primary keys from the table.
- *
+ /** Delete records with specified primary keys from the table.
+ *
* @param objects array of objects containing values of primary key.
*
* @return number of objects actually deleted
*/
public int delete(Object[] objects)
throws SQLException
- {
+ {
return delete(objects, session);
}
- /** Delete records with specified primary keys from the table.
- *
+ /** Delete records with specified primary keys from the table.
+ *
* @param objects array of objects containing values of primary key.
*
* @return number of objects actually deleted
*/
public synchronized int delete(Object[] objects, Session session)
throws SQLException
- {
- if (primaryKeys == null) {
+ {
+ if (primaryKeys == null) {
throw new NoPrimaryKeyError(this);
}
- if (session == null) {
+ if (session == null) {
session = ((SessionThread)Thread.currentThread()).session;
}
int nDeleted = 0;
-// try {
+// try {
checkConnection(session);
- if (deleteStmt == null) {
- String sql = "delete from " + name +
- " where " + primaryKeys[0] + " = ?";
- for (int i = 1; i < primaryKeys.length; i++) {
+ if (deleteStmt == null) {
+ String sql = "delete from " + name +
+ " where " + primaryKeys[0] + " = ?";
+ for (int i = 1; i < primaryKeys.length; i++) {
sql += " and " + primaryKeys[i] + " = ?";
}
deleteStmt = session.connection.prepareStatement(sql);
}
- for (int i = 0; i < objects.length; i++) {
- for (int j = 0; j < primaryKeys.length; j++) {
- fields[primaryKeyIndices[j]].bindVariable(deleteStmt,
+ for (int i = 0; i < objects.length; i++) {
+ for (int j = 0; j < primaryKeys.length; j++) {
+ fields[primaryKeyIndices[j]].bindVariable(deleteStmt,
objects[i], j+1);
}
deleteStmt.addBatch();
}
int rc[] = deleteStmt.executeBatch();
- for (int k = 0; k < rc.length; k++) {
+ for (int k = 0; k < rc.length; k++) {
nDeleted += rc[k];
}
deleteStmt.clearParameters();
@@ -538,15 +537,15 @@ public class Table {
/** Spearator of name components of compound field. For example, if Java
* class constains component "location" of Point class, which
* has two components "x" and "y", then database table should
- * have columns "location_x" and "location_y" (if '_' is used
+ * have columns "location_x" and "location_y" (if '_' is used
* as separator)
*/
public static String fieldSeparator = "_";
- /** Some versions of JDBC driver doesn't support
- * getBigDecimal(int columnIndex). Setting this variable to
- * true makes JORA to explicitly request scale from result
+ /** Some versions of JDBC driver doesn't support
+ * getBigDecimal(int columnIndex). Setting this variable to
+ * true makes JORA to explicitly request scale from result
* set metadata and use deprecated version of getBigDecimal
* with extra scale parameter.
*/
@@ -554,7 +553,7 @@ public class Table {
// --- Implementation -----------------------------------------
-
+
/** Is table abstract - not present in database.
*/
protected boolean isAbstract;
@@ -592,22 +591,22 @@ public class Table {
private static final Object[] bypassFlag = { new Boolean(true) };
private static final Object[] constructorArgs = {};
- static {
- try {
+ static {
+ try {
serializableClass = Class.forName("java.io.Serializable");
Class c = Class.forName("java.lang.reflect.AccessibleObject");
Class[] param = { Boolean.TYPE };
setBypass = c.getMethod("setAccessible", param);
} catch(Exception ex) {}
- }
+ }
- private final void init(String className, String tableName, Session s,
- String[] keys, boolean mixedCaseConvert)
+ private final void init(String className, String tableName, Session s,
+ String[] keys, boolean mixedCaseConvert)
{
name = tableName;
this.mixedCaseConvert = mixedCaseConvert;
- try {
+ try {
cls = Class.forName(className);
} catch(ClassNotFoundException ex) {throw new NoClassDefFoundError();}
isAbstract = tableName == null;
@@ -622,28 +621,28 @@ public class Table {
fields = new FieldDescriptor[nFields];
fieldsVector.copyInto(fields);
- try {
+ try {
constructor = cls.getDeclaredConstructor(new Class[0]);
setBypass.invoke(constructor, bypassFlag);
} catch(Exception ex) {}
- if (keys != null) {
- if (keys.length == 0) {
+ if (keys != null) {
+ if (keys.length == 0) {
throw new NoPrimaryKeyError(this);
}
primaryKeyIndices = new int[keys.length];
- for (int j = keys.length; --j >= 0;) {
- int i = nFields;
- while (--i >= 0) {
- if (fields[i].name.equals(keys[j])) {
+ for (int j = keys.length; --j >= 0;) {
+ int i = nFields;
+ while (--i >= 0) {
+ if (fields[i].name.equals(keys[j])) {
if (!fields[i].isAtomic()) {
throw new NoPrimaryKeyError(this);
}
primaryKeyIndices[j] = i;
break;
}
- }
- if (i < 0) {
+ }
+ if (i < 0) {
throw new NoSuchFieldError("No such field '" + keys[j]
+ "' in table " + name);
}
@@ -652,41 +651,40 @@ public class Table {
insertIntoTableHierarchy();
}
-
private final void insertIntoTableHierarchy()
{
Table t, prev = null;
Table after = null;
int nChilds = 0;
- for (t = allTables; t != null; prev = t, t = t.derived) {
- if (t.cls.isAssignableFrom(cls)) {
- if (primaryKeys == null && t.primaryKeys != null) {
+ for (t = allTables; t != null; prev = t, t = t.derived) {
+ if (t.cls.isAssignableFrom(cls)) {
+ if (primaryKeys == null && t.primaryKeys != null) {
primaryKeys = t.primaryKeys;
primaryKeyIndices = t.primaryKeyIndices;
}
- if (session == null) {
+ if (session == null) {
session = t.session;
}
t.nDerived += 1;
after = t;
- } else if (cls.isAssignableFrom(t.cls)) {
+ } else if (cls.isAssignableFrom(t.cls)) {
after = prev;
- do {
- if (cls.isAssignableFrom(t.cls)) {
- if (primaryKeys != null && t.primaryKeys == null) {
+ do {
+ if (cls.isAssignableFrom(t.cls)) {
+ if (primaryKeys != null && t.primaryKeys == null) {
t.primaryKeys = primaryKeys;
t.primaryKeyIndices = primaryKeyIndices;
}
- if (t.session == null) {
+ if (t.session == null) {
t.session = session;
}
nChilds += 1;
}
- } while ((t = t.derived) != null);
+ } while ((t = t.derived) != null);
break;
}
- }
- if (after == null) {
+ }
+ if (after == null) {
derived = allTables;
allTables = this;
} else {
@@ -697,16 +695,16 @@ public class Table {
}
private final void checkConnection(Session s) throws SQLException {
- if (connectionID != s.connectionID) {
- if (insertStmt != null) {
+ if (connectionID != s.connectionID) {
+ if (insertStmt != null) {
insertStmt.close();
insertStmt = null;
}
- if (updateStmt != null) {
+ if (updateStmt != null) {
updateStmt.close();
updateStmt = null;
}
- if (deleteStmt != null) {
+ if (deleteStmt != null) {
deleteStmt.close();
deleteStmt = null;
}
@@ -745,17 +743,17 @@ public class Table {
Field[] f = cls.getDeclaredFields();
Class superclass = cls;
- while ((superclass = superclass.getSuperclass()) != null) {
+ while ((superclass = superclass.getSuperclass()) != null) {
Field[] inheritedFields = superclass.getDeclaredFields();
Field[] allFields = new Field[inheritedFields.length + f.length];
- System.arraycopy(inheritedFields, 0, allFields, 0,
+ System.arraycopy(inheritedFields, 0, allFields, 0,
inheritedFields.length);
System.arraycopy(f,0, allFields, inheritedFields.length, f.length);
f = allFields;
- }
+ }
- try {
- for (int i = f.length; --i>= 0;) {
+ try {
+ for (int i = f.length; --i>= 0;) {
setBypass.invoke(f[i], bypassFlag);
}
} catch(Exception ex) {
@@ -763,7 +761,7 @@ public class Table {
}
int n = 0;
- for (int i = 0; i < f.length; i++) {
+ for (int i = 0; i < f.length; i++) {
if ((f[i].getModifiers()&(Modifier.TRANSIENT|Modifier.STATIC))==0)
{
String name = f[i].getName();
@@ -783,48 +781,48 @@ public class Table {
else if (c.equals("float")) type = FieldDescriptor.t_float;
else if (c.equals("double")) type = FieldDescriptor.t_double;
else if (c.equals("boolean")) type = FieldDescriptor.t_boolean;
- else if (c.equals("java.lang.Byte"))
+ else if (c.equals("java.lang.Byte"))
type = FieldDescriptor.tByte;
- else if (c.equals("java.lang.Short"))
+ else if (c.equals("java.lang.Short"))
type = FieldDescriptor.tShort;
- else if (c.equals("java.lang.Integer"))
+ else if (c.equals("java.lang.Integer"))
type = FieldDescriptor.tInteger;
- else if (c.equals("java.lang.Long"))
+ else if (c.equals("java.lang.Long"))
type = FieldDescriptor.tLong;
- else if (c.equals("java.lang.Float"))
+ else if (c.equals("java.lang.Float"))
type = FieldDescriptor.tFloat;
- else if (c.equals("java.lang.Double"))
+ else if (c.equals("java.lang.Double"))
type = FieldDescriptor.tDouble;
- else if (c.equals("java.lang.Boolean"))
+ else if (c.equals("java.lang.Boolean"))
type = FieldDescriptor.tBoolean;
- else if (c.equals("java.math.BigDecimal"))
+ else if (c.equals("java.math.BigDecimal"))
type = FieldDescriptor.tDecimal;
- else if (c.equals("java.lang.String"))
+ else if (c.equals("java.lang.String"))
type = FieldDescriptor.tString;
else if (fieldClass.equals(BYTE_PROTO.getClass()))
type = FieldDescriptor.tBytes;
- else if (c.equals("java.sql.Date"))
+ else if (c.equals("java.sql.Date"))
type = FieldDescriptor.tDate;
- else if (c.equals("java.sql.Time"))
+ else if (c.equals("java.sql.Time"))
type = FieldDescriptor.tTime;
- else if (c.equals("java.sql.Timestamp"))
+ else if (c.equals("java.sql.Timestamp"))
type = FieldDescriptor.tTimestamp;
- else if (c.equals("java.lang.InputStream"))
+ else if (c.equals("java.lang.InputStream"))
type = FieldDescriptor.tStream;
- else if (c.equals("java.sql.BlobLocator"))
+ else if (c.equals("java.sql.BlobLocator"))
type = FieldDescriptor.tBlob;
- else if (c.equals("java.sql.ClobLocator"))
+ else if (c.equals("java.sql.ClobLocator"))
type = FieldDescriptor.tClob;
else if (serializableClass.isAssignableFrom(fieldClass))
type = FieldDescriptor.tClosure;
- else {
- int nComponents = buildFieldsList(buf, fieldClass,
+ else {
+ int nComponents = buildFieldsList(buf, fieldClass,
fd.name+fieldSeparator);
- fd.inType = fd.outType =
+ fd.inType = fd.outType =
FieldDescriptor.tCompound + nComponents;
-
- try {
- fd.constructor =
+
+ try {
+ fd.constructor =
fieldClass.getDeclaredConstructor(new Class[0]);
setBypass.invoke(fd.constructor, bypassFlag);
} catch(Exception ex) {}
@@ -847,16 +845,16 @@ public class Table {
}
return n;
}
-
- protected final Object load(ResultSet result) throws SQLException {
+
+ protected final Object load(ResultSet result) throws SQLException {
Object obj;
- try {
+ try {
obj = constructor.newInstance(constructorArgs);
- }
+ }
catch(IllegalAccessException ex) { throw new IllegalAccessError(); }
catch(InstantiationException ex) { throw new InstantiationError(); }
- catch(Exception ex) {
+ catch(Exception ex) {
throw new InstantiationError("Exception was thrown by constructor");
}
load(obj, 0, nFields, 0, result);
@@ -864,28 +862,28 @@ public class Table {
}
private final int load(Object obj, int i, int end, int column,
- ResultSet result)
+ ResultSet result)
throws SQLException
- {
- try {
- while (i < end) {
+ {
+ try {
+ while (i < end) {
FieldDescriptor fd = fields[i++];
- if (!fd.loadVariable(result, obj, ++column)) {
- Object component =
+ if (!fd.loadVariable(result, obj, ++column)) {
+ Object component =
fd.constructor.newInstance(constructorArgs);
fd.field.set(obj, component);
int nComponents = fd.inType - FieldDescriptor.tCompound;
- column = load(component, i, i + nComponents,
+ column = load(component, i, i + nComponents,
column-1, result);
i += nComponents;
}
- }
- }
- catch(IllegalAccessException ex) { throw new IllegalAccessError(); }
- catch(InstantiationException ex) { throw new InstantiationError(); }
- catch(InvocationTargetException ex) {
+ }
+ }
+ catch(IllegalAccessException ex) { throw new IllegalAccessError(); }
+ catch(InstantiationException ex) { throw new InstantiationError(); }
+ catch(InvocationTargetException ex) {
throw new InstantiationError("Exception was thrown by constructor");
- }
+ }
return column;
}
@@ -893,17 +891,16 @@ public class Table {
Object obj)
throws SQLException
{
- bindUpdateVariables(pstmt, obj, 0, nFields, 0);
+ bindUpdateVariables(pstmt, obj, 0, nFields, 0);
}
protected final void bindQueryVariables(PreparedStatement pstmt,
Object obj)
throws SQLException
{
- bindQueryVariables(pstmt, obj, 0, nFields, 0);
+ bindQueryVariables(pstmt, obj, 0, nFields, 0);
}
-
protected final void updateVariables(ResultSet result, Object obj)
throws SQLException
{
@@ -911,7 +908,6 @@ public class Table {
result.updateRow();
}
-
protected final String buildQueryList(Object qbe)
{
StringBuffer buf = new StringBuffer();
@@ -922,33 +918,33 @@ public class Table {
return "select " + listOfFields + " from " + name + buf;
}
-
private final int bindUpdateVariables(PreparedStatement pstmt, Object obj,
- int i, int end, int column)
+ int i, int end, int column)
throws SQLException
- {
- try {
- while (i < end) {
+ {
+ try {
+ while (i < end) {
FieldDescriptor fd = fields[i++];
Object comp = null;
if (!fd.isBuiltin() && (comp = fd.field.get(obj)) == null) {
if (fd.isCompound()) {
int nComponents = fd.outType-FieldDescriptor.tCompound;
- while (--nComponents >= 0) {
+ while (--nComponents >= 0) {
fd = fields[i++];
- if (!fd.isCompound()) {
- pstmt.setNull(++column,
+ if (!fd.isCompound()) {
+ pstmt.setNull(++column,
FieldDescriptor.sqlTypeMapping[fd.outType]);
- }
+ }
}
- } else {
- pstmt.setNull(++column,
- FieldDescriptor.sqlTypeMapping[fd.outType]);
- }
- } else {
- if (!fd.bindVariable(pstmt, obj, ++column)) {
+ } else {
+ pstmt.setNull(
+ ++column,
+ FieldDescriptor.sqlTypeMapping[fd.outType]);
+ }
+ } else {
+ if (!fd.bindVariable(pstmt, obj, ++column)) {
int nComponents = fd.outType-FieldDescriptor.tCompound;
- column = bindUpdateVariables(pstmt, comp,
+ column = bindUpdateVariables(pstmt, comp,
i,i+nComponents,column-1);
i += nComponents;
}
@@ -959,24 +955,24 @@ public class Table {
}
private final int bindQueryVariables(PreparedStatement pstmt, Object obj,
- int i, int end, int column)
+ int i, int end, int column)
throws SQLException
- {
- try {
- while (i < end) {
+ {
+ try {
+ while (i < end) {
Object comp;
FieldDescriptor fd = fields[i++];
- if (!fd.field.getDeclaringClass().isInstance(obj)) {
+ if (!fd.field.getDeclaringClass().isInstance(obj)) {
return column;
}
- int nComponents =
+ int nComponents =
fd.isCompound() ? fd.outType-FieldDescriptor.tCompound : 0;
- if (!fd.isBuiltin()
- && fd.outType != FieldDescriptor.tClosure
- && (comp = fd.field.get(obj)) != null)
+ if (!fd.isBuiltin()
+ && fd.outType != FieldDescriptor.tClosure
+ && (comp = fd.field.get(obj)) != null)
{
- if (!fd.bindVariable(pstmt, obj, ++column)) {
- column = bindQueryVariables(pstmt, comp,
+ if (!fd.bindVariable(pstmt, obj, ++column)) {
+ column = bindQueryVariables(pstmt, comp,
i,i+nComponents,column-1);
}
}
@@ -986,58 +982,58 @@ public class Table {
return column;
}
- private final void buildQueryList(StringBuffer buf, Object qbe,
+ private final void buildQueryList(StringBuffer buf, Object qbe,
int i, int end)
{
- try {
- while (i < end) {
+ try {
+ while (i < end) {
Object comp;
FieldDescriptor fd = fields[i++];
- int nComponents =
+ int nComponents =
fd.isCompound() ? fd.outType-FieldDescriptor.tCompound : 0;
- if (!fd.isBuiltin()
- && fd.outType != FieldDescriptor.tClosure
- && (comp = fd.field.get(qbe)) != null)
+ if (!fd.isBuiltin()
+ && fd.outType != FieldDescriptor.tClosure
+ && (comp = fd.field.get(qbe)) != null)
{
- if (nComponents != 0) {
+ if (nComponents != 0) {
buildQueryList(buf, comp, i, i+nComponents);
- } else {
- if (buf.length() != 0) {
+ } else {
+ if (buf.length() != 0) {
buf.append(",");
}
buf.append(fd.name);
buf.append("=?");
}
- }
+ }
i += nComponents;
}
} catch(IllegalAccessException ex) { throw new IllegalAccessError(); }
}
protected final int updateVariables(ResultSet result, Object obj,
- int i, int end, int column)
+ int i, int end, int column)
throws SQLException
- {
- try {
- while (i < end) {
+ {
+ try {
+ while (i < end) {
FieldDescriptor fd = fields[i++];
Object comp = null;
if (!fd.isBuiltin() && (comp = fd.field.get(obj)) == null) {
if (fd.isCompound()) {
int nComponents = fd.outType-FieldDescriptor.tCompound;
- while (--nComponents >= 0) {
+ while (--nComponents >= 0) {
fd = fields[i++];
- if (!fd.isCompound()) {
+ if (!fd.isCompound()) {
result.updateNull(++column);
- }
+ }
}
- } else {
+ } else {
result.updateNull(++column);
- }
- } else {
- if (!fd.updateVariable(result, obj, ++column)) {
+ }
+ } else {
+ if (!fd.updateVariable(result, obj, ++column)) {
int nComponents = fd.outType-FieldDescriptor.tCompound;
- column = updateVariables(result, comp,
+ column = updateVariables(result, comp,
i, i+nComponents, column-1);
i += nComponents;
}