com.j256.ormlite.stmt.GenericRowMapper Java Examples
The following examples show how to use
com.j256.ormlite.stmt.GenericRowMapper.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JdbcDatabaseConnectionTest.java From ormlite-jdbc with ISC License | 6 votes |
@Test public void testQueryForOneReleaseConnection() throws Exception { Connection connection = createMock(Connection.class); PreparedStatement prepStmt = createMock(PreparedStatement.class); GeneratedKeyHolder keyHolder = createMock(GeneratedKeyHolder.class); ResultSet resultSet = createMock(ResultSet.class); @SuppressWarnings("unchecked") GenericRowMapper<Foo> rowMapper = createMock(GenericRowMapper.class); JdbcDatabaseConnection jdc = new JdbcDatabaseConnection(connection); String statement = "statement"; expect(connection.prepareStatement(statement, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY)) .andReturn(prepStmt); expect(prepStmt.executeQuery()).andReturn(resultSet); expect(resultSet.getMetaData()).andReturn(null); expect(resultSet.next()).andReturn(false); resultSet.close(); expect(prepStmt.getMoreResults()).andReturn(false); // should close the statement prepStmt.close(); connection.close(); replay(connection, prepStmt, keyHolder, resultSet, rowMapper); jdc.queryForOne(statement, new Object[0], new FieldType[0], rowMapper, null); jdc.close(); verify(connection, prepStmt, keyHolder, resultSet, rowMapper); }
Example #2
Source File: H2DatabaseConnection.java From ormlite-core with ISC License | 6 votes |
@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; } }
Example #3
Source File: RxBaseDaoImpl.java From AndroidStarter with Apache License 2.0 | 5 votes |
@Override public Observable<GenericRowMapper<DataType>> rxGetSelectStarRowMapper() { final Func0<Observable<GenericRowMapper<DataType>>> loFunc = () -> { try { return Observable.just(getSelectStarRowMapper()); } catch (SQLException e) { return Observable.error(e); } }; return Observable.defer(loFunc); }
Example #4
Source File: RuntimeExceptionDao.java From ormlite-core with ISC License | 5 votes |
/** * @see Dao#getSelectStarRowMapper() */ @Override public GenericRowMapper<T> getSelectStarRowMapper() { try { return dao.getSelectStarRowMapper(); } catch (SQLException e) { logMessage(e, "getSelectStarRowMapper threw exception"); throw new RuntimeException(e); } }
Example #5
Source File: DatabaseConnectionProxy.java From ormlite-core with ISC License | 5 votes |
@Override public <T> Object queryForOne(String statement, Object[] args, FieldType[] argfieldTypes, GenericRowMapper<T> rowMapper, ObjectCache objectCache) throws SQLException { if (proxy == null) { return null; } else { return proxy.queryForOne(statement, args, argfieldTypes, rowMapper, objectCache); } }
Example #6
Source File: FieldTypeTest.java From ormlite-core with ISC License | 5 votes |
@SuppressWarnings("unchecked") @Test public void testForeignAutoRefresh() throws Exception { Field field = ForeignAutoRefresh.class.getDeclaredField("foreign"); ConnectionSource connectionSource = createMock(ConnectionSource.class); DatabaseConnection connection = createMock(DatabaseConnection.class); expect(connectionSource.getDatabaseType()).andReturn(databaseType).anyTimes(); expect(connectionSource.getReadOnlyConnection("ForeignAutoRefresh")).andReturn(connection); ForeignForeign foreignForeign = new ForeignForeign(); String stuff = "21312j3213"; int id = 4123123; foreignForeign.id = id; foreignForeign.stuff = stuff; expect(connection.queryForOne(isA(String.class), isA(Object[].class), isA(FieldType[].class), isA(GenericRowMapper.class), (ObjectCache) isNull())).andReturn(foreignForeign); connectionSource.releaseConnection(connection); DatabaseResults results = createMock(DatabaseResults.class); ForeignAutoRefresh foreign = new ForeignAutoRefresh(); replay(results, connectionSource, connection); FieldType fieldType = FieldType.createFieldType(databaseType, ForeignAutoRefresh.class.getSimpleName(), field, ForeignAutoRefresh.class); fieldType.configDaoInformation(connectionSource, ForeignAutoRefresh.class); assertNull(foreign.foreign); fieldType.assignField(connectionSource, foreign, id, false, null); assertNotNull(foreign.foreign); assertEquals(id, foreign.foreign.id); assertEquals(stuff, foreign.foreign.stuff); verify(results, connectionSource, connection); }
Example #7
Source File: JdbcDatabaseConnection.java From ormlite-jdbc with ISC License | 4 votes |
@Override public <T> Object queryForOne(String statement, Object[] args, FieldType[] argFieldTypes, GenericRowMapper<T> rowMapper, ObjectCache objectCache) throws SQLException { return queryForOne(statement, args, argFieldTypes, rowMapper, objectCache, "query for one"); }
Example #8
Source File: BaseDaoImpl.java From ormlite-core with ISC License | 4 votes |
@Override public GenericRowMapper<T> getSelectStarRowMapper() throws SQLException { return statementExecutor.getSelectStarRowMapper(); }
Example #9
Source File: IRxDao.java From AndroidStarter with Apache License 2.0 | 2 votes |
/** * Return a row mapper that is suitable for mapping results from a rxQuery to select * (star). */ Observable<GenericRowMapper<T>> rxGetSelectStarRowMapper();
Example #10
Source File: Dao.java From ormlite-core with ISC License | 2 votes |
/** * Return a row mapper that is suitable for mapping results from a query to select * (star). */ public GenericRowMapper<T> getSelectStarRowMapper() throws SQLException;
Example #11
Source File: DatabaseConnection.java From ormlite-core with ISC License | 2 votes |
/** * Perform a SQL query with the associated SQL statement, arguments, and types and returns a single result. * * @param statement * SQL statement to use for deleting. * @param args * Object arguments for the SQL '?'s. * @param argfieldTypes * Field types of the arguments. * @param rowMapper * The mapper to use to convert the row into the returned object. * @param objectCache * Any object cache associated with the query or null if none. * @return The first data item returned by the query which can be cast to T, null if none, the object * {@link #MORE_THAN_ONE} if more than one result was found. */ public <T> Object queryForOne(String statement, Object[] args, FieldType[] argfieldTypes, GenericRowMapper<T> rowMapper, ObjectCache objectCache) throws SQLException;