com.j256.ormlite.dao.RawRowMapper Java Examples
The following examples show how to use
com.j256.ormlite.dao.RawRowMapper.
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: JdbcRawResultsImplTest.java From ormlite-jdbc with ISC License | 6 votes |
@Test public void testCustomColumnNames() throws Exception { Dao<Foo, Integer> dao = createDao(Foo.class, true); Foo foo = new Foo(); foo.val = 1213213; assertEquals(1, dao.create(foo)); final String idName = "SOME_ID"; final String valName = "SOME_VAL"; final AtomicBoolean gotResult = new AtomicBoolean(false); GenericRawResults<Object> results = dao.queryRaw("select id as " + idName + ", val as " + valName + " from foo", new RawRowMapper<Object>() { @Override public Object mapRow(String[] columnNames, String[] resultColumns) { assertEquals(idName, columnNames[0]); assertEquals(valName, columnNames[1]); gotResult.set(true); return new Object(); } }); List<Object> list = results.getResults(); assertNotNull(list); assertEquals(1, list.size()); assertTrue(gotResult.get()); }
Example #2
Source File: StatementExecutor.java From ormlite-core with ISC License | 6 votes |
/** * Return a results object associated with an internal iterator is mapped by the user's rowMapper. */ public <UO> GenericRawResults<UO> queryRaw(ConnectionSource connectionSource, String query, RawRowMapper<UO> rowMapper, String[] arguments, ObjectCache objectCache) throws SQLException { logger.debug("executing raw query for: {}", query); if (arguments.length > 0) { // need to do the (Object) cast to force args to be a single object logger.trace("query arguments: {}", (Object) arguments); } DatabaseConnection connection = connectionSource.getReadOnlyConnection(tableInfo.getTableName()); CompiledStatement compiledStatement = null; try { compiledStatement = connection.compileStatement(query, StatementType.SELECT, noFieldTypes, DatabaseConnection.DEFAULT_RESULT_FLAGS, false); assignStatementArguments(compiledStatement, arguments); RawResultsImpl<UO> rawResults = new RawResultsImpl<UO>(connectionSource, connection, query, String[].class, compiledStatement, new UserRawRowMapper<UO>(rowMapper, this), objectCache); compiledStatement = null; connection = null; return rawResults; } finally { IOUtils.closeThrowSqlException(compiledStatement, "compiled statement"); if (connection != null) { connectionSource.releaseConnection(connection); } } }
Example #3
Source File: RawResultsImplTest.java From ormlite-core with ISC License | 6 votes |
@Test public void testCustomColumnNames() throws Exception { Dao<Foo, Integer> dao = createDao(Foo.class, true); Foo foo = new Foo(); foo.val = 1213213; assertEquals(1, dao.create(foo)); final String idName = "SOME_ID"; final String valName = "SOME_VAL"; final AtomicBoolean gotResult = new AtomicBoolean(false); GenericRawResults<Object> results = dao.queryRaw("select id as " + idName + ", val as " + valName + " from foo", new RawRowMapper<Object>() { @Override public Object mapRow(String[] columnNames, String[] resultColumns) { assertEquals(idName, columnNames[0]); assertEquals(valName, columnNames[1]); gotResult.set(true); return new Object(); } }); assertEquals(1, results.getResults().size()); results.close(); assertTrue(gotResult.get()); }
Example #4
Source File: RxBaseDaoImpl.java From AndroidStarter with Apache License 2.0 | 5 votes |
@Override public <UO> Observable<GenericRawResults<UO>> rxQueryRaw(final String query, final RawRowMapper<UO> mapper, final String... arguments) { final Func0<Observable<GenericRawResults<UO>>> loFunc = () -> { try { return Observable.just(queryRaw(query, mapper, arguments)); } catch (SQLException e) { return Observable.error(e); } }; return Observable.defer(loFunc); }
Example #5
Source File: StatementExecutor.java From ormlite-core with ISC License | 5 votes |
/** * Return a raw row mapper suitable for use with {@link Dao#queryRaw(String, RawRowMapper, String...)}. */ public RawRowMapper<T> getRawRowMapper() { if (rawRowMapper == null) { rawRowMapper = new RawRowMapperImpl<T, ID>(dao); } return rawRowMapper; }
Example #6
Source File: RxBaseDaoImpl.java From AndroidStarter with Apache License 2.0 | 4 votes |
@Override public Observable<RawRowMapper<DataType>> rxGetRawRowMapper() { final Func0<Observable<RawRowMapper<DataType>>> loFunc = () -> Observable.just(getRawRowMapper()); return Observable.defer(loFunc); }
Example #7
Source File: StatementExecutor.java From ormlite-core with ISC License | 4 votes |
public UserRawRowMapper(RawRowMapper<UO> mapper, GenericRowMapper<String[]> stringMapper) { this.mapper = mapper; this.stringRowMapper = stringMapper; }
Example #8
Source File: IRxDao.java From AndroidStarter with Apache License 2.0 | 2 votes |
/** * Similar to the {@link #queryRaw(String, String...)} but this iterator returns rows that you can map yourself. For * every result that is returned by the database, the {@link RawRowMapper#mapRow(String[], String[])} method is * called so you can convert the result columns into an object to be returned by the iterator. The arguments are * optional but can be set with strings to expand ? type of SQL. For a simple implementation of a raw row mapper, * see {@link #getRawRowMapper()}. */ <UO> Observable<GenericRawResults<UO>> rxQueryRaw(final String query, final RawRowMapper<UO> mapper, final String... arguments) ;
Example #9
Source File: IRxDao.java From AndroidStarter with Apache License 2.0 | 2 votes |
/** * Return a row mapper that is suitable for use with {@link #queryRaw(String, RawRowMapper, String...)}. This is a * bit experimental at this time. It most likely will _not_ work with all databases since the string output for each * data type is hard to forecast. Please provide feedback. */ Observable<RawRowMapper<T>> rxGetRawRowMapper();