本文整理了Java中com.j256.ormlite.dao.Dao.query()
方法的一些代码示例,展示了Dao.query()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Dao.query()
方法的具体详情如下:
包路径:com.j256.ormlite.dao.Dao
类名称:Dao
方法名:query
[英]Query for the items in the object table which match the prepared query. See #queryBuilder for more information.
NOTE: For medium sized or large tables, this may load a lot of objects into memory so you should consider using the #iterator(PreparedQuery) method instead.
[中]查询对象表中与准备的查询匹配的项。有关更多信息,请参阅#queryBuilder。
注意:对于中等大小或较大的表,这可能会将大量对象加载到内存中,因此您应该考虑使用γ迭代器(PravaReqQuy)方法。
代码示例来源:origin: magefree/mage
public List<UserStats> getAllUsers() {
try {
QueryBuilder<UserStats, Object> qb = dao.queryBuilder();
return dao.query(qb.prepare());
} catch (SQLException ex) {
Logger.getLogger(UserStatsRepository.class).error("Error getting all users from DB - ", ex);
}
return null;
}
代码示例来源:origin: magefree/mage
public List<ExpansionInfo> getAll() {
try {
QueryBuilder<ExpansionInfo, Object> qb = expansionDao.queryBuilder();
qb.orderBy("releaseDate", true);
return expansionDao.query(qb.prepare());
} catch (SQLException ex) {
logger.error(ex);
}
return Collections.emptyList();
}
代码示例来源:origin: magefree/mage
public List<CardInfo> findCards(CardCriteria criteria) {
try {
QueryBuilder<CardInfo, Object> queryBuilder = cardDao.queryBuilder();
criteria.buildQuery(queryBuilder);
return cardDao.query(queryBuilder.prepare());
} catch (SQLException ex) {
Logger.getLogger(CardRepository.class).error("Error during execution of card repository query statement", ex);
}
return Collections.emptyList();
}
代码示例来源:origin: magefree/mage
public List<String> getAllSetNames() {
try {
QueryBuilder<ExpansionInfo, Object> qb = expansionDao.queryBuilder();
qb.orderBy("releaseDate", true);
List<ExpansionInfo> expansions = expansionDao.query(qb.prepare());
List<String> setNames = new LinkedList<>();
for (ExpansionInfo expansionInfo : expansions) {
setNames.add(expansionInfo.getName());
}
return setNames;
} catch (SQLException ex) {
logger.error(ex);
}
return Collections.emptyList();
}
代码示例来源:origin: magefree/mage
public UserStats getUser(String userName) {
try {
QueryBuilder<UserStats, Object> qb = dao.queryBuilder();
qb.limit(1L).where().eq("userName", userName);
List<UserStats> users = dao.query(qb.prepare());
if (!users.isEmpty()) {
return users.get(0);
}
} catch (SQLException ex) {
Logger.getLogger(UserStatsRepository.class).error("Error getting a user from DB - ", ex);
}
return null;
}
代码示例来源:origin: magefree/mage
public List<CardInfo> getMissingCards(List<String> classNames) {
try {
QueryBuilder<CardInfo, Object> queryBuilder = cardDao.queryBuilder();
queryBuilder.where().not().in("className", classNames);
return cardDao.query(queryBuilder.prepare());
} catch (SQLException ex) {
Logger.getLogger(CardRepository.class).error("Error getting missing cards from DB : " + ex);
}
return Collections.emptyList();
}
代码示例来源:origin: magefree/mage
public long getLatestEndTimeMs() {
try {
QueryBuilder<UserStats, Object> qb = dao.queryBuilder();
qb.orderBy("endTimeMs", false).limit(1L);
List<UserStats> users = dao.query(qb.prepare());
if (!users.isEmpty()) {
return users.get(0).getEndTimeMs();
}
} catch (SQLException ex) {
Logger.getLogger(UserStatsRepository.class).error("Error getting the latest end time from DB - ", ex);
}
return 0;
}
代码示例来源:origin: magefree/mage
public List<TableRecord> getAfter(long endTimeMs) {
try {
QueryBuilder<TableRecord, Object> qb = dao.queryBuilder();
qb.where().gt("endTimeMs", endTimeMs);
qb.orderBy("endTimeMs", true);
return dao.query(qb.prepare());
} catch (SQLException ex) {
Logger.getLogger(TableRecordRepository.class).error("Error getting table_records from DB - ", ex);
}
return null;
}
代码示例来源:origin: magefree/mage
public List<ExpansionInfo> getSetsFromBlock(String blockName) {
List<ExpansionInfo> sets = new LinkedList<>();
try {
QueryBuilder<ExpansionInfo, Object> qb = expansionDao.queryBuilder();
qb.where().eq("blockName", new SelectArg(blockName));
return expansionDao.query(qb.prepare());
} catch (SQLException ex) {
logger.error(ex);
}
return sets;
}
代码示例来源:origin: magefree/mage
public AuthorizedUser getByName(String userName) {
try {
QueryBuilder<AuthorizedUser, Object> qb = dao.queryBuilder();
qb.where().eq("name", new SelectArg(userName));
List<AuthorizedUser> results = dao.query(qb.prepare());
if (results.size() == 1) {
return results.get(0);
}
return null;
} catch (SQLException ex) {
Logger.getLogger(AuthorizedUserRepository.class).error("Error getting a authorized_user - ", ex);
}
return null;
}
代码示例来源:origin: magefree/mage
public AuthorizedUser getByEmail(String userName) {
try {
QueryBuilder<AuthorizedUser, Object> qb = dao.queryBuilder();
qb.where().eq("email", new SelectArg(userName));
List<AuthorizedUser> results = dao.query(qb.prepare());
if (results.size() == 1) {
return results.get(0);
}
return null;
} catch (SQLException ex) {
Logger.getLogger(AuthorizedUserRepository.class).error("Error getting a authorized_user - ", ex);
}
return null;
}
代码示例来源:origin: magefree/mage
public List<CardInfo> findCards(String name) {
try {
QueryBuilder<CardInfo, Object> queryBuilder = cardDao.queryBuilder();
queryBuilder.where().eq("name", new SelectArg(name));
return cardDao.query(queryBuilder.prepare());
} catch (SQLException ex) {
}
return Collections.emptyList();
}
代码示例来源:origin: magefree/mage
public List<ExpansionInfo> getSetsWithBasicLandsByReleaseDate() {
List<ExpansionInfo> sets = new LinkedList<>();
try {
QueryBuilder<ExpansionInfo, Object> qb = expansionDao.queryBuilder();
qb.orderBy("releaseDate", false);
qb.where().eq("basicLands", new SelectArg(true));
sets = expansionDao.query(qb.prepare());
} catch (SQLException ex) {
logger.error(ex);
}
return sets;
}
代码示例来源:origin: magefree/mage
public ExpansionInfo getSetByCode(String setCode) {
ExpansionInfo set = null;
try {
QueryBuilder<ExpansionInfo, Object> qb = expansionDao.queryBuilder();
qb.limit(1L).where().eq("code", new SelectArg(setCode));
List<ExpansionInfo> expansions = expansionDao.query(qb.prepare());
if (!expansions.isEmpty()) {
set = expansions.get(0);
}
} catch (SQLException ex) {
logger.error(ex);
}
return set;
}
代码示例来源:origin: magefree/mage
public ExpansionInfo getSetByName(String setName) {
ExpansionInfo set = null;
try {
QueryBuilder<ExpansionInfo, Object> qb = expansionDao.queryBuilder();
qb.limit(1L).where().eq("name", new SelectArg(setName));
List<ExpansionInfo> expansions = expansionDao.query(qb.prepare());
if (!expansions.isEmpty()) {
set = expansions.get(0);
}
} catch (SQLException ex) {
logger.error(ex);
}
return set;
}
代码示例来源:origin: magefree/mage
public boolean cardExists(String className) {
try {
if (classNames == null) {
QueryBuilder<CardInfo, Object> qb = cardDao.queryBuilder();
qb.distinct().selectColumns("className").where().isNotNull("className");
List<CardInfo> results = cardDao.query(qb.prepare());
classNames = new TreeSet<>();
for (CardInfo card : results) {
classNames.add(card.getClassName());
}
}
return classNames.contains(className);
} catch (SQLException ex) {
}
return false;
}
代码示例来源:origin: magefree/mage
public static long getDatabaseVersion(ConnectionSource connectionSource, String entityName) throws SQLException {
TableUtils.createTableIfNotExists(connectionSource, DatabaseVersion.class);
Dao<DatabaseVersion, Object> dbVersionDao = DaoManager.createDao(connectionSource, DatabaseVersion.class);
QueryBuilder<DatabaseVersion, Object> queryBuilder = dbVersionDao.queryBuilder();
queryBuilder.where().eq("entity", new SelectArg(entityName));
List<DatabaseVersion> dbVersions = dbVersionDao.query(queryBuilder.prepare());
if (dbVersions.isEmpty()) {
return 0;
} else {
return dbVersions.get(0).getVersion();
}
}
代码示例来源:origin: magefree/mage
public CardInfo findCard(String setCode, String cardNumber) {
try {
QueryBuilder<CardInfo, Object> queryBuilder = cardDao.queryBuilder();
queryBuilder.limit(1L).where().eq("setCode", new SelectArg(setCode)).and().eq("cardNumber", cardNumber).and().eq("nightCard", false);
List<CardInfo> result = cardDao.query(queryBuilder.prepare());
if (!result.isEmpty()) {
return result.get(0);
}
} catch (SQLException ex) {
Logger.getLogger(CardRepository.class).error("Error finding card from DB : " + ex);
}
return null;
}
代码示例来源:origin: magefree/mage
public static boolean isDatabaseObsolete(ConnectionSource connectionSource, String entityName, long version) throws SQLException {
TableUtils.createTableIfNotExists(connectionSource, DatabaseVersion.class);
Dao<DatabaseVersion, Object> dbVersionDao = DaoManager.createDao(connectionSource, DatabaseVersion.class);
QueryBuilder<DatabaseVersion, Object> queryBuilder = dbVersionDao.queryBuilder();
queryBuilder.where().eq("entity", new SelectArg(entityName)).and().eq("version", version);
List<DatabaseVersion> dbVersions = dbVersionDao.query(queryBuilder.prepare());
if (dbVersions.isEmpty()) {
DatabaseVersion dbVersion = new DatabaseVersion();
dbVersion.setEntity(entityName);
dbVersion.setVersion(version);
dbVersionDao.create(dbVersion);
}
return dbVersions.isEmpty();
}
代码示例来源:origin: magefree/mage
public static void updateVersion(ConnectionSource connectionSource, String entityName, long version) throws SQLException {
TableUtils.createTableIfNotExists(connectionSource, DatabaseVersion.class);
Dao<DatabaseVersion, Object> dbVersionDao = DaoManager.createDao(connectionSource, DatabaseVersion.class);
QueryBuilder<DatabaseVersion, Object> queryBuilder = dbVersionDao.queryBuilder();
queryBuilder.where().eq("entity", new SelectArg(entityName));
List<DatabaseVersion> dbVersions = dbVersionDao.query(queryBuilder.prepare());
if (!dbVersions.isEmpty()) {
DeleteBuilder<DatabaseVersion, Object> deleteBuilder = dbVersionDao.deleteBuilder();
deleteBuilder.where().eq("entity", new SelectArg(entityName));
deleteBuilder.delete();
}
DatabaseVersion databaseVersion = new DatabaseVersion();
databaseVersion.setEntity(entityName);
databaseVersion.setVersion(version);
dbVersionDao.create(databaseVersion);
}
内容来源于网络,如有侵权,请联系作者删除!