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

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

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

Query.executeAndFetchFirst介绍

暂无

代码示例

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

public CacheEntry findMostRecent(Connection con)
{
  return con.createQuery("select id, revision, date from cache order by revision desc, date desc limit 1")
    .executeAndFetchFirst(CacheEntry.class);
}

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

public ArchiveEntry findArchive(Connection con, IndexEntry index,
  int archiveId, int nameHash, int crc, int revision)
{
  if (findArchive == null)
  {
    findArchive = con.createQuery("select distinct archive.id, archive.archiveId, archive.nameHash,"
      + " archive.crc, archive.revision, archive.hash from archive "
      + " join index_archive on index_archive.archive = archive.id"
      + " join `index` on index.id = index_archive.index"
      + " where archive.archiveId = :archiveId"
      + " and archive.nameHash = :nameHash"
      + " and archive.crc = :crc"
      + " and archive.revision = :revision"
      + " and index.indexId = :indexId");
  }
  ArchiveEntry entry = findArchive
    .addParameter("archiveId", archiveId)
    .addParameter("nameHash", nameHash)
    .addParameter("crc", crc)
    .addParameter("revision", revision)
    .addParameter("indexId", index.getIndexId())
    .executeAndFetchFirst(ArchiveEntry.class);
  return entry;
}

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

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

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

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

代码示例来源:origin: biezhi/anima

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

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

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

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

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

代码示例来源:origin: biezhi/anima

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

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

public static Credential getCredentialFor(Connection connection, String domain) {
  String query = "select domain,jid,password from credentials where domain=:domain";
  return connection.createQuery(query)
      .addParameter("domain", domain)
      .executeAndFetchFirst(Credential.class);
}

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

public long count(String sql, Object... args) {
  int pos = 1;
  while (sql.contains("?")) {
    sql = sql.replaceFirst("\\?", ":p" + (pos++));
  }
  args = args == null ? new Object[]{} : args;
  try (Connection con = getSql2o().open()) {
    this.cleanParam();
    log.debug(EXECUTE_SQL_PREFIX + " => {}", sql);
    log.debug(PARAMETER_PREFIX + " => {}", Arrays.toString(args));
    return con.createQuery(sql).withParams(args)
        .executeAndFetchFirst(Long.class);
  }
}

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

public <T> T query(Class<T> type, String sql, Object... args) {
  int pos = 1;
  while (sql.contains(SQL_QM)) {
    sql = sql.replaceFirst("\\?", ":p" + (pos++));
  }
  try (Connection con = getSql2o().open()) {
    log.debug(EXECUTE_SQL_PREFIX + " => {}", sql);
    log.debug(PARAMETER_PREFIX + " => {}", Arrays.toString(args));
    this.cleanParam();
    Query     query     = con.createQuery(sql).withParams(args).throwOnMappingFailure(false);
    QueryMeta queryMeta = SqlBuilder.buildFindAllSql(this, null);
    if (queryMeta.hasColumnMapping()) {
      queryMeta.getColumnMapping().forEach(query::addColumnMapping);
    }
    return query.executeAndFetchFirst(type);
  }
}

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

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;
}

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

@Override
public Todo findById(Long id) {
  return sql2oHandler.withSql2o(sql2o -> sql2o.withConnection((connection, argument) -> {
    return connection.createQuery("SELECT * FROM todos WHERE id = :id")
      .addParameter("id", id)
      .executeAndFetchFirst(Todo.class);
  }));
}

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

public static Server getServer(Connection connection, String domain) {
  String query = "select domain,software_name,software_version,listed from servers where domain = :domain";
  return connection.createQuery(query)
      .addColumnMapping("software_name", "softwareName")
      .addColumnMapping("software_version", "softwareVersion")
      .addParameter("domain", domain)
      .executeAndFetchFirst(Server.class);
}

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

private long count(boolean cleanParam) {
  QueryMeta queryMeta = SqlBuilder.buildCountSql(this);
  try (Connection con = getSql2o().open()) {
    if (cleanParam) this.cleanParam();
    log.debug(EXECUTE_SQL_PREFIX + " => {}", queryMeta.getSql());
    log.debug(PARAMETER_PREFIX + " => {}", Arrays.toString(queryMeta.getParams()));
    return con.createQuery(queryMeta.getSql())
        .withParams(queryMeta.getParams())
        .executeAndFetchFirst(Long.class);
  }
}

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

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);
  }
}

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

/**
 * Get latest iteration, null if no iteration exists
 *
 * @param connection
 * @return
 */
public static Iteration getLatestIteration(Connection connection) {
  String query = "select iteration_number, begin_time, end_time from periodic_test_iterations" +
      " where iteration_number = (select max(iteration_number) from periodic_test_iterations)";
  return connection.createQuery(query)
      .addColumnMapping("iteration_number", "iterationNumber")
      .addColumnMapping("begin_time", "begin")
      .addColumnMapping("end_time", "end")
      .executeAndFetchFirst(Iteration.class);
}

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

public static Subscriber removeSubscriber(Connection connection, String unsubscribeCode) {
  Subscriber subscriber = connection.createQuery(
      "select email,domain,unsubscribeCode from subscribers " +
          "where unsubscribeCode=:unsubscribeCode")
      .addParameter("unsubscribeCode", unsubscribeCode)
      .executeAndFetchFirst(Subscriber.class);
  connection.createQuery("delete from subscribers " +
      "where unsubscribeCode=:unsubscribeCode")
      .addParameter("unsubscribeCode", unsubscribeCode)
      .executeUpdate();
  return subscriber;
}

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

public <T> T find(Class<T> type, Serializable id) {
  String    sql       = "SELECT * FROM " + getTableName() + " WHERE " + getPk() + " = :p1";
  QueryMeta queryMeta = new QueryMeta();
  SqlBuilder.mapping(queryMeta, this.getClass());
  try (Connection con = getSql2o().open()) {
    this.cleanParam();
    log.debug(EXECUTE_SQL_PREFIX + " => {}", sql);
    log.debug(PARAMETER_PREFIX + " => [{}]", id);
    Query query = con.createQuery(sql).withParams(id).throwOnMappingFailure(false);
    if (queryMeta.hasColumnMapping()) {
      queryMeta.getColumnMapping().forEach(query::addColumnMapping);
    }
    return query.executeAndFetchFirst(type);
  }
}

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

/**
 * Get the iteration which has the given iteration number
 *
 * @param connection
 * @param iterationNumber The iteration numbers for which the corresponding iteration is to be found
 * @return A list of iterations
 */
public static Iteration getIteration(Connection connection, int iterationNumber) {
  String query = "select iteration_number, begin_time, end_time from periodic_test_iterations" +
      " where iteration_number = (:iteration) limit 1";
  return connection.createQuery(query)
      .addParameter("iteration", iterationNumber)
      .addColumnMapping("iteration_number", "iterationNumber")
      .addColumnMapping("begin_time", "begin")
      .addColumnMapping("end_time", "end")
      .executeAndFetchFirst(Iteration.class);
}

相关文章