本文整理了Java中com.j256.ormlite.dao.Dao.updateBuilder()
方法的一些代码示例,展示了Dao.updateBuilder()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Dao.updateBuilder()
方法的具体详情如下:
包路径:com.j256.ormlite.dao.Dao
类名称:Dao
方法名:updateBuilder
[英]Like #queryBuilder() but allows you to build an UPDATE statement. You can then call call UpdateBuilder#prepare() and pass the returned PreparedUpdate to #update(PreparedUpdate).
[中]类似于#queryBuilder(),但允许您构建UPDATE语句。然后可以调用UpdateBuilder#prepare()并将返回的PreparedUpdate传递给#update(PreparedUpdate)。
代码示例来源:origin: j256/ormlite-core
/**
* @see Dao#updateBuilder()
*/
@Override
public UpdateBuilder<T, ID> updateBuilder() {
return dao.updateBuilder();
}
代码示例来源:origin: com.j256.ormlite/ormlite-core
/**
* @see Dao#updateBuilder()
*/
@Override
public UpdateBuilder<T, ID> updateBuilder() {
return dao.updateBuilder();
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
private void enableDisable(List<Integer> ids, boolean enabled) {
try {
UpdateBuilder<ForwardPayload, Integer> updateBuilder = this.getDao().updateBuilder();
updateBuilder.updateColumnValue(ForwardPayload.KEY_ENABLED, enabled).where()
.in(ForwardPayload.KEY_ID, ids);
int updateCount = updateBuilder.update();
_logger.debug("Updated rows count:{}", updateCount);
} catch (SQLException ex) {
_logger.error("Failed to update, Ids:{}", ids, ex);
}
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
@Override
public void disableAllTriggered() {
try {
UpdateBuilder<RuleDefinitionTable, Integer> updateBuilder = getDao().updateBuilder();
updateBuilder.updateColumnValue(RuleDefinitionTable.KEY_TRIGGERED, false).where()
.eq(RuleDefinitionTable.KEY_TRIGGERED, true);
Integer count = updateBuilder.update();
_logger.debug("Number of rows updated:[{}]", count);
} catch (SQLException ex) {
_logger.error("unable to update rule triggered status", ex);
}
}
代码示例来源:origin: annmuor/jnode
public void update(String field, Object value, Object... args) {
try {
UpdateBuilder<T, ?> ub = getDao().updateBuilder();
buildWhere(ub, true, args);
ub.updateColumnValue(field, value);
ub.update();
} catch (SQLException e) {
logger.l1("SQL Exception in update", e);
logger.l1(MessageFormat.format("we worked with {0} {1} {2}", field,
value, Arrays.toString(args)));
}
}
代码示例来源:origin: mycontroller-org/mycontroller
private void enableDisable(List<Integer> ids, boolean enabled) {
try {
UpdateBuilder<ForwardPayload, Integer> updateBuilder = this.getDao().updateBuilder();
updateBuilder.updateColumnValue(ForwardPayload.KEY_ENABLED, enabled).where()
.in(ForwardPayload.KEY_ID, ids);
int updateCount = updateBuilder.update();
_logger.debug("Updated rows count:{}", updateCount);
} catch (SQLException ex) {
_logger.error("Failed to update, Ids:{}", ids, ex);
throw new McDatabaseException(ex);
}
}
代码示例来源:origin: mycontroller-org/mycontroller
@Override
public void disableAllTriggered() {
try {
UpdateBuilder<RuleDefinitionTable, Integer> updateBuilder = getDao().updateBuilder();
updateBuilder.updateColumnValue(RuleDefinitionTable.KEY_TRIGGERED, false).where()
.eq(RuleDefinitionTable.KEY_TRIGGERED, true);
Integer count = updateBuilder.update();
_logger.debug("Number of rows updated:[{}]", count);
} catch (SQLException ex) {
_logger.error("unable to update rule triggered status", ex);
throw new McDatabaseException(ex);
}
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
@Override
public void updateTimestamp(int sensorVariableId, long timestampOld, long timestanpNew) {
try {
UpdateBuilder<MetricsBinaryTypeDevice, Object> _ub = getDao().updateBuilder();
_ub.where().eq(MetricsBinaryTypeDevice.KEY_SENSOR_VARIABLE_ID, sensorVariableId).and()
.eq(MetricsBinaryTypeDevice.KEY_TIMESTAMP, timestampOld);
_ub.updateColumnValue(MetricsBinaryTypeDevice.KEY_TIMESTAMP, timestanpNew);
int updateCount = _ub.update();
_logger.debug("Update count:{}", updateCount);
} catch (SQLException ex) {
_logger.error("SQL Exception", ex);
}
}
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
@Override
public void update(String key, String subKey, String value) {
try {
//Create it if not available
createIfNotAvailable(key, subKey);
UpdateBuilder<Settings, Integer> updateBuilder = this.getDao().updateBuilder();
updateBuilder.where().eq(Settings.KEY_KEY, key).and().eq(Settings.KEY_SUB_KEY, subKey);
updateBuilder.updateColumnValue(Settings.KEY_VALUE, value);
int count = updateBuilder.update();
_logger.debug("update count:{}", count);
} catch (SQLException ex) {
_logger.error("unable to get item for key:{}, subKey:{}", key, subKey, ex);
}
}
代码示例来源:origin: mycontroller-org/mycontroller
@Override
public void updateTimestamp(int sensorVariableId, long timestampOld, long timestanpNew) {
try {
UpdateBuilder<MetricsBinaryTypeDevice, Object> _ub = getDao().updateBuilder();
_ub.where().eq(MetricsBinaryTypeDevice.KEY_SENSOR_VARIABLE_ID, sensorVariableId).and()
.eq(MetricsBinaryTypeDevice.KEY_TIMESTAMP, timestampOld);
_ub.updateColumnValue(MetricsBinaryTypeDevice.KEY_TIMESTAMP, timestanpNew);
int updateCount = _ub.update();
_logger.debug("Update count:{}", updateCount);
} catch (SQLException ex) {
_logger.error("SQL Exception", ex);
throw new McDatabaseException(ex);
}
}
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
private void updateEnabled(RESOURCE_TYPE resourceType, Integer resourceId, boolean enabled) {
try {
UpdateBuilder<Resource, Integer> updateBuilder = getDao().updateBuilder();
Where<Resource, Integer> where = updateBuilder.where();
int whereCount = 0;
where.eq(Resource.KEY_RESOURCE_TYPE, resourceType);
whereCount++;
where.eq(Resource.KEY_RESOURCE_ID, resourceId);
where.and(whereCount);
updateBuilder.setWhere(where);
updateBuilder.updateColumnValue(Resource.KEY_ENABLED, enabled);
int updateCount = updateBuilder.update();
_logger.debug("Update count:{}", updateCount);
} catch (SQLException ex) {
_logger.error("Failed to update! input:[resourceType:{}, resourceId:{}, enabled:{}], ",
resourceType, resourceId, enabled, ex);
}
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
@Override
public void update(String key, String subKey, String value, String altValue) {
try {
//Create it if not available
createIfNotAvailable(key, subKey);
UpdateBuilder<Settings, Integer> updateBuilder = this.getDao().updateBuilder();
updateBuilder.where().eq(Settings.KEY_KEY, key).and().eq(Settings.KEY_SUB_KEY, subKey);
updateBuilder.updateColumnValue(Settings.KEY_VALUE, value);
updateBuilder.updateColumnValue(Settings.KEY_ALT_VALUE, altValue);
int count = updateBuilder.update();
_logger.debug("update count:{}", count);
} catch (SQLException ex) {
_logger.error("unable to get item for key:{}, subKey:{}", key, subKey, ex);
}
}
代码示例来源:origin: mycontroller-org/mycontroller
@Override
public void update(String key, String subKey, String value) {
try {
//Create it if not available
createIfNotAvailable(key, subKey);
UpdateBuilder<Settings, Integer> updateBuilder = this.getDao().updateBuilder();
updateBuilder.where().eq(Settings.KEY_KEY, key).and().eq(Settings.KEY_SUB_KEY, subKey);
updateBuilder.updateColumnValue(Settings.KEY_VALUE, value);
int count = updateBuilder.update();
_logger.debug("update count:{}", count);
} catch (SQLException ex) {
_logger.error("unable to get item for key:{}, subKey:{}", key, subKey, ex);
throw new McDatabaseException(ex);
}
}
代码示例来源:origin: mycontroller-org/mycontroller
@Override
public void update(String key, String subKey, String value, String altValue) {
try {
//Create it if not available
createIfNotAvailable(key, subKey);
UpdateBuilder<Settings, Integer> updateBuilder = this.getDao().updateBuilder();
updateBuilder.where().eq(Settings.KEY_KEY, key).and().eq(Settings.KEY_SUB_KEY, subKey);
updateBuilder.updateColumnValue(Settings.KEY_VALUE, value);
updateBuilder.updateColumnValue(Settings.KEY_ALT_VALUE, altValue);
int count = updateBuilder.update();
_logger.debug("update count:{}", count);
} catch (SQLException ex) {
_logger.error("unable to get item for key:{}, subKey:{}", key, subKey, ex);
throw new McDatabaseException(ex);
}
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testUpdateTwoNullsInSeperateStatements() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
UpdateBuilder<Foo, Integer> ub = dao.updateBuilder();
ub.updateColumnValue(Foo.STRING_COLUMN_NAME, null);
dao.update(ub.prepare());
ub = dao.updateBuilder();
ub.updateColumnValue(Foo.EQUAL_COLUMN_NAME, null);
dao.update(ub.prepare());
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testUpdateTwoDates() throws Exception {
Dao<TwoDates, Integer> dao = createDao(TwoDates.class, true);
TwoDates foo = new TwoDates();
long now = System.currentTimeMillis();
Date date1 = new Date(now);
Date date2 = new Date(now + 1000);
foo.date1 = date1;
foo.date2 = date2;
assertEquals(1, dao.create(foo));
UpdateBuilder<TwoDates, Integer> ub = dao.updateBuilder();
ub.updateColumnValue(TwoDates.FIELD_NAME_DATE1, date2);
ub.updateColumnValue(TwoDates.FIELD_NAME_DATE2, date1);
dao.update(ub.prepare());
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testUpdateTwoNulls() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
UpdateBuilder<Foo, Integer> ub = dao.updateBuilder();
ub.updateColumnValue(Foo.STRING_COLUMN_NAME, null);
ub.updateColumnValue(Foo.EQUAL_COLUMN_NAME, null);
dao.update(ub.prepare());
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testUpdateBuildUpdateMathod() throws Exception {
Dao<UpdateDate, Integer> dao = createDao(UpdateDate.class, true);
UpdateDate updateDate = new UpdateDate();
updateDate.date = new Date();
assertEquals(1, dao.create(updateDate));
Date newDate = new Date(System.currentTimeMillis() + 10);
UpdateBuilder<UpdateDate, Integer> ub = dao.updateBuilder();
ub.updateColumnValue(UpdateDate.DATE_FIELD, newDate);
// this used to cause a NPE because of a missing args
assertEquals(1, ub.update());
// make sure the update worked
UpdateDate result = dao.queryForId(updateDate.id);
assertNotNull(result);
assertEquals(newDate, result.date);
}
代码示例来源:origin: com.j256.ormlite/ormlite-jdbc
@Test
public void testPrepareStatementUpdateValueNumber() throws Exception {
Dao<Foo, Integer> fooDao = createDao(Foo.class, true);
Foo foo = new Foo();
foo.val = 123213;
assertEquals(1, fooDao.create(foo));
QueryBuilder<Foo, Integer> stmtb = fooDao.queryBuilder();
stmtb.where().eq(Foo.ID_FIELD_NAME, foo.id);
List<Foo> results = fooDao.query(stmtb.prepare());
assertEquals(1, results.size());
UpdateBuilder<Foo, Integer> updateb = fooDao.updateBuilder();
updateb.updateColumnValue(Foo.VAL_FIELD_NAME, foo.val + 1);
assertEquals(1, fooDao.update(updateb.prepare()));
results = fooDao.query(stmtb.prepare());
assertEquals(1, results.size());
assertEquals(foo.val + 1, results.get(0).val);
}
代码示例来源:origin: j256/ormlite-core
@Test(expected = SQLException.class)
public void testUpdatePreparedThrow() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
Foo foo = new Foo();
assertEquals(1, dao.create(foo));
DatabaseConnection conn = connectionSource.getReadWriteConnection(FOO_TABLE_NAME);
try {
conn.close();
UpdateBuilder<Foo, Integer> ub = dao.updateBuilder();
ub.updateColumnValue(Foo.EQUAL_COLUMN_NAME, 1);
dao.update(ub.prepare());
} finally {
connectionSource.releaseConnection(conn);
}
}
内容来源于网络,如有侵权,请联系作者删除!