本文整理汇总了Java中com.j256.ormlite.support.DatabaseResults类的典型用法代码示例。如果您正苦于以下问题:Java DatabaseResults类的具体用法?Java DatabaseResults怎么用?Java DatabaseResults使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DatabaseResults类属于com.j256.ormlite.support包,在下文中一共展示了DatabaseResults类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: queryForFirst
import com.j256.ormlite.support.DatabaseResults; //导入依赖的package包/类
public T queryForFirst(DatabaseConnection paramDatabaseConnection, PreparedStmt<T> paramPreparedStmt, ObjectCache paramObjectCache)
{
CompiledStatement localCompiledStatement = paramPreparedStmt.compile(paramDatabaseConnection, StatementBuilder.StatementType.SELECT);
try
{
DatabaseResults localDatabaseResults = localCompiledStatement.runQuery(paramObjectCache);
if (localDatabaseResults.first())
{
logger.debug("query-for-first of '{}' returned at least 1 result", paramPreparedStmt.getStatement());
Object localObject2 = paramPreparedStmt.mapRow(localDatabaseResults);
return localObject2;
}
logger.debug("query-for-first of '{}' returned at 0 results", paramPreparedStmt.getStatement());
return null;
}
finally
{
localCompiledStatement.close();
}
}
开发者ID:mmmsplay10,项目名称:QuizUpWinner,代码行数:21,代码来源:StatementExecutor.java
示例2: queryForLong
import com.j256.ormlite.support.DatabaseResults; //导入依赖的package包/类
public long queryForLong(DatabaseConnection paramDatabaseConnection, PreparedStmt<T> paramPreparedStmt)
{
CompiledStatement localCompiledStatement = paramPreparedStmt.compile(paramDatabaseConnection, StatementBuilder.StatementType.SELECT_LONG);
try
{
DatabaseResults localDatabaseResults = localCompiledStatement.runQuery(null);
if (localDatabaseResults.first())
{
long l = localDatabaseResults.getLong(0);
return l;
}
throw new SQLException("No result found in queryForLong: " + paramPreparedStmt.getStatement());
}
finally
{
localCompiledStatement.close();
}
}
开发者ID:mmmsplay10,项目名称:QuizUpWinner,代码行数:19,代码来源:StatementExecutor.java
示例3: resultToJava
import com.j256.ormlite.support.DatabaseResults; //导入依赖的package包/类
public <T> T resultToJava(DatabaseResults paramDatabaseResults, Map<String, Integer> paramMap)
{
Integer localInteger1 = (Integer)paramMap.get(this.columnName);
Integer localInteger2 = localInteger1;
if (localInteger1 == null)
{
localInteger2 = Integer.valueOf(paramDatabaseResults.findColumn(this.columnName));
paramMap.put(this.columnName, localInteger2);
}
Object localObject = this.fieldConverter.resultToJava(this, paramDatabaseResults, localInteger2.intValue());
if (this.fieldConfig.isForeign())
{
if (paramDatabaseResults.wasNull(localInteger2.intValue()))
return null;
}
else if (this.dataPersister.isPrimitive())
{
if ((this.fieldConfig.isThrowIfNull()) && (paramDatabaseResults.wasNull(localInteger2.intValue())))
throw new SQLException("Results value for primitive field '" + this.field.getName() + "' was an invalid null value");
}
else if ((!this.fieldConverter.isStreamType()) && (paramDatabaseResults.wasNull(localInteger2.intValue())))
return null;
return localObject;
}
开发者ID:mmmsplay10,项目名称:QuizUpWinner,代码行数:25,代码来源:FieldType.java
示例4: testDateStringResultInvalid
import com.j256.ormlite.support.DatabaseResults; //导入依赖的package包/类
@Test(expected = SQLException.class)
public void testDateStringResultInvalid() throws Exception {
Class<LocalString> clazz = LocalString.class;
Dao<LocalString, Object> dao = createDao(clazz, true);
LocalString foo = new LocalString();
foo.string = "not a date format";
assertEquals(1, dao.create(foo));
DatabaseConnection conn = connectionSource.getReadOnlyConnection(TABLE_NAME);
CompiledStatement stmt = null;
try {
stmt =
conn.compileStatement("select * from " + TABLE_NAME, StatementType.SELECT, noFieldTypes,
DatabaseConnection.DEFAULT_RESULT_FLAGS, true);
DatabaseResults results = stmt.runQuery(null);
assertTrue(results.next());
int colNum = results.findColumn(STRING_COLUMN);
DataType.DATE_STRING.getDataPersister().resultToJava(null, results, colNum);
} finally {
if (stmt != null) {
stmt.close();
}
connectionSource.releaseConnection(conn);
}
}
开发者ID:j256,项目名称:ormlite-tests,代码行数:25,代码来源:BaseDataTypeTest.java
示例5: testSerializableInvalidResult
import com.j256.ormlite.support.DatabaseResults; //导入依赖的package包/类
@Test(expected = SQLException.class)
public void testSerializableInvalidResult() throws Exception {
Class<LocalByteArray> clazz = LocalByteArray.class;
Dao<LocalByteArray, Object> dao = createDao(clazz, true);
LocalByteArray foo = new LocalByteArray();
foo.byteField = new byte[] { 1, 2, 3, 4, 5 };
assertEquals(1, dao.create(foo));
DatabaseConnection conn = connectionSource.getReadOnlyConnection(TABLE_NAME);
CompiledStatement stmt = null;
try {
stmt =
conn.compileStatement("select * from " + TABLE_NAME, StatementType.SELECT, noFieldTypes,
DatabaseConnection.DEFAULT_RESULT_FLAGS, true);
DatabaseResults results = stmt.runQuery(null);
assertTrue(results.next());
FieldType fieldType =
FieldType.createFieldType(connectionSource, TABLE_NAME,
LocalSerializable.class.getDeclaredField(SERIALIZABLE_COLUMN), LocalSerializable.class);
DataType.SERIALIZABLE.getDataPersister().resultToJava(fieldType, results, results.findColumn(BYTE_COLUMN));
} finally {
if (stmt != null) {
stmt.close();
}
connectionSource.releaseConnection(conn);
}
}
开发者ID:j256,项目名称:ormlite-tests,代码行数:27,代码来源:BaseDataTypeTest.java
示例6: testEnumStringResultsNoFieldType
import com.j256.ormlite.support.DatabaseResults; //导入依赖的package包/类
@Test
public void testEnumStringResultsNoFieldType() throws Exception {
Class<LocalEnumString> clazz = LocalEnumString.class;
Dao<LocalEnumString, Object> dao = createDao(clazz, true);
OurEnum val = OurEnum.SECOND;
LocalEnumString foo = new LocalEnumString();
foo.ourEnum = val;
assertEquals(1, dao.create(foo));
DatabaseConnection conn = connectionSource.getReadOnlyConnection(TABLE_NAME);
CompiledStatement stmt = null;
try {
stmt =
conn.compileStatement("select * from " + TABLE_NAME, StatementType.SELECT, noFieldTypes,
DatabaseConnection.DEFAULT_RESULT_FLAGS, true);
DatabaseResults results = stmt.runQuery(null);
assertTrue(results.next());
assertEquals(val.toString(),
DataType.ENUM_STRING.getDataPersister()
.resultToJava(null, results, results.findColumn(ENUM_COLUMN)));
} finally {
if (stmt != null) {
stmt.close();
}
connectionSource.releaseConnection(conn);
}
}
开发者ID:j256,项目名称:ormlite-tests,代码行数:27,代码来源:BaseDataTypeTest.java
示例7: queryForOne
import com.j256.ormlite.support.DatabaseResults; //导入依赖的package包/类
@Override
public <T> Object queryForOne(String statement, Object[] args, FieldType[] argFieldTypes,
GenericRowMapper<T> rowMapper, ObjectCache objectCache) throws SQLException {
PreparedStatement stmt =
connection.prepareStatement(statement, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
if (args != null) {
statementSetArgs(stmt, args, argFieldTypes);
}
DatabaseResults results = new H2DatabaseResults(stmt.executeQuery(), objectCache, true);
if (!results.next()) {
// no results at all
IOUtils.closeThrowSqlException(results, "results");
return null;
}
T first = rowMapper.mapRow(results);
if (results.next()) {
return MORE_THAN_ONE;
} else {
return first;
}
}
开发者ID:j256,项目名称:ormlite-core,代码行数:22,代码来源:H2DatabaseConnection.java
示例8: queryForLong
import com.j256.ormlite.support.DatabaseResults; //导入依赖的package包/类
/**
* Return a long value from a prepared query.
*/
public long queryForLong(DatabaseConnection databaseConnection, PreparedStmt<T> preparedStmt) throws SQLException {
CompiledStatement compiledStatement = preparedStmt.compile(databaseConnection, StatementType.SELECT_LONG);
DatabaseResults results = null;
try {
results = compiledStatement.runQuery(null);
if (results.first()) {
return results.getLong(0);
} else {
throw new SQLException("No result found in queryForLong: " + preparedStmt.getStatement());
}
} finally {
IOUtils.closeThrowSqlException(results, "results");
IOUtils.closeThrowSqlException(compiledStatement, "compiled statement");
}
}
开发者ID:j256,项目名称:ormlite-core,代码行数:19,代码来源:StatementExecutor.java
示例9: testMappedQuery
import com.j256.ormlite.support.DatabaseResults; //导入依赖的package包/类
@Test
public void testMappedQuery() throws Exception {
Field field = Foo.class.getDeclaredField(Foo.ID_COLUMN_NAME);
String tableName = "basefoo";
FieldType[] resultFieldTypes =
new FieldType[] { FieldType.createFieldType(connectionSource, tableName, field, Foo.class) };
BaseMappedQuery<Foo, Integer> baseMappedQuery = new BaseMappedQuery<Foo, Integer>(baseFooTableInfo,
"select * from " + tableName, new FieldType[0], resultFieldTypes) {
};
DatabaseResults results = createMock(DatabaseResults.class);
int colN = 1;
expect(results.getObjectCacheForRetrieve()).andReturn(null);
expect(results.getObjectCacheForStore()).andReturn(null);
expect(results.findColumn(Foo.ID_COLUMN_NAME)).andReturn(colN);
int id = 63365;
expect(results.getInt(colN)).andReturn(id);
replay(results);
Foo baseFoo = baseMappedQuery.mapRow(results);
assertNotNull(baseFoo);
assertEquals(id, baseFoo.id);
verify(results);
}
开发者ID:j256,项目名称:ormlite-core,代码行数:23,代码来源:BaseMappedQueryTest.java
示例10: checkResults
import com.j256.ormlite.support.DatabaseResults; //导入依赖的package包/类
private void checkResults(List<LocalFoo> foos, MappedPreparedStmt<LocalFoo, Integer> preparedQuery, int expectedNum)
throws SQLException {
DatabaseConnection conn = connectionSource.getReadOnlyConnection(TABLE_NAME);
CompiledStatement stmt = null;
try {
stmt = preparedQuery.compile(conn, StatementType.SELECT);
DatabaseResults results = stmt.runQuery(null);
int fooC = 0;
while (results.next()) {
LocalFoo foo2 = preparedQuery.mapRow(results);
assertEquals(foos.get(fooC).id, foo2.id);
fooC++;
}
assertEquals(expectedNum, fooC);
} finally {
IOUtils.closeThrowSqlException(stmt, "compiled statement");
connectionSource.releaseConnection(conn);
}
}
开发者ID:j256,项目名称:ormlite-core,代码行数:20,代码来源:MappedPreparedQueryTest.java
示例11: testHasNextThrow
import com.j256.ormlite.support.DatabaseResults; //导入依赖的package包/类
@Test(expected = IllegalStateException.class)
public void testHasNextThrow() throws Exception {
ConnectionSource cs = createMock(ConnectionSource.class);
cs.releaseConnection(null);
CompiledStatement stmt = createMock(CompiledStatement.class);
DatabaseResults results = createMock(DatabaseResults.class);
expect(stmt.runQuery(null)).andReturn(results);
expect(results.first()).andThrow(new SQLException("some database problem"));
stmt.close();
replay(stmt, results, cs);
SelectIterator<Foo, Integer> iterator =
new SelectIterator<Foo, Integer>(Foo.class, null, null, cs, null, stmt, "statement", null);
try {
iterator.hasNext();
} finally {
iterator.close();
}
}
开发者ID:j256,项目名称:ormlite-core,代码行数:19,代码来源:SelectIteratorTest.java
示例12: testNextThrow
import com.j256.ormlite.support.DatabaseResults; //导入依赖的package包/类
@Test(expected = IllegalStateException.class)
public void testNextThrow() throws Exception {
ConnectionSource cs = createMock(ConnectionSource.class);
cs.releaseConnection(null);
CompiledStatement stmt = createMock(CompiledStatement.class);
DatabaseResults results = createMock(DatabaseResults.class);
expect(stmt.runQuery(null)).andReturn(results);
expect(results.first()).andThrow(new SQLException("some result problem"));
@SuppressWarnings("unchecked")
GenericRowMapper<Foo> mapper = (GenericRowMapper<Foo>) createMock(GenericRowMapper.class);
stmt.close();
replay(stmt, mapper, cs, results);
SelectIterator<Foo, Integer> iterator =
new SelectIterator<Foo, Integer>(Foo.class, null, mapper, cs, null, stmt, "statement", null);
try {
iterator.hasNext();
} finally {
iterator.close();
}
verify(stmt, mapper, cs, results);
}
开发者ID:j256,项目名称:ormlite-core,代码行数:22,代码来源:SelectIteratorTest.java
示例13: testQueryRawDatabaseResults
import com.j256.ormlite.support.DatabaseResults; //导入依赖的package包/类
@Test
public void testQueryRawDatabaseResults() throws Exception {
Dao<Foo, Object> dao = createDao(Foo.class, true);
Foo foo = new Foo();
foo.val = 342234232;
assertEquals(1, dao.create(foo));
CloseableIterator<Foo> iterator =
dao.iterator(dao.queryBuilder().where().eq(Foo.VAL_COLUMN_NAME, foo.val).prepare());
try {
DatabaseResults results = iterator.getRawResults();
assertTrue(results.first());
assertTrue(results.getColumnCount() >= 4);
int valIndex = results.findColumn(Foo.VAL_COLUMN_NAME);
assertEquals(foo.val, results.getInt(valIndex));
assertFalse(results.next());
} finally {
iterator.closeQuietly();
}
}
开发者ID:j256,项目名称:ormlite-core,代码行数:21,代码来源:CloseableIteratorTest.java
示例14: testSerializableNoValue
import com.j256.ormlite.support.DatabaseResults; //导入依赖的package包/类
@Test
public void testSerializableNoValue() throws Exception {
Class<LocalSerializable> clazz = LocalSerializable.class;
Dao<LocalSerializable, Object> dao = createDao(clazz, true);
LocalSerializable foo = new LocalSerializable();
foo.serializable = null;
assertEquals(1, dao.create(foo));
DatabaseConnection conn = connectionSource.getReadOnlyConnection(TABLE_NAME);
CompiledStatement stmt = null;
try {
stmt = conn.compileStatement("select * from " + TABLE_NAME, StatementType.SELECT, noFieldTypes,
DatabaseConnection.DEFAULT_RESULT_FLAGS, true);
DatabaseResults results = stmt.runQuery(null);
assertTrue(results.next());
FieldType fieldType = FieldType.createFieldType(connectionSource, TABLE_NAME,
clazz.getDeclaredField(SERIALIZABLE_COLUMN), clazz);
assertNull(DataType.SERIALIZABLE.getDataPersister().resultToJava(fieldType, results,
results.findColumn(SERIALIZABLE_COLUMN)));
} finally {
if (stmt != null) {
stmt.close();
}
connectionSource.releaseConnection(conn);
}
}
开发者ID:j256,项目名称:ormlite-core,代码行数:26,代码来源:SerializableTypeTest.java
示例15: testSerializableInvalidResult
import com.j256.ormlite.support.DatabaseResults; //导入依赖的package包/类
@Test(expected = SQLException.class)
public void testSerializableInvalidResult() throws Exception {
Class<LocalByteArray> clazz = LocalByteArray.class;
Dao<LocalByteArray, Object> dao = createDao(clazz, true);
LocalByteArray foo = new LocalByteArray();
foo.byteField = new byte[] { 1, 2, 3, 4, 5 };
assertEquals(1, dao.create(foo));
DatabaseConnection conn = connectionSource.getReadOnlyConnection(TABLE_NAME);
CompiledStatement stmt = null;
try {
stmt = conn.compileStatement("select * from " + TABLE_NAME, StatementType.SELECT, noFieldTypes,
DatabaseConnection.DEFAULT_RESULT_FLAGS, true);
DatabaseResults results = stmt.runQuery(null);
assertTrue(results.next());
FieldType fieldType = FieldType.createFieldType(connectionSource, TABLE_NAME,
LocalSerializable.class.getDeclaredField(SERIALIZABLE_COLUMN), LocalSerializable.class);
DataType.SERIALIZABLE.getDataPersister().resultToJava(fieldType, results, results.findColumn(BYTE_COLUMN));
} finally {
if (stmt != null) {
stmt.close();
}
connectionSource.releaseConnection(conn);
}
}
开发者ID:j256,项目名称:ormlite-core,代码行数:25,代码来源:SerializableTypeTest.java
示例16: testDateStringResultInvalid
import com.j256.ormlite.support.DatabaseResults; //导入依赖的package包/类
@Test(expected = SQLException.class)
public void testDateStringResultInvalid() throws Exception {
Class<LocalString> clazz = LocalString.class;
Dao<LocalString, Object> dao = createDao(clazz, true);
LocalString foo = new LocalString();
foo.string = "not a date format";
assertEquals(1, dao.create(foo));
DatabaseConnection conn = connectionSource.getReadOnlyConnection(FOO_TABLE_NAME);
CompiledStatement stmt = null;
try {
stmt = conn.compileStatement("select * from " + TABLE_NAME, StatementType.SELECT, noFieldTypes,
DatabaseConnection.DEFAULT_RESULT_FLAGS, true);
DatabaseResults results = stmt.runQuery(null);
assertTrue(results.next());
int colNum = results.findColumn(STRING_COLUMN);
DataType.DATE_STRING.getDataPersister().resultToJava(null, results, colNum);
} finally {
if (stmt != null) {
stmt.close();
}
connectionSource.releaseConnection(conn);
}
}
开发者ID:j256,项目名称:ormlite-core,代码行数:24,代码来源:DateStringTypeTest.java
示例17: testEnumIntResultsNoFieldType
import com.j256.ormlite.support.DatabaseResults; //导入依赖的package包/类
@Test
public void testEnumIntResultsNoFieldType() throws Exception {
Class<LocalEnumInt> clazz = LocalEnumInt.class;
Dao<LocalEnumInt, Object> dao = createDao(clazz, true);
OurEnum val = OurEnum.SECOND;
LocalEnumInt foo = new LocalEnumInt();
foo.ourEnum = val;
assertEquals(1, dao.create(foo));
DatabaseConnection conn = connectionSource.getReadOnlyConnection(FOO_TABLE_NAME);
CompiledStatement stmt = null;
try {
stmt = conn.compileStatement("select * from " + TABLE_NAME, StatementType.SELECT, noFieldTypes,
DatabaseConnection.DEFAULT_RESULT_FLAGS, true);
DatabaseResults results = stmt.runQuery(null);
assertTrue(results.next());
assertEquals(val.ordinal(), DataType.ENUM_INTEGER.getDataPersister().resultToJava(null, results,
results.findColumn(ENUM_COLUMN)));
} finally {
if (stmt != null) {
stmt.close();
}
connectionSource.releaseConnection(conn);
}
}
开发者ID:j256,项目名称:ormlite-core,代码行数:25,代码来源:EnumIntegerTypeTest.java
示例18: testEnumStringResultsNoFieldType
import com.j256.ormlite.support.DatabaseResults; //导入依赖的package包/类
@Test
public void testEnumStringResultsNoFieldType() throws Exception {
Dao<LocalEnumString, Object> dao = createDao(LocalEnumString.class, true);
OurEnum val = OurEnum.SECOND;
LocalEnumString foo = new LocalEnumString();
foo.ourEnum = val;
assertEquals(1, dao.create(foo));
DatabaseConnection conn = connectionSource.getReadOnlyConnection(TABLE_NAME);
CompiledStatement stmt = null;
try {
stmt = conn.compileStatement("select * from " + TABLE_NAME, StatementType.SELECT, noFieldTypes,
DatabaseConnection.DEFAULT_RESULT_FLAGS, true);
DatabaseResults results = stmt.runQuery(null);
assertTrue(results.next());
assertEquals(val.toString(), DataType.ENUM_STRING.getDataPersister().resultToJava(null, results,
results.findColumn(ENUM_COLUMN)));
} finally {
if (stmt != null) {
stmt.close();
}
connectionSource.releaseConnection(conn);
}
}
开发者ID:j256,项目名称:ormlite-core,代码行数:24,代码来源:EnumStringTypeTest.java
示例19: testSerializableNull
import com.j256.ormlite.support.DatabaseResults; //导入依赖的package包/类
@Test
public void testSerializableNull() throws Exception {
Field[] fields = SerializableField.class.getDeclaredFields();
assertTrue(fields.length >= 1);
Field field = fields[0];
FieldType fieldType = FieldType.createFieldType(connectionSource, SerializableField.class.getSimpleName(),
field, SerializableField.class);
DatabaseResults results = createMock(DatabaseResults.class);
int fieldNum = 1;
expect(results.findColumn(field.getName())).andReturn(fieldNum);
expect(results.getTimestamp(fieldNum)).andReturn(null);
expect(results.wasNull(fieldNum)).andReturn(true);
replay(results);
assertNull(fieldType.resultToJava(results, new HashMap<String, Integer>()));
verify(results);
}
开发者ID:j256,项目名称:ormlite-core,代码行数:17,代码来源:FieldTypeTest.java
示例20: rxMapSelectStarRow
import com.j256.ormlite.support.DatabaseResults; //导入依赖的package包/类
@Override
public Observable<DataType> rxMapSelectStarRow(final DatabaseResults results) {
final Func0<Observable<DataType>> loFunc = () -> {
try {
return Observable.just(mapSelectStarRow(results));
} catch (SQLException e) {
return Observable.error(e);
}
};
return Observable.defer(loFunc);
}
开发者ID:RoRoche,项目名称:AndroidStarter,代码行数:12,代码来源:RxBaseDaoImpl.java
注:本文中的com.j256.ormlite.support.DatabaseResults类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论