com.j256.ormlite.stmt.DeleteBuilder Java Examples

The following examples show how to use com.j256.ormlite.stmt.DeleteBuilder. 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: BaseDaoImplTest.java    From ormlite-core with ISC License 6 votes vote down vote up
@Test
public void testDeletePreparedStatement() throws Exception {
	Dao<Foo, Integer> dao = createDao(Foo.class, true);
	Foo foo1 = new Foo();
	assertEquals(1, dao.create(foo1));
	Foo foo2 = new Foo();
	assertEquals(1, dao.create(foo2));

	assertNotNull(dao.queryForId(foo1.id));
	assertNotNull(dao.queryForId(foo2.id));

	DeleteBuilder<Foo, Integer> deleteBuilder = dao.deleteBuilder();
	deleteBuilder.where().eq(Foo.ID_COLUMN_NAME, foo1.id);
	assertEquals(1, dao.delete(deleteBuilder.prepare()));

	assertEquals(1, dao.queryForAll().size());
	assertNull(dao.queryForId(foo1.id));
	assertNotNull(dao.queryForId(foo2.id));
}
 
Example #2
Source File: LocalAlbumBiz.java    From android-project-wo2b with Apache License 2.0 6 votes vote down vote up
@Override
public int deleteAll()
{
	try
	{
		DeleteBuilder<FocusItemInfo, Long> deleteBuilder = mFocusItemInfoDao.deleteBuilder();
		deleteBuilder.where().isNotNull("id");
		return deleteBuilder.delete();
	}
	catch (SQLException e)
	{
		e.printStackTrace();
	}
	
	return super.deleteAll();
}
 
Example #3
Source File: MyFavoritesBiz.java    From android-project-wo2b with Apache License 2.0 6 votes vote down vote up
@Override
public int deleteAll()
{
	try
	{
		DeleteBuilder<MyFavorites, Long> deleteBuilder = mMyFavoritesDao.deleteBuilder();
		deleteBuilder.where().isNotNull("albumid");
		
		return deleteBuilder.delete();
	}
	catch (SQLException e)
	{
		e.printStackTrace();
	}
	
	return super.deleteAll();
}
 
Example #4
Source File: PhotoBiz.java    From android-project-wo2b with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param albumid
 * @return
 */
public int deleteByAlbumid(String albumid)
{
	try
	{
		DeleteBuilder<PhotoInfo, Long> deleteBuilder = mPhotoDao.deleteBuilder();
		deleteBuilder.where().eq("albumid", albumid);
		return deleteBuilder.delete();
	}
	catch (SQLException e)
	{
		e.printStackTrace();
	}
	
	return super.deleteAll();
}
 
Example #5
Source File: AlbumBiz.java    From android-project-wo2b with Apache License 2.0 6 votes vote down vote up
@Override
public int deleteAll()
{
	try
	{
		DeleteBuilder<AlbumInfo, Long> deleteBuilder = mAlbumDao.deleteBuilder();
		deleteBuilder.where().isNotNull("albumid");
		return deleteBuilder.delete();
	}
	catch (SQLException e)
	{
		e.printStackTrace();
	}
	
	return super.deleteAll();
}
 
Example #6
Source File: DatabaseHelper.java    From android-overlay-protection with Apache License 2.0 6 votes vote down vote up
/**
 * This is called when your application is upgraded and it has a higher version number. This allows you to adjust
 * the various data to match the new version number.
 */
@Override
public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource, int oldVersion, int newVersion) {
    try {
        Log.i(TAG, "onUpgrade");
        TableUtils.dropTable(connectionSource, SuspectedApp.class, true);
        Log.d(TAG, String.format("Dropped suspected app table!"));
        Dao<WhiteEntry, Integer> whiteListDao = getWhiteListDao();
        DeleteBuilder<WhiteEntry, Integer> deleteBuilder = whiteListDao.deleteBuilder();
        deleteBuilder.where().eq("systemEntry", Boolean.TRUE);
        int deleted = deleteBuilder.delete();
        Log.d(TAG, String.format("Delete %d old system whitelist entries", deleted));
        onCreate(db, connectionSource);
    } catch (SQLException e) {
        Log.e(TAG, "Can't drop databases", e);
        throw new RuntimeException(e);
    }
}
 
Example #7
Source File: NoteManager.java    From ETSMobile-Android2 with Apache License 2.0 6 votes vote down vote up
/**
 * Deletes marks in DB that doesn't exist on API
 *
 * @param
 */
private void deleteExpiredListeDesElementsEvaluation(String id) {
    DatabaseHelper dbHelper = new DatabaseHelper(context);

    try {

        Dao<ListeDesElementsEvaluation, String> listeDesElementsEvaluationDao = dbHelper.getDao(ListeDesElementsEvaluation.class);
        ListeDesElementsEvaluation listeDesElementsEvaluation = listeDesElementsEvaluationDao.queryForId(id);

        if (listeDesElementsEvaluation != null) {
            Dao<ElementEvaluation, String> elementsEvaluationDao = dbHelper.getDao(ElementEvaluation.class);
            DeleteBuilder<ElementEvaluation, String> deleteBuilder = elementsEvaluationDao.deleteBuilder();

            Where where = deleteBuilder.where();
            where.eq("listeDesElementsEvaluation_id", listeDesElementsEvaluation);

            deleteBuilder.delete();
        }

        listeDesElementsEvaluationDao.deleteById(id);


    } catch (SQLException e) {
        e.printStackTrace();
    }
}
 
Example #8
Source File: FeatureTileLinkDao.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public int delete(FeatureTileLink data) throws SQLException {
	DeleteBuilder<FeatureTileLink, FeatureTileLinkKey> db = deleteBuilder();

	db.where()
			.eq(FeatureTileLink.COLUMN_FEATURE_TABLE_NAME,
					data.getFeatureTableName())
			.and()
			.eq(FeatureTileLink.COLUMN_TILE_TABLE_NAME,
					data.getTileTableName());

	PreparedDelete<FeatureTileLink> deleteQuery = db.prepare();
	int deleted = delete(deleteQuery);
	return deleted;
}
 
Example #9
Source File: TableIndexDao.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * Delete the TableIndex, cascading
 * 
 * @param tableIndex
 *            table index
 * @return rows deleted
 * @throws SQLException
 *             upon deletion error
 */
public int deleteCascade(TableIndex tableIndex) throws SQLException {
	int count = 0;

	if (tableIndex != null) {

		// Delete Geometry Indices
		GeometryIndexDao geometryIndexDao = getGeometryIndexDao();
		if (geometryIndexDao.isTableExists()) {
			DeleteBuilder<GeometryIndex, GeometryIndexKey> db = geometryIndexDao
					.deleteBuilder();
			db.where().eq(GeometryIndex.COLUMN_TABLE_NAME,
					tableIndex.getTableName());
			PreparedDelete<GeometryIndex> deleteQuery = db.prepare();
			geometryIndexDao.delete(deleteQuery);
		}

		count = delete(tableIndex);
	}
	return count;
}
 
Example #10
Source File: FeatureTableCoreIndex.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * Clear the Geometry Indices for the table name
 * 
 * @return number of rows deleted
 */
private int clearGeometryIndices() {
	int deleted = 0;
	DeleteBuilder<GeometryIndex, GeometryIndexKey> db = geometryIndexDao
			.deleteBuilder();
	try {
		db.where().eq(GeometryIndex.COLUMN_TABLE_NAME, tableName);
		PreparedDelete<GeometryIndex> deleteQuery = db.prepare();
		deleted = geometryIndexDao.delete(deleteQuery);
	} catch (SQLException e) {
		throw new GeoPackageException(
				"Failed to clear Geometry Index rows for GeoPackage: "
						+ geoPackage.getName() + ", Table Name: "
						+ tableName + ", Column Name: " + columnName,
				e);
	}

	return deleted;
}
 
Example #11
Source File: GriddedCoverageDao.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * Delete by table name
 * 
 * @param tableName
 *            table name
 * @return deleted count
 */
public int delete(String tableName) {
	DeleteBuilder<GriddedCoverage, Long> db = deleteBuilder();

	int deleted = 0;

	try {
		db.where().eq(GriddedCoverage.COLUMN_TILE_MATRIX_SET_NAME,
				tableName);

		PreparedDelete<GriddedCoverage> deleteQuery = db.prepare();
		deleted = delete(deleteQuery);
	} catch (SQLException e) {
		throw new GeoPackageException(
				"Failed to delete Gridded Coverage by Table Name: "
						+ tableName, e);
	}

	return deleted;
}
 
Example #12
Source File: GriddedTileDao.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * Delete by table name
 * 
 * @param tableName
 *            table name
 * @return deleted count
 */
public int delete(String tableName) {
	DeleteBuilder<GriddedTile, Long> db = deleteBuilder();

	int deleted = 0;

	try {
		db.where().eq(GriddedTile.COLUMN_TABLE_NAME, tableName);

		PreparedDelete<GriddedTile> deleteQuery = db.prepare();
		deleted = delete(deleteQuery);
	} catch (SQLException e) {
		throw new GeoPackageException(
				"Failed to delete Gridded Tile by Table Name: " + tableName,
				e);
	}

	return deleted;
}
 
Example #13
Source File: GeometryColumnsSfSqlDao.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public int delete(GeometryColumnsSfSql data) throws SQLException {
	DeleteBuilder<GeometryColumnsSfSql, TableColumnKey> db = deleteBuilder();

	db.where()
			.eq(GeometryColumnsSfSql.COLUMN_F_TABLE_NAME,
					data.getFTableName())
			.and()
			.eq(GeometryColumnsSfSql.COLUMN_F_GEOMETRY_COLUMN,
					data.getFGeometryColumn());

	PreparedDelete<GeometryColumnsSfSql> deleteQuery = db.prepare();
	int deleted = delete(deleteQuery);
	return deleted;
}
 
Example #14
Source File: MessageDataManager.java    From q-municate-android with Apache License 2.0 6 votes vote down vote up
public void deleteTempMessages(List<Long> dialogOccupantsIdsList) {
    try {
        DeleteBuilder<Message, Long> deleteBuilder = dao.deleteBuilder();

        Where<Message, Long> where = deleteBuilder.where();
        where.and(
                where.in(DialogOccupant.Column.ID, dialogOccupantsIdsList),
                where.or(
                        where.eq(Message.Column.STATE, State.TEMP_LOCAL),
                        where.eq(Message.Column.STATE, State.TEMP_LOCAL_UNREAD)
                )
        );

        if (deleteBuilder.delete() > 0) {
            //TODO VT need to think how to send IDs to observers
            notifyObserversDeletedById(dialogOccupantsIdsList);
        }
    } catch (SQLException e) {
        ErrorUtils.logError(e);
    }

}
 
Example #15
Source File: JdbcBaseDaoImplTest.java    From ormlite-jdbc with ISC License 6 votes vote down vote up
@Test
public void testDeletePreparedStmtIn() throws Exception {
	Dao<Foo, Integer> fooDao = createDao(Foo.class, true);
	List<Integer> fooIdList = new ArrayList<Integer>();
	for (int i = 0; i < 100; i++) {
		Foo foo = new Foo();
		assertEquals(1, fooDao.create(foo));
		fooIdList.add(foo.id);
	}

	DeleteBuilder<Foo, Integer> stmtBuilder = fooDao.deleteBuilder();
	stmtBuilder.where().in(Foo.ID_FIELD_NAME, fooIdList);

	assertEquals(fooIdList.size(), fooDao.delete(stmtBuilder.prepare()));
	assertEquals(0, fooDao.queryForAll().size());
}
 
Example #16
Source File: JdbcBaseDaoImplTest.java    From ormlite-jdbc with ISC License 6 votes vote down vote up
@Test
public void testDeleteAllPreparedStmt() throws Exception {
	Dao<Foo, Integer> fooDao = createDao(Foo.class, true);
	int fooN = 100;
	for (int i = 0; i < fooN; i++) {
		Foo foo = new Foo();
		assertEquals(1, fooDao.create(foo));
	}

	DeleteBuilder<Foo, Integer> stmtBuilder = fooDao.deleteBuilder();

	int deleted = fooDao.delete(stmtBuilder.prepare());
	if (DELETE_ROWS_NO_WHERE_RETURNS_ZERO) {
		assertEquals(0, deleted);
	} else {
		assertEquals(fooN, deleted);
	}
	assertEquals(0, fooDao.queryForAll().size());
}
 
Example #17
Source File: DialogDataManager.java    From q-municate-android with Apache License 2.0 5 votes vote down vote up
public void deleteById(String dialogId) {
    try {
        DeleteBuilder<Dialog, Long> deleteBuilder = dao.deleteBuilder();
        deleteBuilder.where().eq(Dialog.Column.ID, dialogId);

        if (deleteBuilder.delete() > 0){
            //TODO VT need to think how to send ID to observers
            notifyObserversDeletedById(dialogId);
        }
    } catch (SQLException e) {
        ErrorUtils.logError(e);
    }
}
 
Example #18
Source File: FriendDataManager.java    From q-municate-android with Apache License 2.0 5 votes vote down vote up
public void deleteByUserId(int userId) {
    try {
        DeleteBuilder<Friend, Long> deleteBuilder = dao.deleteBuilder();
        deleteBuilder.where().eq(QMUserColumns.ID, userId);

        if (deleteBuilder.delete() > 0) {
            //TODO VT need to think how to send ID to observers
            notifyObserversDeletedById(userId);
        }
    } catch (SQLException e) {
        ErrorUtils.logError(e);
    }
}
 
Example #19
Source File: UserRequestDataManager.java    From q-municate-android with Apache License 2.0 5 votes vote down vote up
public void deleteByUserId(int userId) {
    try {
        DeleteBuilder<UserRequest, Long> deleteBuilder = dao.deleteBuilder();
        deleteBuilder.where().eq(QMUserColumns.ID, userId);

        if (deleteBuilder.delete() > 0) {
            //TODO VT need to think how to send ID to observers
            notifyObserversDeletedById(userId);
        }
    } catch (SQLException e) {
        ErrorUtils.logError(e);
    }

}
 
Example #20
Source File: QMUserCacheImpl.java    From q-municate-android with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteUserByExternalId(String externalId) {
    try {
        DeleteBuilder<QMUser, Long> deleteBuilder = dao.deleteBuilder();
        deleteBuilder.where().eq(EXTERNAL_ID,externalId);
        PreparedDelete<QMUser> preparedQuery = deleteBuilder.prepare();
        dao.delete(preparedQuery);
        notifyObservers(OBSERVE_KEY);
    } catch (SQLException e) {
        ErrorUtils.logError(e);
    }
}
 
Example #21
Source File: OrmLiteDao.java    From AndroidBase with Apache License 2.0 5 votes vote down vote up
/**
 * 清空表数据
 *
 * @return
 */
public boolean clearTableData() throws SQLException {
    long count = ormLiteDao.countOf();
    if (count == 0) {
        return true;
    }
    DeleteBuilder deleteBuilder = ormLiteDao.deleteBuilder();
    deleteBuilder.where().isNotNull("id");
    return deleteBuilder.delete() > 0;
}
 
Example #22
Source File: RuntimeExceptionDaoTest.java    From ormlite-core with ISC License 5 votes vote down vote up
@Test
public void testDeletes() throws Exception {
	Dao<Foo, Integer> exceptionDao = createDao(Foo.class, true);
	RuntimeExceptionDao<Foo, Integer> dao = new RuntimeExceptionDao<Foo, Integer>(exceptionDao);

	Foo foo = new Foo();
	int val = 1232131321;
	foo.val = val;
	assertEquals(1, dao.create(foo));

	assertNotNull(dao.queryForId(foo.id));
	assertEquals(1, dao.deleteById(foo.id));
	assertNull(dao.queryForId(foo.id));

	assertEquals(1, dao.create(foo));
	assertNotNull(dao.queryForId(foo.id));
	assertEquals(1, dao.delete(Arrays.asList(foo)));
	assertNull(dao.queryForId(foo.id));

	assertEquals(1, dao.create(foo));
	assertNotNull(dao.queryForId(foo.id));
	assertEquals(1, dao.deleteIds(Arrays.asList(foo.id)));
	assertNull(dao.queryForId(foo.id));

	assertEquals(1, dao.create(foo));
	assertNotNull(dao.queryForId(foo.id));
	DeleteBuilder<Foo, Integer> db = dao.deleteBuilder();
	dao.delete(db.prepare());
	assertNull(dao.queryForId(foo.id));
}
 
Example #23
Source File: DetectedOverlayFragment.java    From android-overlay-protection with Apache License 2.0 5 votes vote down vote up
private void clearHistory() {
    try {
        Dao<DetectedOverlay, Integer> detectedOverlayDao = DatabaseHelper.getHelper(getActivity()).getDetectedOverlayDao();
        DeleteBuilder<DetectedOverlay, Integer> deleteBuilder = detectedOverlayDao.deleteBuilder();
        deleteBuilder.where().gt("id", 0);
        int deleted = deleteBuilder.delete();
        Log.i(getTag(), "Deleted " + deleted + " entries from DetectedOverlay");
    } catch (SQLException e) {
        Log.e(getTag(), "Failed to deleted entries", e);
    }
    mAdapter.clear();
}
 
Example #24
Source File: QMAbstractBaseCache.java    From q-municate-android with Apache License 2.0 5 votes vote down vote up
@Override
public void clear() {
    DeleteBuilder<T, ID> deleteBuilder = dao.deleteBuilder();
    try {
        deleteBuilder.delete();
    } catch (SQLException e) {
        ErrorUtils.logError(e);
    }
}
 
Example #25
Source File: DataColumnConstraintsDao.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * Delete using the unique columns
 */
@Override
public int delete(DataColumnConstraints dataColumnConstraints)
		throws SQLException {

	DeleteBuilder<DataColumnConstraints, Void> db = deleteBuilder();

	setUniqueWhere(db.where(), dataColumnConstraints.getConstraintName(),
			dataColumnConstraints.getConstraintType(),
			dataColumnConstraints.getValue());

	int deleted = db.delete();

	return deleted;
}
 
Example #26
Source File: DataColumnsDao.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public int delete(DataColumns data) throws SQLException {
	DeleteBuilder<DataColumns, TableColumnKey> db = deleteBuilder();

	db.where().eq(DataColumns.COLUMN_TABLE_NAME, data.getTableName()).and()
			.eq(DataColumns.COLUMN_COLUMN_NAME, data.getColumnName());

	PreparedDelete<DataColumns> deleteQuery = db.prepare();
	int deleted = delete(deleteQuery);
	return deleted;
}
 
Example #27
Source File: GeometryColumnsDao.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public int delete(GeometryColumns data) throws SQLException {
	DeleteBuilder<GeometryColumns, TableColumnKey> db = deleteBuilder();

	db.where().eq(GeometryColumns.COLUMN_TABLE_NAME, data.getTableName())
			.and()
			.eq(GeometryColumns.COLUMN_COLUMN_NAME, data.getColumnName());

	PreparedDelete<GeometryColumns> deleteQuery = db.prepare();
	int deleted = delete(deleteQuery);
	return deleted;
}
 
Example #28
Source File: TableIndexDao.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Delete all table indices
 * 
 * @return rows deleted
 * @throws SQLException
 *             upon deletion failure
 * @since 1.1.5
 */
public int deleteAll() throws SQLException {

	int count = 0;

	if (isTableExists()) {
		DeleteBuilder<TableIndex, String> db = deleteBuilder();
		PreparedDelete<TableIndex> deleteQuery = db.prepare();
		count = delete(deleteQuery);
	}

	return count;
}
 
Example #29
Source File: GeometryIndexDao.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Delete all geometry indices
 * 
 * @return rows deleted
 * @throws SQLException
 *             upon deletion failure
 * @since 1.1.5
 */
public int deleteAll() throws SQLException {

	int count = 0;

	if (isTableExists()) {
		DeleteBuilder<GeometryIndex, GeometryIndexKey> db = deleteBuilder();
		PreparedDelete<GeometryIndex> deleteQuery = db.prepare();
		count = delete(deleteQuery);
	}

	return count;
}
 
Example #30
Source File: TileMatrixDao.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public int delete(TileMatrix data) throws SQLException {
	DeleteBuilder<TileMatrix, TileMatrixKey> db = deleteBuilder();

	db.where().eq(TileMatrix.COLUMN_TABLE_NAME, data.getTableName()).and()
			.eq(TileMatrix.COLUMN_ZOOM_LEVEL, data.getZoomLevel());

	PreparedDelete<TileMatrix> deleteQuery = db.prepare();
	int deleted = delete(deleteQuery);
	return deleted;
}