提交 274f303b authored 作者: Thomas Mueller's avatar Thomas Mueller

Cleanup:

- Increment by something that isn't a number directly didn't work
 
上级 b5d1d344
......@@ -144,6 +144,15 @@ public class UpdateTest extends TestBase {
assertEquals(original.productName, restored.productName);
assertEquals(original.unitPrice, restored.unitPrice);
assertEquals(original.unitsInStock, restored.unitsInStock);
double unitPriceOld = db.from(p).where(p.productId).is(1).selectFirst().unitPrice;
// double the unit price
db.from(p).increment(p.unitPrice).by(p.unitPrice)
.where(p.productId).is(1).update();
double unitPriceNew = db.from(p).where(p.productId).is(1).selectFirst().unitPrice;
assertEquals(unitPriceOld * 2, unitPriceNew);
}
}
......@@ -59,7 +59,7 @@ public class Db {
dialect = getDialect(conn.getClass().getCanonicalName());
}
SQLDialect getDialect(String clazz) {
private SQLDialect getDialect(String clazz) {
int todo;
// TODO add special cases here
return new DefaultSQLDialect();
......@@ -124,33 +124,32 @@ public class Db {
public <T> void insert(T t) {
Class<?> clazz = t.getClass();
int upgradeDbSoundsWrongHere;
upgradeDb().define(clazz).createTableIfRequired(this).insert(this, t, false);
define(clazz).createTableIfRequired(this).insert(this, t, false);
}
public <T> long insertAndGetKey(T t) {
Class<?> clazz = t.getClass();
return upgradeDb().define(clazz).createTableIfRequired(this).insert(this, t, true);
return define(clazz).createTableIfRequired(this).insert(this, t, true);
}
public <T> void merge(T t) {
Class<?> clazz = t.getClass();
upgradeDb().define(clazz).createTableIfRequired(this).merge(this, t);
define(clazz).createTableIfRequired(this).merge(this, t);
}
public <T> void update(T t) {
Class<?> clazz = t.getClass();
upgradeDb().define(clazz).createTableIfRequired(this).update(this, t);
define(clazz).createTableIfRequired(this).update(this, t);
}
public <T> void delete(T t) {
Class<?> clazz = t.getClass();
upgradeDb().define(clazz).createTableIfRequired(this).delete(this, t);
define(clazz).createTableIfRequired(this).delete(this, t);
}
public <T extends Object> Query<T> from(T alias) {
Class<?> clazz = alias.getClass();
upgradeDb().define(clazz).createTableIfRequired(this);
define(clazz).createTableIfRequired(this);
return Query.from(this, alias);
}
......@@ -229,6 +228,7 @@ public class Db {
<T> TableDefinition<T> define(Class<T> clazz) {
TableDefinition<T> def = getTableDefinition(clazz);
if (def == null) {
upgradeDb();
def = new TableDefinition<T>(clazz);
def.mapFields();
classMap.put(clazz, def);
......
......@@ -34,14 +34,8 @@ public class IncrementColumn<T, A> implements Declaration {
query.appendSQL(stat, x);
stat.appendSQL("=(");
query.appendSQL(stat, x);
int todoSomethingWrongHere;
if (y instanceof Number) {
Number n = (Number) y;
if (n.doubleValue() > 0) {
stat.appendSQL("+");
}
}
stat.appendSQL(y.toString());
stat.appendSQL("+");
query.appendSQL(stat, y);
stat.appendSQL(")");
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论