\r
public <T> void insert(T t) {\r
Class<?> clazz = t.getClass();\r
- long rc = define(clazz).createTableIfRequired(this).insert(this, t, false);\r
+ long rc = define(clazz).createIfRequired(this).insert(this, t, false);\r
if (rc == 0) {\r
throw new IciqlException("Failed to insert {0}. Affected rowcount == 0.", t);\r
}\r
\r
public <T> long insertAndGetKey(T t) {\r
Class<?> clazz = t.getClass();\r
- return define(clazz).createTableIfRequired(this).insert(this, t, true);\r
+ return define(clazz).createIfRequired(this).insert(this, t, true);\r
}\r
\r
/**\r
*/\r
public <T> void merge(T t) {\r
Class<?> clazz = t.getClass();\r
- TableDefinition<?> def = define(clazz).createTableIfRequired(this);\r
+ TableDefinition<?> def = define(clazz).createIfRequired(this);\r
int rc = def.merge(this, t);\r
if (rc == 0) {\r
rc = def.update(this, t);\r
\r
public <T> int update(T t) {\r
Class<?> clazz = t.getClass();\r
- return define(clazz).createTableIfRequired(this).update(this, t);\r
+ return define(clazz).createIfRequired(this).update(this, t);\r
}\r
\r
public <T> int delete(T t) {\r
Class<?> clazz = t.getClass();\r
- return define(clazz).createTableIfRequired(this).delete(this, t);\r
+ return define(clazz).createIfRequired(this).delete(this, t);\r
}\r
\r
public <T extends Object> Query<T> from(T alias) {\r
Class<?> clazz = alias.getClass();\r
- define(clazz).createTableIfRequired(this);\r
+ define(clazz).createIfRequired(this);\r
return Query.from(this, alias);\r
}\r
\r
\r
public static void primaryKey(Object... columns) {\r
checkInDefine();\r
- currentTableDefinition.setPrimaryKey(columns);\r
+ currentTableDefinition.definePrimaryKey(columns);\r
}\r
\r
public static void index(Object... columns) {\r
checkInDefine();\r
- currentTableDefinition.addIndex(IndexType.STANDARD, columns);\r
+ currentTableDefinition.defineIndex(IndexType.STANDARD, columns);\r
}\r
\r
public static void uniqueIndex(Object... columns) {\r
checkInDefine();\r
- currentTableDefinition.addIndex(IndexType.UNIQUE, columns);\r
+ currentTableDefinition.defineIndex(IndexType.UNIQUE, columns);\r
}\r
\r
public static void hashIndex(Object column) {\r
checkInDefine();\r
- currentTableDefinition.addIndex(IndexType.HASH, new Object[] { column });\r
+ currentTableDefinition.defineIndex(IndexType.HASH, new Object[] { column });\r
}\r
\r
public static void uniqueHashIndex(Object column) {\r
checkInDefine();\r
- currentTableDefinition.addIndex(IndexType.UNIQUE_HASH, new Object[] { column });\r
+ currentTableDefinition.defineIndex(IndexType.UNIQUE_HASH, new Object[] { column });\r
}\r
\r
public static void columnName(Object column, String columnName) {\r
checkInDefine();\r
- currentTableDefinition.setColumnName(column, columnName);\r
+ currentTableDefinition.defineColumnName(column, columnName);\r
}\r
\r
public static void length(Object column, int length) {\r
checkInDefine();\r
- currentTableDefinition.setLength(column, length);\r
+ currentTableDefinition.defineLength(column, length);\r
}\r
\r
public static void scale(Object column, int scale) {\r
checkInDefine();\r
- currentTableDefinition.setScale(column, scale);\r
+ currentTableDefinition.defineScale(column, scale);\r
}\r
\r
public static void tableName(String tableName) {\r
checkInDefine();\r
- currentTableDefinition.setTableName(tableName);\r
+ currentTableDefinition.defineTableName(tableName);\r
}\r
\r
@SuppressWarnings("deprecation")\r
}\r
}\r
\r
- Object initWithNewObject(Object obj) {\r
+ private Object initWithNewObject(Object obj) {\r
Object o = Utils.newObject(field.getType());\r
setValue(obj, o);\r
return o;\r
}\r
\r
- void setValue(Object obj, Object o) {\r
+ private void setValue(Object obj, Object o) {\r
try {\r
if (!field.isAccessible()) {\r
field.setAccessible(true);\r
}\r
}\r
\r
- Object read(ResultSet rs, int columnIndex) {\r
+ private Object read(ResultSet rs, int columnIndex) {\r
try {\r
return rs.getObject(columnIndex);\r
} catch (SQLException e) {\r
List<String> primaryKeyColumnNames;\r
boolean memoryTable;\r
\r
- private boolean createTableIfRequired = true;\r
+ private boolean createIfRequired = true;\r
private Class<T> clazz;\r
private IdentityHashMap<Object, FieldDefinition> fieldMap = Utils.newIdentityHashMap();\r
private ArrayList<IndexDefinition> indexes = Utils.newArrayList();\r
return fields;\r
}\r
\r
- FieldDefinition getField(String name) {\r
- for (FieldDefinition field : fields) {\r
- if (field.columnName.equalsIgnoreCase(name)) {\r
- return field;\r
- }\r
- }\r
- return null;\r
- }\r
-\r
- void setSchemaName(String schemaName) {\r
+ void defineSchemaName(String schemaName) {\r
this.schemaName = schemaName;\r
}\r
\r
- void setTableName(String tableName) {\r
+ void defineTableName(String tableName) {\r
this.tableName = tableName;\r
}\r
\r
* @param modelFields\r
* the ordered list of model fields\r
*/\r
- void setPrimaryKey(Object[] modelFields) {\r
+ void definePrimaryKey(Object[] modelFields) {\r
List<String> columnNames = mapColumnNames(modelFields);\r
setPrimaryKey(columnNames);\r
}\r
* @param columnNames\r
* the ordered list of column names\r
*/\r
- void setPrimaryKey(List<String> columnNames) {\r
+ private void setPrimaryKey(List<String> columnNames) {\r
primaryKeyColumnNames = Utils.newArrayList(columnNames);\r
// set isPrimaryKey flag for all field definitions\r
for (FieldDefinition fieldDefinition : fieldMap.values()) {\r
}\r
}\r
\r
- <A> String getColumnName(A fieldObject) {\r
+ private <A> String getColumnName(A fieldObject) {\r
FieldDefinition def = fieldMap.get(fieldObject);\r
return def == null ? null : def.columnName;\r
}\r
* @param modelFields\r
* the ordered list of model fields\r
*/\r
- void addIndex(IndexType type, Object[] modelFields) {\r
+ void defineIndex(IndexType type, Object[] modelFields) {\r
List<String> columnNames = mapColumnNames(modelFields);\r
addIndex(null, type, columnNames);\r
}\r
* @param columnNames\r
* the ordered list of column names\r
*/\r
- void addIndex(String name, IndexType type, List<String> columnNames) {\r
+ private void addIndex(String name, IndexType type, List<String> columnNames) {\r
IndexDefinition index = new IndexDefinition();\r
if (StringUtils.isNullOrEmpty(name)) {\r
index.indexName = tableName + "_" + indexes.size();\r
indexes.add(index);\r
}\r
\r
- public void setColumnName(Object column, String columnName) {\r
+ void defineColumnName(Object column, String columnName) {\r
FieldDefinition def = fieldMap.get(column);\r
if (def != null) {\r
def.columnName = columnName;\r
}\r
}\r
\r
- public void setLength(Object column, int length) {\r
+ void defineLength(Object column, int length) {\r
FieldDefinition def = fieldMap.get(column);\r
if (def != null) {\r
def.length = length;\r
}\r
}\r
\r
- public void setScale(Object column, int scale) {\r
+ void defineScale(Object column, int scale) {\r
FieldDefinition def = fieldMap.get(column);\r
if (def != null) {\r
def.scale = scale;\r
}\r
return value;\r
}\r
- // standard behavior\r
+ \r
+ // return the value unchanged\r
return value;\r
}\r
\r
return stat.executeUpdate();\r
}\r
\r
- TableDefinition<T> createTableIfRequired(Db db) {\r
- if (!createTableIfRequired) {\r
+ TableDefinition<T> createIfRequired(Db db) {\r
+ if (!createIfRequired) {\r
// skip table and index creation\r
// but still check for upgrades\r
db.upgradeTable(this);\r
}\r
\r
// allow control over createTableIfRequired()\r
- createTableIfRequired = tableAnnotation.create();\r
+ createIfRequired = tableAnnotation.create();\r
\r
// model version\r
if (clazz.isAnnotationPresent(IQVersion.class)) {\r
}\r
}\r
\r
- void addIndex(IQIndex index) {\r
+ private void addIndex(IQIndex index) {\r
List<String> columns = Arrays.asList(index.value());\r
addIndex(index.name(), index.type(), columns);\r
}\r
return indexes;\r
}\r
\r
- void initObject(Object obj, Map<Object, FieldDefinition> map) {\r
+ private void initObject(Object obj, Map<Object, FieldDefinition> map) {\r
for (FieldDefinition def : fields) {\r
Object newValue = def.initWithNewObject(obj);\r
map.put(newValue, def);\r