本文整理了Java中com.j256.ormlite.stmt.Where.queryForFirst()
方法的一些代码示例,展示了Where.queryForFirst()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Where.queryForFirst()
方法的具体详情如下:
包路径:com.j256.ormlite.stmt.Where
类名称:Where
方法名:queryForFirst
[英]A short-cut for calling QueryBuilder#queryForFirst().
[中]调用QueryBuilder#queryForFirst()的捷径。
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
public Tdao get(String key, Object value) {
try {
return this.getDao().queryBuilder().where().eq(key, value).queryForFirst();
} catch (SQLException ex) {
_logger.error("unable to get all items key:{}, value:{}", key, value, ex);
return null;
}
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
@Override
public RuleDefinitionTable getByName(String name) {
try {
return this.getDao().queryBuilder().where().eq(RuleDefinitionTable.KEY_NAME, name).queryForFirst();
} catch (SQLException ex) {
_logger.error("unable to get rule definition name:{},", name, ex);
}
return null;
}
代码示例来源:origin: zulip/zulip-android
@SuppressWarnings("WeakerAccess")
public static Person getByEmail(Dao<Person, ?> dao, String email) {
try {
return dao.queryBuilder().where()
.eq(Person.EMAIL_FIELD, new SelectArg(email))
.queryForFirst();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
@Override
public Timer getByName(String name) {
try {
return this.getDao().queryBuilder().where().eq(RuleDefinitionTable.KEY_NAME, name).queryForFirst();
} catch (SQLException ex) {
_logger.error("unable to get timer:{},", name, ex);
}
return null;
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
@Override
public UserSettings get(User user, String key) {
try {
QueryBuilder<UserSettings, Integer> queryBuilder = getDao().queryBuilder();
return queryBuilder.where().eq("key", key).queryForFirst();
} catch (SQLException ex) {
_logger.error("unable to get:[key:{}]", key, ex);
return null;
}
}
}
代码示例来源:origin: mycontroller-org/mycontroller
@Override
public RuleDefinitionTable getByName(String name) {
try {
return this.getDao().queryBuilder().where().eq(RuleDefinitionTable.KEY_NAME, name).queryForFirst();
} catch (SQLException ex) {
_logger.error("unable to get rule definition name:{},", name, ex);
throw new McDatabaseException(ex);
}
}
代码示例来源:origin: mycontroller-org/mycontroller
public Tdao get(String key, Object value) {
try {
return this.getDao().queryBuilder().where().eq(key, value).queryForFirst();
} catch (SQLException ex) {
_logger.error("unable to get all items key:{}, value:{}", key, value, ex);
throw new McDatabaseException(ex);
}
}
代码示例来源:origin: mycontroller-org/mycontroller
@Override
public Timer getByName(String name) {
try {
return this.getDao().queryBuilder().where().eq(RuleDefinitionTable.KEY_NAME, name).queryForFirst();
} catch (SQLException ex) {
_logger.error("unable to get timer:{},", name, ex);
throw new McDatabaseException(ex);
}
}
代码示例来源:origin: mycontroller-org/mycontroller
@Override
public UserSettings get(User user, String key) {
try {
QueryBuilder<UserSettings, Integer> queryBuilder = getDao().queryBuilder();
return queryBuilder.where().eq("key", key).queryForFirst();
} catch (SQLException ex) {
_logger.error("unable to get:[key:{}]", key, ex);
throw new McDatabaseException(ex);
}
}
}
代码示例来源:origin: zulip/zulip-android
public static Stream getByName(ZulipApp app, String name) {
Stream stream = null;
try {
RuntimeExceptionDao<Stream, Object> streams = app.getDao(Stream.class);
stream = streams.queryBuilder().where()
.eq(Stream.NAME_FIELD, new SelectArg(name)).queryForFirst();
if (stream == null) {
Log.w("Stream.getByName",
"We received a stream message for a stream we don't have data for. Fake it until you make it.");
stream = new Stream(name);
app.getDao(Stream.class).createIfNotExists(stream);
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
return stream;
}
代码示例来源:origin: PaNaVTEC/Clean-Contacts
@Override public Contact obtain(String md5) {
try {
BddContact bddContact =
daoContacts.queryBuilder().where().eq(BddContact.FIELD_MD5, md5).queryForFirst();
if (!cachingStrategy.isValid(bddContact)) {
return null;
}
return mapper.map(bddContact);
} catch (Throwable e) {
throw new LocalException();
}
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
@Override
public boolean isRecordFound(AGGREGATION_TYPE aggregationType, long start, long end) {
QueryBuilder<MetricsCounterTypeDevice, Object> queryBuilder = getDao().queryBuilder();
try {
return queryBuilder.where().gt(MetricsCounterTypeDevice.KEY_TIMESTAMP, start).and()
.le(MetricsCounterTypeDevice.KEY_TIMESTAMP, end).and()
.eq(MetricsCounterTypeDevice.KEY_AGGREGATION_TYPE, aggregationType).queryForFirst() != null;
} catch (Exception ex) {
_logger.error("Unable to execute countOf query", ex);
return true;
}
}
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
@Override
public boolean isRecordFound(AGGREGATION_TYPE aggregationType, long start, long end) {
QueryBuilder<MetricsBatteryUsage, Object> queryBuilder = getDao().queryBuilder();
try {
return queryBuilder.where().gt(MetricsBatteryUsage.KEY_TIMESTAMP, start).and()
.le(MetricsBatteryUsage.KEY_TIMESTAMP, end).and()
.eq(MetricsBatteryUsage.KEY_AGGREGATION_TYPE, aggregationType).queryForFirst() != null;
} catch (Exception ex) {
_logger.error("Unable to execute countOf query", ex);
return true;
}
}
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
@Override
public boolean isRecordFound(AGGREGATION_TYPE aggregationType, long start, long end) {
QueryBuilder<MetricsDoubleTypeDevice, Object> queryBuilder = getDao().queryBuilder();
try {
return queryBuilder.where()
.gt(MetricsDoubleTypeDevice.KEY_TIMESTAMP, start).and()
.le(MetricsDoubleTypeDevice.KEY_TIMESTAMP, end).and()
.eq(MetricsDoubleTypeDevice.KEY_AGGREGATION_TYPE, aggregationType)
.queryForFirst() != null;
} catch (Exception ex) {
_logger.error("Unable to execute countOf query", ex);
return true;
}
}
}
代码示例来源:origin: mycontroller-org/mycontroller
@Override
public boolean isRecordFound(AGGREGATION_TYPE aggregationType, long start, long end) {
QueryBuilder<MetricsCounterTypeDevice, Object> queryBuilder = getDao().queryBuilder();
try {
return queryBuilder.where().gt(MetricsCounterTypeDevice.KEY_TIMESTAMP, start).and()
.le(MetricsCounterTypeDevice.KEY_TIMESTAMP, end).and()
.eq(MetricsCounterTypeDevice.KEY_AGGREGATION_TYPE, aggregationType).queryForFirst() != null;
} catch (Exception ex) {
_logger.error("Unable to execute countOf query", ex);
throw new McDatabaseException(ex);
}
}
}
代码示例来源:origin: mycontroller-org/mycontroller
@Override
public boolean isRecordFound(AGGREGATION_TYPE aggregationType, long start, long end) {
QueryBuilder<MetricsBatteryUsage, Object> queryBuilder = getDao().queryBuilder();
try {
return queryBuilder.where().gt(MetricsBatteryUsage.KEY_TIMESTAMP, start).and()
.le(MetricsBatteryUsage.KEY_TIMESTAMP, end).and()
.eq(MetricsBatteryUsage.KEY_AGGREGATION_TYPE, aggregationType).queryForFirst() != null;
} catch (Exception ex) {
_logger.error("Unable to execute countOf query", ex);
throw new McDatabaseException(ex);
}
}
}
代码示例来源:origin: mycontroller-org/mycontroller
@Override
public boolean isRecordFound(AGGREGATION_TYPE aggregationType, long start, long end) {
QueryBuilder<MetricsDoubleTypeDevice, Object> queryBuilder = getDao().queryBuilder();
try {
return queryBuilder.where()
.gt(MetricsDoubleTypeDevice.KEY_TIMESTAMP, start).and()
.le(MetricsDoubleTypeDevice.KEY_TIMESTAMP, end).and()
.eq(MetricsDoubleTypeDevice.KEY_AGGREGATION_TYPE, aggregationType)
.queryForFirst() != null;
} catch (Exception ex) {
_logger.error("Unable to execute countOf query", ex);
throw new McDatabaseException(ex);
}
}
}
代码示例来源:origin: zulip/zulip-android
/**
* Checks stream name is valid or not
*
* @param app ZulipApp
* @param streamName Checks this stream name is valid or not
* @return null if stream does not exist else cursor
*/
public static Stream streamCheckBeforeMessageSend(ZulipApp app, CharSequence streamName) {
if (streamName == null) {
return null;
}
try {
return app.getDao(Stream.class)
.queryBuilder().where()
.eq(Stream.NAME_FIELD, new SelectArg(Stream.NAME_FIELD, streamName)).queryForFirst();
} catch (SQLException e) {
ZLog.logException(e);
}
return null;
}
代码示例来源:origin: zulip/zulip-android
/**
* This function returns the last message read in {@param streamName} stream.
*
* @param app {@link ZulipApp}
* @param streamName name of stream
* @return last message {@link Message} read
*/
public static Message getLastMessageRead(ZulipApp app, String streamName) {
try {
Dao<Message, Integer> messageDao = app.getDatabaseHelper().getDao(Message.class);
// query for message in given stream and orderby timestamp decreasingly
return messageDao.queryBuilder().orderBy(Message.TIMESTAMP_FIELD, false)
.where().eq(Message.RECIPIENTS_FIELD, new SelectArg(Message.RECIPIENTS_FIELD, streamName))
.queryForFirst();
} catch (SQLException e) {
ZLog.logException(e);
}
return null;
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testMaxJoin() throws Exception {
Dao<Foo, Object> dao = createDao(Foo.class, true);
Foo foo1 = new Foo();
foo1.val = 10;
assertEquals(1, dao.create(foo1));
Foo foo2 = new Foo();
foo2.val = 20;
assertEquals(1, dao.create(foo2));
Foo foo3 = new Foo();
foo3.val = 30;
assertEquals(1, dao.create(foo3));
Foo foo4 = new Foo();
foo4.val = 40;
assertEquals(1, dao.create(foo4));
QueryBuilder<Foo, Object> iqb = dao.queryBuilder();
iqb.selectRaw("max(id)");
QueryBuilder<Foo, Object> oqb = dao.queryBuilder();
Foo result = oqb.where().in(Foo.ID_COLUMN_NAME, iqb).queryForFirst();
assertNotNull(result);
assertEquals(foo4.id, result.id);
}
内容来源于网络,如有侵权,请联系作者删除!