本文整理了Java中com.j256.ormlite.stmt.Where.prepare()
方法的一些代码示例,展示了Where.prepare()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Where.prepare()
方法的具体详情如下:
包路径:com.j256.ormlite.stmt.Where
类名称:Where
方法名:prepare
[英]A short-cut for calling QueryBuilder#prepare().
[中]调用QueryBuilder#prepare()的捷径。
代码示例来源:origin: lamarios/Homedash2
/**
* Gets all the module layouts for a layout
*
* @param layout
* @return
* @throws SQLException
*/
public List<ModuleLayout> getModuleLayoutsForLayout(Layout layout) throws SQLException {
QueryBuilder<ModuleLayout, Integer> query = DB.MODULE_LAYOUT_DAO.queryBuilder();
PreparedQuery<ModuleLayout> preparedQuery = query.where().eq("layout_id", layout.getId()).prepare();
return DB.MODULE_LAYOUT_DAO.query(preparedQuery);
}
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
@Override
public SensorVariable get(Integer sensorRefId, MESSAGE_TYPE_SET_REQ messageVariableType) {
try {
nodeIdSensorIdnullCheck(sensorRefId, messageVariableType);
return this.getDao().queryForFirst(
this.getDao().queryBuilder()
.where().eq(SensorVariable.KEY_SENSOR_DB_ID, sensorRefId)
.and().eq(SensorVariable.KEY_VARIABLE_TYPE, messageVariableType).prepare());
} catch (SQLException ex) {
_logger.error("unable to get", ex);
} catch (DbException dbEx) {
_logger.error("unable to get, nodeId:{},sensorId:{}", sensorRefId, messageVariableType, dbEx);
}
return null;
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
@Override
public Sensor get(Integer nodeId, String sensorId) {
try {
nodeIdSensorIdnullCheck(nodeId, sensorId);
return this.getDao().queryForFirst(
this.getDao().queryBuilder()
.where().eq(Sensor.KEY_NODE_ID, nodeId)
.and().eq(Sensor.KEY_SENSOR_ID, sensorId).prepare());
} catch (SQLException ex) {
_logger.error("unable to get", ex);
} catch (DbException dbEx) {
_logger.error("unable to get, nodeId:{},sensorId:{}", nodeId, sensorId, dbEx);
}
return null;
}
代码示例来源:origin: mycontroller-org/mycontroller
@Override
public SensorsVariablesMap get(MESSAGE_TYPE_PRESENTATION sensorType, MESSAGE_TYPE_SET_REQ variableType) {
try {
nodeIdSensorIdnullCheck(sensorType, variableType);
return this.getDao().queryForFirst(
this.getDao().queryBuilder()
.where().eq(SensorsVariablesMap.KEY_SENSOR_TYPE, sensorType)
.and().eq(SensorsVariablesMap.KEY_VARIABLE_TYPE, variableType).prepare());
} catch (SQLException ex) {
_logger.error("unable to get", ex);
throw new McDatabaseException(ex);
} catch (DbException dbEx) {
_logger.error("unable to get, sensorType:{},variableType:{}", sensorType, variableType, dbEx);
throw new McDatabaseException(dbEx);
}
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
@Override
public MetricsBinaryTypeDevice get(MetricsBinaryTypeDevice metric) {
try {
return this.getDao().queryForFirst(
this.getDao().queryBuilder()
.where()
.eq(MetricsBinaryTypeDevice.KEY_SENSOR_VARIABLE_ID, metric.getSensorVariable().getId())
.and().eq(MetricsBinaryTypeDevice.KEY_TIMESTAMP, metric.getTimestamp()).prepare());
} catch (SQLException ex) {
_logger.error("unable to get, metric:{}", metric, ex);
}
return null;
}
代码示例来源:origin: mycontroller-org/mycontroller
@Override
public MetricsBinaryTypeDevice get(MetricsBinaryTypeDevice metric) {
try {
return this.getDao().queryForFirst(
this.getDao().queryBuilder()
.where()
.eq(MetricsBinaryTypeDevice.KEY_SENSOR_VARIABLE_ID, metric.getSensorVariable().getId())
.and().eq(MetricsBinaryTypeDevice.KEY_TIMESTAMP, metric.getTimestamp()).prepare());
} catch (SQLException ex) {
_logger.error("unable to get, metric:{}", metric, ex);
throw new McDatabaseException(ex);
}
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
@Override
public MetricsGPSTypeDevice get(MetricsGPSTypeDevice metric) {
try {
return this.getDao().queryForFirst(
this.getDao().queryBuilder()
.where()
.eq(MetricsGPSTypeDevice.KEY_SENSOR_VARIABLE_ID, metric.getSensorVariable().getId())
.and().eq(MetricsGPSTypeDevice.KEY_AGGREGATION_TYPE, metric.getAggregationType())
.and().eq(MetricsGPSTypeDevice.KEY_TIMESTAMP, metric.getTimestamp()).prepare());
} catch (SQLException ex) {
_logger.error("unable to get, metric:{}", metric, ex);
}
return null;
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
@Override
public MetricsBatteryUsage get(MetricsBatteryUsage metric) {
try {
return this.getDao().queryForFirst(
this.getDao().queryBuilder()
.where()
.eq(MetricsBatteryUsage.KEY_NODE_ID, metric.getNode().getId())
.and().eq(MetricsBatteryUsage.KEY_AGGREGATION_TYPE, metric.getAggregationType())
.and().eq(MetricsBatteryUsage.KEY_TIMESTAMP, metric.getTimestamp()).prepare());
} catch (SQLException ex) {
_logger.error("unable to get, metric:{}", metric, ex);
}
return null;
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
@Override
public MetricsDoubleTypeDevice get(MetricsDoubleTypeDevice metric) {
try {
return this.getDao().queryForFirst(
this.getDao().queryBuilder()
.where()
.eq(MetricsDoubleTypeDevice.KEY_SENSOR_VARIABLE_ID, metric.getSensorVariable().getId())
.and().eq(MetricsDoubleTypeDevice.KEY_AGGREGATION_TYPE, metric.getAggregationType())
.and().eq(MetricsDoubleTypeDevice.KEY_TIMESTAMP, metric.getTimestamp()).prepare());
} catch (SQLException ex) {
_logger.error("unable to get, metric:{}", metric, ex);
}
return null;
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
@Override
public MetricsCounterTypeDevice get(MetricsCounterTypeDevice metric) {
try {
return this.getDao().queryForFirst(
this.getDao().queryBuilder()
.where()
.eq(MetricsCounterTypeDevice.KEY_SENSOR_VARIABLE_ID, metric.getSensorVariable().getId())
.and().eq(MetricsCounterTypeDevice.KEY_AGGREGATION_TYPE, metric.getAggregationType())
.and().eq(MetricsCounterTypeDevice.KEY_TIMESTAMP, metric.getTimestamp()).prepare());
} catch (SQLException ex) {
_logger.error("unable to get, metric:{}", metric, ex);
}
return null;
}
代码示例来源:origin: mycontroller-org/mycontroller
@Override
public MetricsBatteryUsage get(MetricsBatteryUsage metric) {
try {
return this.getDao().queryForFirst(
this.getDao().queryBuilder()
.where()
.eq(MetricsBatteryUsage.KEY_NODE_ID, metric.getNode().getId())
.and().eq(MetricsBatteryUsage.KEY_AGGREGATION_TYPE, metric.getAggregationType())
.and().eq(MetricsBatteryUsage.KEY_TIMESTAMP, metric.getTimestamp()).prepare());
} catch (SQLException ex) {
_logger.error("unable to get, metric:{}", metric, ex);
throw new McDatabaseException(ex);
}
}
代码示例来源:origin: mycontroller-org/mycontroller
@Override
public MetricsDoubleTypeDevice get(MetricsDoubleTypeDevice metric) {
try {
return this.getDao().queryForFirst(
this.getDao().queryBuilder()
.where()
.eq(MetricsDoubleTypeDevice.KEY_SENSOR_VARIABLE_ID, metric.getSensorVariable().getId())
.and().eq(MetricsDoubleTypeDevice.KEY_AGGREGATION_TYPE, metric.getAggregationType())
.and().eq(MetricsDoubleTypeDevice.KEY_TIMESTAMP, metric.getTimestamp()).prepare());
} catch (SQLException ex) {
_logger.error("unable to get, metric:{}", metric, ex);
throw new McDatabaseException(ex);
}
}
代码示例来源:origin: mycontroller-org/mycontroller
@Override
public MetricsCounterTypeDevice get(MetricsCounterTypeDevice metric) {
try {
return this.getDao().queryForFirst(
this.getDao().queryBuilder()
.where()
.eq(MetricsCounterTypeDevice.KEY_SENSOR_VARIABLE_ID, metric.getSensorVariable().getId())
.and().eq(MetricsCounterTypeDevice.KEY_AGGREGATION_TYPE, metric.getAggregationType())
.and().eq(MetricsCounterTypeDevice.KEY_TIMESTAMP, metric.getTimestamp()).prepare());
} catch (SQLException ex) {
_logger.error("unable to get, metric:{}", metric, ex);
throw new McDatabaseException(ex);
}
}
代码示例来源:origin: mycontroller-org/mycontroller
@Override
public MetricsGPSTypeDevice get(MetricsGPSTypeDevice metric) {
try {
return this.getDao().queryForFirst(
this.getDao().queryBuilder()
.where()
.eq(MetricsGPSTypeDevice.KEY_SENSOR_VARIABLE_ID, metric.getSensorVariable().getId())
.and().eq(MetricsGPSTypeDevice.KEY_AGGREGATION_TYPE, metric.getAggregationType())
.and().eq(MetricsGPSTypeDevice.KEY_TIMESTAMP, metric.getTimestamp()).prepare());
} catch (SQLException ex) {
_logger.error("unable to get, metric:{}", metric, ex);
throw new McDatabaseException(ex);
}
}
代码示例来源:origin: com.j256.ormlite/ormlite-jdbc
@Test
public void testWherePrepare() throws Exception {
Dao<Foo, String> fooDao = createTestData();
List<Foo> results = fooDao.query(fooDao.queryBuilder()
.where()
.eq(Foo.ID_COLUMN_NAME, foo1.id)
.and()
.eq(Foo.VAL_COLUMN_NAME, foo1.val)
.prepare());
assertEquals(1, results.size());
assertEquals(foo1, results.get(0));
}
代码示例来源:origin: com.j256.ormlite/ormlite-jdbc
@Test
public void testIdEq() throws Exception {
Dao<Foo, Integer> fooDao = createDao(Foo.class, true);
Foo foo = new Foo();
foo.id = "wow id wow";
assertEquals(1, fooDao.create(foo));
List<Foo> results = fooDao.query(fooDao.queryBuilder().where().idEq(fooDao, foo).prepare());
assertEquals(1, results.size());
assertEquals(foo.id, results.get(0).id);
}
代码示例来源:origin: j256/ormlite-core
@Test(expected = SQLException.class)
public void testResultColumnNoMatchWhere() throws Exception {
BaseDaoImpl<ForeignFoo, Integer> foreignDao =
new BaseDaoImpl<ForeignFoo, Integer>(connectionSource, ForeignFoo.class) {
};
QueryBuilder<ForeignFoo, Integer> qbInner = foreignDao.queryBuilder();
qbInner.selectColumns(STRING_COLUMN_NAME);
QueryBuilder<ForeignFoo, Integer> qbOuter = foreignDao.queryBuilder();
Where<ForeignFoo, Integer> where = qbOuter.where();
where.in(ID_COLUMN_NAME, qbInner);
where.prepare();
}
代码示例来源:origin: j256/ormlite-core
@Test(expected = SQLException.class)
public void testTwoResultsInSubQuery() throws Exception {
BaseDaoImpl<ForeignFoo, Integer> foreignDao =
new BaseDaoImpl<ForeignFoo, Integer>(connectionSource, ForeignFoo.class) {
};
QueryBuilder<ForeignFoo, Integer> qbInner = foreignDao.queryBuilder();
qbInner.selectColumns(ID_COLUMN_NAME);
QueryBuilder<ForeignFoo, Integer> qbOuter = foreignDao.queryBuilder();
qbInner.selectColumns(FOREIGN_COLUMN_NAME);
Where<ForeignFoo, Integer> where = qbOuter.where();
where.in(ID_COLUMN_NAME, qbInner);
where.prepare();
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testQueryPrepared() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
Foo foo1 = new Foo();
assertEquals(1, dao.create(foo1));
Foo foo2 = new Foo();
assertEquals(1, dao.create(foo2));
Where<Foo, Integer> qb = dao.queryBuilder().where().eq(Foo.ID_COLUMN_NAME, foo2.id);
List<Foo> results = dao.query(qb.prepare());
assertEquals(1, results.size());
assertEquals(foo2.id, results.get(0).id);
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testIteratorPrepared() throws Exception {
Dao<Foo, Integer> dao = createDao(Foo.class, true);
Foo foo1 = new Foo();
assertEquals(1, dao.create(foo1));
Foo foo2 = new Foo();
assertEquals(1, dao.create(foo2));
PreparedQuery<Foo> query = dao.queryBuilder().where().eq(Foo.ID_COLUMN_NAME, foo2.id).prepare();
CloseableIterator<Foo> iterator = dao.iterator(query);
assertTrue(iterator.hasNext());
Foo result = iterator.next();
assertEquals(foo2.id, result.id);
assertFalse(iterator.hasNext());
assertNull(iterator.nextThrow());
}
内容来源于网络,如有侵权,请联系作者删除!