com.j256.ormlite.stmt.PreparedUpdate Java Examples

The following examples show how to use com.j256.ormlite.stmt.PreparedUpdate. 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: RxBaseDaoImpl.java    From AndroidStarter with Apache License 2.0 5 votes vote down vote up
@Override
public Observable<Integer> rxUpdate(final PreparedUpdate<DataType> preparedUpdate) {
    final Func0<Observable<Integer>> loFunc = () -> {
        try {
            return Observable.just(update(preparedUpdate));
        } catch (SQLException e) {
            return Observable.error(e);
        }
    };
    return Observable.defer(loFunc);
}
 
Example #2
Source File: BaseDaoImpl.java    From ormlite-core with ISC License 5 votes vote down vote up
@Override
public int update(PreparedUpdate<T> preparedUpdate) throws SQLException {
	checkForInitialized();
	DatabaseConnection connection = connectionSource.getReadWriteConnection(tableInfo.getTableName());
	try {
		return statementExecutor.update(connection, preparedUpdate);
	} finally {
		connectionSource.releaseConnection(connection);
	}
}
 
Example #3
Source File: RuntimeExceptionDao.java    From ormlite-core with ISC License 5 votes vote down vote up
/**
 * @see Dao#update(PreparedUpdate)
 */
@Override
public int update(PreparedUpdate<T> preparedUpdate) {
	try {
		return dao.update(preparedUpdate);
	} catch (SQLException e) {
		logMessage(e, "update threw exception on: " + preparedUpdate);
		throw new RuntimeException(e);
	}
}
 
Example #4
Source File: RuntimeExceptionDaoTest.java    From ormlite-core with ISC License 5 votes vote down vote up
@Test(expected = RuntimeException.class)
public void testUpdatePreparedThrow() 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.update((PreparedUpdate<Foo>) null)).andThrow(new SQLException("Testing catch"));
	replay(dao);
	rtDao.update((PreparedUpdate<Foo>) null);
	verify(dao);
}
 
Example #5
Source File: MetadataReferenceDao.java    From geopackage-core-java with MIT License 3 votes vote down vote up
/**
 * Remove metadata references (by updating the field to null) with foreign
 * keys to the metadata parent id
 * 
 * @param parentId
 *            parent id
 * @return updated count
 * @throws SQLException
 *             upon failure
 */
public int removeMetadataParent(long parentId) throws SQLException {

	UpdateBuilder<MetadataReference, Void> ub = updateBuilder();
	ub.updateColumnValue(MetadataReference.COLUMN_PARENT_ID, null);

	ub.where().eq(MetadataReference.COLUMN_PARENT_ID, parentId);

	PreparedUpdate<MetadataReference> update = ub.prepare();
	int updated = update(update);

	return updated;
}
 
Example #6
Source File: IRxDao.java    From AndroidStarter with Apache License 2.0 2 votes vote down vote up
/**
 * Update all rows in the table according to the prepared statement parameter. To use this, the
 * {@link UpdateBuilder} must have set-columns applied to it using the
 * {@link UpdateBuilder#updateColumnValue(String, Object)} or
 * {@link UpdateBuilder#updateColumnExpression(String, String)} methods.
 *
 * @param preparedUpdate A prepared statement to match database rows to be rxDeleted and define the columns to update.
 * @return The number of rows updated in the database.
 * @throws SQLException             on any SQL problems.
 * @throws IllegalArgumentException If there is only an ID field in the object. See the {@link #updateId} method.
 */
Observable<Integer> rxUpdate(final PreparedUpdate<T> preparedUpdate);
 
Example #7
Source File: Dao.java    From ormlite-core with ISC License 2 votes vote down vote up
/**
 * Update all rows in the table according to the prepared statement parameter. To use this, the
 * {@link UpdateBuilder} must have set-columns applied to it using the
 * {@link UpdateBuilder#updateColumnValue(String, Object)} or
 * {@link UpdateBuilder#updateColumnExpression(String, String)} methods.
 * 
 * @param preparedUpdate
 *            A prepared statement to match database rows to be deleted and define the columns to update.
 * @return The number of rows updated in the database.
 * @throws SQLException
 *             on any SQL problems.
 * @throws IllegalArgumentException
 *             If there is only an ID field in the object. See the {@link #updateId} method.
 */
public int update(PreparedUpdate<T> preparedUpdate) throws SQLException;