org.sql2o.Query.executeAndFetch()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(140)

本文整理了Java中org.sql2o.Query.executeAndFetch方法的一些代码示例,展示了Query.executeAndFetch的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.executeAndFetch方法的具体详情如下:
包路径:org.sql2o.Query
类名称:Query
方法名:executeAndFetch

Query.executeAndFetch介绍

[英]Read a collection lazily. Generally speaking, this should only be used if you are reading MANY results and keeping them all in a Collection would cause memory issues. You MUST call org.sql2o.ResultSetIterable#close() when you are done iterating.
[中]懒洋洋地读一本藏书。一般来说,只有当你正在阅读许多结果,并且将它们全部保存在一个集合中会导致内存问题时,才应该使用这个选项。你必须打电话给org。sql2o。迭代完成后,ResultSetTable#close()将自动关闭。

代码示例

代码示例来源:origin: runelite/runelite

public List<IndexEntry> findIndexesForCache(Connection con, CacheEntry cache)
{
  return con.createQuery("select id, indexId, crc, revision from `index` where cache = :cache")
    .addParameter("cache", cache.getId())
    .executeAndFetch(IndexEntry.class);
}

代码示例来源:origin: aaberg/sql2o

public <T> List<T> executeAndFetch(ResultSetHandler<T> resultSetHandler){
  return executeAndFetch(newResultSetHandlerFactory(resultSetHandler));
}

代码示例来源:origin: aaberg/sql2o

public <T> List<T> executeAndFetch(Class<T> returnType){
  return executeAndFetch(newResultSetHandlerFactory(returnType));
}

代码示例来源:origin: aaberg/sql2o

public <T> List<T> executeScalarList(final Class<T> returnType){
  return executeAndFetch(newScalarResultSetHandler(returnType));
}

代码示例来源:origin: iNPUTmice/caas

public static List<Credential> getCredentials(Connection connection) {
  String query = "select domain,jid,password from credentials";
  return connection.createQuery(query).executeAndFetch(Credential.class);
}

代码示例来源:origin: org.sql2o/sql2o

public <T> List<T> executeScalarList(final Class<T> returnType){
  return executeAndFetch(newScalarResultSetHandler(returnType));
}

代码示例来源:origin: 100cm/thunder

public static  <T> T find_by_id(int id ,Class<T> tClass){
  String[] tablename =tClass.getName().toLowerCase().split("[.]");
  String table = tablename[tablename.length-1];
  List<T> list = (List<T>) DB.sql2o.beginTransaction().createQuery("select * from " + table+ " where id = " +id).executeAndFetch(tClass);
  return list.get(0);
}

代码示例来源:origin: sparktutorials/BlogService_SparkExample

private List<String> getCategoriesFor(Connection conn, UUID post_uuid) {
  return conn.createQuery("select category from posts_categories where post_uuid=:post_uuid")
      .addParameter("post_uuid", post_uuid)
      .executeAndFetch(String.class);
}

代码示例来源:origin: iNPUTmice/caas

public static List<String> getCompliantServers(Connection connection) {
  String query = "select servers.domain from servers inner join current_tests on current_tests.domain = servers.domain" +
      " where test in (:tests) group by current_tests.domain having sum(success) = count(success) and listed = 1";
  List<String> tests = new ArrayList<>(TestUtils.getTestNames());
  //Make sure server supports in-band registration
  tests.add("xep0077");
  return connection.createQuery(query)
      .addParameter("tests",tests)
      .executeAndFetch(String.class);
}

代码示例来源:origin: iNPUTmice/caas

public static List<Subscriber> getSubscribersFor(Connection connection, String domain) {
  List<Subscriber> subscribers = connection.createQuery(
      "select email,domain,unsubscribeCode from subscribers where domain=:domain")
      .addParameter("domain", domain)
      .executeAndFetch(Subscriber.class);
  return subscribers;
}

代码示例来源:origin: 100cm/thunder

public <T> List<T> list(Class<T> type) {
  List<T> result = null;
  Query query = null;
  String sql = buildSql(this.customSql);
  sql = sql.replaceAll("#table#", Util.getclassName(type).toLowerCase());
  query = connection.createQuery(sql);
  logger.info(Constant.LOG_AC_NAME+" execute sql " + sql );
  result = query.executeAndFetch(type);
  this.connection.close();
  return result;
}

代码示例来源:origin: sparktutorials/BlogService_SparkExample

@Override
public boolean existPost(UUID post) {
  try (Connection conn = sql2o.open()) {
    List<Post> posts = conn.createQuery("select * from posts where post_uuid=:post")
        .addParameter("post", post)
        .executeAndFetch(Post.class);
    return posts.size() > 0;
  }
}

代码示例来源:origin: 100cm/thunder

public  static  <T> List<T> find_all(Class<T> tClass){
  Logger logger = LogManager.getLogger(ActiveRecordBase.class);
  Connection connection = DB.sql2o.beginTransaction();
  String table = Util.getclassName(tClass).toLowerCase();
  String sql = "select * from "+table;
  logger.info(Constant.LOG_AC_NAME+"execute sql " + sql);
  List<T> list = connection.createQuery(sql).executeAndFetch(tClass);
  return list;
}

代码示例来源:origin: aalmiray/javatrove

@Override
@SuppressWarnings({"ConstantConditions", "unchecked"})
public Collection<Todo> findAll() {
  return sql2oHandler.withSql2o(sql2o -> (Collection<Todo>) sql2o.withConnection((connection, argument) -> {
    return connection.createQuery("SELECT * FROM todos").executeAndFetch(Todo.class);
  }));
}

代码示例来源:origin: sparktutorials/BlogService_SparkExample

@Override
public List<Comment> getAllCommentsOn(UUID post) {
  try (Connection conn = sql2o.open()) {
    return conn.createQuery("select * from comments where post_uuid=:post_uuid")
        .addParameter("post_uuid", post)
        .executeAndFetch(Comment.class);
  }
}

代码示例来源:origin: iNPUTmice/caas

public static List<Server> getPublicServers(Connection connection) {
  String query = "select domain,software_name,software_version,listed from servers where listed=1";
  return connection.createQuery(query)
      .addColumnMapping("software_name", "softwareName")
      .addColumnMapping("software_version", "softwareVersion")
      .executeAndFetch(Server.class);
}

代码示例来源:origin: iNPUTmice/caas

public static List<Server> getAllServers(Connection connection) {
  String query = "select domain,software_name,software_version,listed from servers";
  return connection.createQuery(query)
      .addColumnMapping("software_name", "softwareName")
      .addColumnMapping("software_version", "softwareVersion")
      .executeAndFetch(Server.class);
}

代码示例来源:origin: sparktutorials/BlogService_SparkExample

@Override
public List<Post> getAllPosts() {
  try (Connection conn = sql2o.open()) {
    List<Post> posts = conn.createQuery("select * from posts")
        .executeAndFetch(Post.class);
    posts.forEach((post) -> post.setCategories(getCategoriesFor(conn, post.getPost_uuid())));
    return posts;
  }
}

代码示例来源:origin: junicorn/mario

public static <T> List<T> getList(String sql, Class<T> clazz, Map<String, Object> params){
  Connection con = sql2o.open();
  Query query = con.createQuery(sql);
  executeQuery(query, params);
  List<T> list = query.executeAndFetch(clazz);
  con.close();
  return list;
}

代码示例来源:origin: lets-blade/blade-jdbc

public <T> List<T> findAll(Class<T> type, Supplier<ConditionEnum>... conditions) {
  QueryMeta queryMeta = SqlBuilder.buildFindAllSql(this, conditions);
  try (Connection con = getSql2o().open()) {
    log.debug(EXECUTE_SQL_PREFIX + " => {}", queryMeta.getSql());
    log.debug(PARAMETER_PREFIX + " => {}", Arrays.toString(queryMeta.getParams()));
    this.cleanParam();
    Query query = con.createQuery(queryMeta.getSql()).withParams(queryMeta.getParams()).throwOnMappingFailure(false);
    if (queryMeta.hasColumnMapping()) {
      queryMeta.getColumnMapping().forEach(query::addColumnMapping);
    }
    return query.executeAndFetch(type);
  }
}

相关文章