Java Code Examples for com.j256.ormlite.support.DatabaseConnection#delete()

The following examples show how to use com.j256.ormlite.support.DatabaseConnection#delete() . 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: MappedDeleteCollection.java    From ormlite-core with ISC License 6 votes vote down vote up
private static <T, ID> int updateRows(DatabaseConnection databaseConnection, Class<T> clazz,
		MappedDeleteCollection<T, ID> deleteCollection, Object[] args, ObjectCache objectCache)
		throws SQLException {
	try {
		int rowC = databaseConnection.delete(deleteCollection.statement, args, deleteCollection.argFieldTypes);
		if (rowC > 0 && objectCache != null) {
			for (Object id : args) {
				objectCache.remove(clazz, id);
			}
		}
		logger.debug("delete-collection with statement '{}' and {} args, changed {} rows",
				deleteCollection.statement, args.length, rowC);
		if (args.length > 0) {
			// need to do the (Object) cast to force args to be a single object
			logger.trace("delete-collection arguments: {}", (Object) args);
		}
		return rowC;
	} catch (SQLException e) {
		throw SqlExceptionUtil.create("Unable to run delete collection stmt: " + deleteCollection.statement, e);
	}
}
 
Example 2
Source File: MappedDelete.java    From ormlite-core with ISC License 6 votes vote down vote up
/**
 * Delete the object from the database.
 */
public int delete(DatabaseConnection databaseConnection, T data, ObjectCache objectCache) throws SQLException {
	try {
		Object[] args = getFieldObjects(data);
		int rowC = databaseConnection.delete(statement, args, argFieldTypes);
		logger.debug("delete data with statement '{}' and {} args, changed {} rows", statement, args.length, rowC);
		if (args.length > 0) {
			// need to do the (Object) cast to force args to be a single object
			logger.trace("delete arguments: {}", (Object) args);
		}
		if (rowC > 0 && objectCache != null) {
			Object id = idField.extractJavaFieldToSqlArgValue(data);
			objectCache.remove(clazz, id);
		}
		return rowC;
	} catch (SQLException e) {
		throw SqlExceptionUtil.create("Unable to run delete stmt on object " + data + ": " + statement, e);
	}
}
 
Example 3
Source File: MappedDelete.java    From ormlite-core with ISC License 6 votes vote down vote up
/**
 * Delete the object from the database.
 */
public int deleteById(DatabaseConnection databaseConnection, ID id, ObjectCache objectCache) throws SQLException {
	try {
		Object[] args = new Object[] { convertIdToFieldObject(id) };
		int rowC = databaseConnection.delete(statement, args, argFieldTypes);
		logger.debug("delete data with statement '{}' and {} args, changed {} rows", statement, args.length, rowC);
		if (args.length > 0) {
			// need to do the (Object) cast to force args to be a single object
			logger.trace("delete arguments: {}", (Object) args);
		}
		if (rowC > 0 && objectCache != null) {
			objectCache.remove(clazz, id);
		}
		return rowC;
	} catch (SQLException e) {
		throw SqlExceptionUtil.create("Unable to run deleteById stmt on id " + id + ": " + statement, e);
	}
}