本文整理汇总了Java中org.sql2o.Query.executeAndFetchFirst方法的典型用法代码示例。如果您正苦于以下问题:Java Query.executeAndFetchFirst方法的具体用法?Java Query.executeAndFetchFirst怎么用?Java Query.executeAndFetchFirst使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.sql2o.Query
的用法示例。
在下文中一共展示了Query.executeAndFetchFirst方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getHomePage
import org.sql2o.Query; //导入方法依赖的package包/类
@Override
public Class<? extends Page> getHomePage() {
Sql2o sql2o = Spring.getBean(Sql2o.class);
try (Connection connection = sql2o.open()) {
Query query = connection.createQuery("SELECT groovy.java_class FROM setting INNER JOIN page on setting.value = page.page_id INNER JOIN groovy on page.groovy_id = groovy.groovy_id where setting.name = 'home_page'");
String javaClass = query.executeAndFetchFirst(String.class);
if (Strings.isNullOrEmpty(javaClass)) {
return DashboardPage.class;
} else {
GroovyClassLoader classLoader = Spring.getBean(GroovyClassLoader.class);
try {
return (Class<? extends Page>) classLoader.loadClass(javaClass);
} catch (ClassNotFoundException | ClassCastException e) {
return DashboardPage.class;
}
}
}
}
示例2: find
import org.sql2o.Query; //导入方法依赖的package包/类
public <T extends ActiveRecord> T find() {
QueryMeta queryMeta = SqlBuilder.buildFindSql(this);
Class<T> type = (Class<T>) getClass();
try (Connection con = getSql2o().open()) {
this.cleanParam();
log.debug(EXECUTE_SQL_PREFIX + " => {}", queryMeta.getSql());
log.debug(PARAMETER_PREFIX + " => {}", Arrays.toString(queryMeta.getParams()));
Query query = con.createQuery(queryMeta.getSql()).withParams(queryMeta.getParams()).throwOnMappingFailure(false);
if (queryMeta.hasColumnMapping()) {
queryMeta.getColumnMapping().forEach(query::addColumnMapping);
}
return query.executeAndFetchFirst(type);
}
}
示例3: getObject
import org.sql2o.Query; //导入方法依赖的package包/类
@Override
public Item getObject(String id, IModel<? extends List<? extends Item>> choices) {
Sql2o sql2o = Spring.getBean(Sql2o.class);
try (Connection connection = sql2o.open()) {
List<String> where = new ArrayList<>();
where.addAll(this.where);
where.add(this.idField + " = :id");
Query query = connection.createQuery("SELECT " + this.idField + " id, " + this.labelField + " value " + " FROM " + this.table + " WHERE " + StringUtils.join(where, " AND "));
query.addParameter("id", id);
return query.executeAndFetchFirst(Item.class);
}
}
示例4: toChoice
import org.sql2o.Query; //导入方法依赖的package包/类
@Override
public Item toChoice(String s) {
Sql2o sql2o = Spring.getBean(Sql2o.class);
try (Connection connection = sql2o.open()) {
List<String> where = new ArrayList<>();
where.addAll(this.where);
where.add(this.idField + " = :id");
Query query = connection.createQuery("SELECT " + this.idField + " id, " + this.labelField + " value " + " FROM " + this.table + " WHERE " + StringUtils.join(where, " AND "));
query.addParameter("id", s);
return query.executeAndFetchFirst(Item.class);
}
}
示例5: get
import org.sql2o.Query; //导入方法依赖的package包/类
public static <T> T get(String sql, Class<T> clazz, Map<String, Object> params){
Connection con = sql2o.open();
Query query = con.createQuery(sql);
executeQuery(query, params);
T t = query.executeAndFetchFirst(clazz);
con.close();
return t;
}