com.j256.ormlite.dao.Dao.queryRaw()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(176)

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

Dao.queryRaw介绍

[英]Similar to the #queryRaw(String,RawRowMapper,String...) but this iterator returns rows that you can map yourself using DatabaseResultsMapper.
[中]类似于#queryRaw(String、RawRowMapper、String…)但是这个迭代器返回可以使用DatabaseResultsMapper自己映射的行。

代码示例

代码示例来源:origin: magefree/mage

public List<CardInfo> findCardsCaseInsensitive(String name) {
  try {
    String sqlName = name.toLowerCase(Locale.ENGLISH).replaceAll("\'", "\'\'");
    GenericRawResults<CardInfo> rawResults = cardDao.queryRaw(
        "select * from " + CardRepository.VERSION_ENTITY_NAME + " where lower(name) = '" + sqlName + '\'',
        cardDao.getRawRowMapper());
    List<CardInfo> result = new ArrayList<>();
    for (CardInfo cardinfo : rawResults) {
      result.add(cardinfo);
    }
    return result;
  } catch (SQLException ex) {
    Logger.getLogger(CardRepository.class).error("Error during execution of raw sql statement", ex);
  }
  return Collections.emptyList();
}

代码示例来源:origin: magefree/mage

public ExpansionInfo[] getWithBoostersSortedByReleaseDate() {
  try {
    // only with boosters and cards
    GenericRawResults<ExpansionInfo> setsList = expansionDao.queryRaw(
        "select * from expansion e "
            + " where e.boosters = 1 "
            + "   and exists(select (1) from  card c where c.setcode = e.code) "
            + " order by e.releasedate desc",
        expansionDao.getRawRowMapper());
    List<ExpansionInfo> resList = new ArrayList<>();
    for (ExpansionInfo info : setsList) {
      resList.add(info);
    }
    return resList.toArray(new ExpansionInfo[0]);
  } catch (SQLException ex) {
    logger.error(ex);
    return new ExpansionInfo[0];
  }
}

代码示例来源:origin: j256/ormlite-core

/**
 * @see Dao#queryRaw(String, DatabaseResultsMapper, String...)
 */
@Override
public <UO> GenericRawResults<UO> queryRaw(String query, DatabaseResultsMapper<UO> mapper, String... arguments) {
  try {
    return dao.queryRaw(query, mapper, arguments);
  } catch (SQLException e) {
    logMessage(e, "queryRaw threw exception on: " + query);
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: j256/ormlite-core

/**
 * A short cut to {@link Dao#queryRaw(String, String...)}.
 */
public GenericRawResults<String[]> queryRaw() throws SQLException {
  return dao.queryRaw(prepareStatementString());
}

代码示例来源:origin: j256/ormlite-core

/**
 * @see Dao#queryRaw(String, String...)
 */
@Override
public GenericRawResults<String[]> queryRaw(String query, String... arguments) {
  try {
    return dao.queryRaw(query, arguments);
  } catch (SQLException e) {
    logMessage(e, "queryRaw threw exception on: " + query);
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: j256/ormlite-core

/**
 * @see Dao#queryRaw(String, RawRowMapper, String...)
 */
@Override
public <UO> GenericRawResults<UO> queryRaw(String query, RawRowMapper<UO> mapper, String... arguments) {
  try {
    return dao.queryRaw(query, mapper, arguments);
  } catch (SQLException e) {
    logMessage(e, "queryRaw threw exception on: " + query);
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: j256/ormlite-core

/**
 * @see Dao#queryRaw(String, DataType[], String...)
 */
@Override
public GenericRawResults<Object[]> queryRaw(String query, DataType[] columnTypes, String... arguments) {
  try {
    return dao.queryRaw(query, columnTypes, arguments);
  } catch (SQLException e) {
    logMessage(e, "queryRaw threw exception on: " + query);
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: com.j256.ormlite/ormlite-core

/**
 * @see Dao#queryRaw(String, String...)
 */
@Override
public GenericRawResults<String[]> queryRaw(String query, String... arguments) {
  try {
    return dao.queryRaw(query, arguments);
  } catch (SQLException e) {
    logMessage(e, "queryRaw threw exception on: " + query);
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: com.j256.ormlite/ormlite-core

/**
 * @see Dao#queryRaw(String, DatabaseResultsMapper, String...)
 */
@Override
public <UO> GenericRawResults<UO> queryRaw(String query, DatabaseResultsMapper<UO> mapper, String... arguments) {
  try {
    return dao.queryRaw(query, mapper, arguments);
  } catch (SQLException e) {
    logMessage(e, "queryRaw threw exception on: " + query);
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: com.j256.ormlite/ormlite-core

/**
 * @see Dao#queryRaw(String, RawRowMapper, String...)
 */
@Override
public <UO> GenericRawResults<UO> queryRaw(String query, RawRowMapper<UO> mapper, String... arguments) {
  try {
    return dao.queryRaw(query, mapper, arguments);
  } catch (SQLException e) {
    logMessage(e, "queryRaw threw exception on: " + query);
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: com.j256.ormlite/ormlite-core

/**
 * @see Dao#queryRaw(String, DataType[], String...)
 */
@Override
public GenericRawResults<Object[]> queryRaw(String query, DataType[] columnTypes, String... arguments) {
  try {
    return dao.queryRaw(query, columnTypes, arguments);
  } catch (SQLException e) {
    logMessage(e, "queryRaw threw exception on: " + query);
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: j256/ormlite-core

/**
 * @see Dao#queryRaw(String, DataType[], RawRowObjectMapper, String...)
 */
@Override
public <UO> GenericRawResults<UO> queryRaw(String query, DataType[] columnTypes, RawRowObjectMapper<UO> mapper,
    String... arguments) {
  try {
    return dao.queryRaw(query, columnTypes, mapper, arguments);
  } catch (SQLException e) {
    logMessage(e, "queryRaw threw exception on: " + query);
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: com.j256.ormlite/ormlite-core

/**
 * @see Dao#queryRaw(String, DataType[], RawRowObjectMapper, String...)
 */
@Override
public <UO> GenericRawResults<UO> queryRaw(String query, DataType[] columnTypes, RawRowObjectMapper<UO> mapper,
    String... arguments) {
  try {
    return dao.queryRaw(query, columnTypes, mapper, arguments);
  } catch (SQLException e) {
    logMessage(e, "queryRaw threw exception on: " + query);
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: j256/ormlite-core

/**
 * A short cut to {@link Dao#queryRaw(String, String...)} and {@link GenericRawResults#getFirstResult()}.
 */
public String[] queryRawFirst() throws SQLException {
  return dao.queryRaw(prepareStatementString()).getFirstResult();
}

代码示例来源:origin: annmuor/jnode

public GenericRawResults<Object[]> getRaw(String query, DataType[] types) {
  try {
    return getDao().queryRaw(query, types);
  } catch (SQLException e) {
    logger.l1("SQL Exception in getRaw", e);
    logger.l1(MessageFormat.format("we worked with {0} {1}", query,
        Arrays.toString(types)));
  }
  return null;
}

代码示例来源:origin: mycontroller-org/mycontroller

public boolean hasTable(String tableName) {
  try {
    // test if the table already exists
    DaoUtils.getUserDao().getDao().queryRaw("SELECT count(*) FROM " + getTableName(tableName));
    return true;
  } catch (SQLException ex) {
    return false;
  }
}

代码示例来源:origin: j256/ormlite-core

@Test(expected = RuntimeException.class)
public void testQueryRawDateTypesThrow() throws Exception {
  @SuppressWarnings("unchecked")
  Dao<Foo, String> dao = (Dao<Foo, String>) createMock(Dao.class);
  RuntimeExceptionDao<Foo, String> rtDao = new RuntimeExceptionDao<Foo, String>(dao);
  expect(dao.queryRaw(null, (DataType[]) null)).andThrow(new SQLException("Testing catch"));
  replay(dao);
  rtDao.queryRaw(null, (DataType[]) null);
  verify(dao);
}

代码示例来源:origin: j256/ormlite-core

@Test(expected = RuntimeException.class)
public void testQueryRawThrow() throws Exception {
  @SuppressWarnings("unchecked")
  Dao<Foo, String> dao = (Dao<Foo, String>) createMock(Dao.class);
  RuntimeExceptionDao<Foo, String> rtDao = new RuntimeExceptionDao<Foo, String>(dao);
  expect(dao.queryRaw(null)).andThrow(new SQLException("Testing catch"));
  replay(dao);
  rtDao.queryRaw(null);
  verify(dao);
}

代码示例来源:origin: j256/ormlite-core

@Test(expected = RuntimeException.class)
public void testQueryRawRowMapperThrow() throws Exception {
  @SuppressWarnings("unchecked")
  Dao<Foo, String> dao = (Dao<Foo, String>) createMock(Dao.class);
  RuntimeExceptionDao<Foo, String> rtDao = new RuntimeExceptionDao<Foo, String>(dao);
  expect(dao.queryRaw(null, (RawRowMapper<String>) null)).andThrow(new SQLException("Testing catch"));
  replay(dao);
  rtDao.queryRaw(null, (RawRowMapper<String>) null);
  verify(dao);
}

代码示例来源:origin: j256/ormlite-core

@Test(expected = SQLException.class)
public void testQueryRawObjectsThrow() throws Exception {
  Dao<Foo, Integer> dao = createDao(Foo.class, true);
  Foo foo = new Foo();
  assertEquals(1, dao.create(foo));
  DatabaseConnection conn = connectionSource.getReadWriteConnection(FOO_TABLE_NAME);
  try {
    conn.close();
    dao.queryRaw("SELECT * FROM FOO", new DataType[0]);
  } finally {
    connectionSource.releaseConnection(conn);
  }
}

相关文章