\r
**%VERSION%** ([zip](http://code.google.com/p/iciql/downloads/detail?name=%ZIP%)|[jar](http://code.google.com/p/iciql/downloads/detail?name=%JAR%)) *released %BUILDDATE%*\r
\r
+- fixed failure of db.delete(PrimitiveModel) and db.update(PrimitiveModel)\r
+\r
+### Older Releases\r
+\r
+**0.6.4** *released 2011-08-12*\r
+\r
- api change release (API v4)\r
- @IQTable.createIfRequired -> @IQTable.create\r
- don't INSERT primitive autoIncrement fields, let database assign value\r
@IQTable( primaryKey = {"name", "nickname"})\r
%ENDCODE%\r
\r
-### Older Releases\r
-\r
**0.6.3** *released 2011-08-08*\r
\r
- api change release (API v3)\r
define(clazz).createTableIfRequired(this).merge(this, t);\r
}\r
\r
- public <T> void update(T t) {\r
+ public <T> int update(T t) {\r
Class<?> clazz = t.getClass();\r
- define(clazz).createTableIfRequired(this).update(this, t);\r
+ return define(clazz).createTableIfRequired(this).update(this, t);\r
}\r
\r
- public <T> void delete(T t) {\r
+ public <T> int delete(T t) {\r
Class<?> clazz = t.getClass();\r
- define(clazz).createTableIfRequired(this).delete(this, t);\r
+ return define(clazz).createTableIfRequired(this).delete(this, t);\r
}\r
\r
public <T extends Object> Query<T> from(T alias) {\r
stat.executeUpdate();\r
}\r
\r
- void update(Db db, Object obj) {\r
+ int update(Db db, Object obj) {\r
if (primaryKeyColumnNames == null || primaryKeyColumnNames.size() == 0) {\r
throw new IllegalStateException("No primary key columns defined " + "for table " + obj.getClass()\r
+ " - no update possible");\r
boolean firstCondition = true;\r
for (FieldDefinition field : fields) {\r
if (field.isPrimaryKey) {\r
- Object aliasValue = field.getValue(alias);\r
+ Object fieldAlias = field.getValue(alias);\r
Object value = field.getValue(obj);\r
+ if (field.isPrimitive) {\r
+ fieldAlias = query.getPrimitiveAliasByValue(fieldAlias);\r
+ }\r
if (!firstCondition) {\r
query.addConditionToken(ConditionAndOr.AND);\r
}\r
firstCondition = false;\r
- query.addConditionToken(new Condition<Object>(aliasValue, value, CompareType.EQUAL));\r
+ query.addConditionToken(new Condition<Object>(fieldAlias, value, CompareType.EQUAL));\r
}\r
}\r
stat.setSQL(buff.toString());\r
query.appendWhere(stat);\r
StatementLogger.update(stat.getSQL());\r
- stat.executeUpdate();\r
+ return stat.executeUpdate();\r
}\r
\r
- void delete(Db db, Object obj) {\r
+ int delete(Db db, Object obj) {\r
if (primaryKeyColumnNames == null || primaryKeyColumnNames.size() == 0) {\r
- throw new IllegalStateException("No primary key columns defined " + "for table " + obj.getClass()\r
+ throw new IllegalStateException("No primary key columns defined for table " + obj.getClass()\r
+ " - no update possible");\r
}\r
SQLStatement stat = new SQLStatement(db);\r
boolean firstCondition = true;\r
for (FieldDefinition field : fields) {\r
if (field.isPrimaryKey) {\r
- Object aliasValue = field.getValue(alias);\r
+ Object fieldAlias = field.getValue(alias);\r
Object value = field.getValue(obj);\r
+ if (field.isPrimitive) {\r
+ fieldAlias = query.getPrimitiveAliasByValue(fieldAlias);\r
+ }\r
if (!firstCondition) {\r
query.addConditionToken(ConditionAndOr.AND);\r
}\r
firstCondition = false;\r
- query.addConditionToken(new Condition<Object>(aliasValue, value, CompareType.EQUAL));\r
+ query.addConditionToken(new Condition<Object>(fieldAlias, value, CompareType.EQUAL));\r
}\r
}\r
stat.setSQL(buff.toString());\r
query.appendWhere(stat);\r
StatementLogger.delete(stat.getSQL());\r
- stat.executeUpdate();\r
+ return stat.executeUpdate();\r
}\r
\r
TableDefinition<T> createTableIfRequired(Db db) {\r
List<PrimitivesModel> list = db.from(p).orderBy(p.myLong).select();\r
assertEquals(models.size(), list.size());\r
assertEquals("[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]", list.toString());\r
+ \r
+ // test model update\r
+ retrievedModel.myInteger = 1337;\r
+ assertEquals(1, db.update(retrievedModel));\r
+ assertEquals(1, db.delete(retrievedModel)); \r
\r
db.close();\r
}\r