Java Code Examples for com.j256.ormlite.stmt.DeleteBuilder

The following examples show how to use com.j256.ormlite.stmt.DeleteBuilder. These examples are extracted from open source projects. 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 Project: android-overlay-protection   Source File: DatabaseHelper.java    License: 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 2
Source Project: android-project-wo2b   Source File: LocalAlbumBiz.java    License: 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 Project: android-project-wo2b   Source File: MyFavoritesBiz.java    License: 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 Project: android-project-wo2b   Source File: PhotoBiz.java    License: 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 Project: android-project-wo2b   Source File: AlbumBiz.java    License: 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 Project: ETSMobile-Android2   Source File: NoteManager.java    License: 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 7
Source Project: geopackage-core-java   Source File: FeatureTileLinkDao.java    License: 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 8
Source Project: geopackage-core-java   Source File: TableIndexDao.java    License: 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 9
Source Project: geopackage-core-java   Source File: FeatureTableCoreIndex.java    License: 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 10
Source Project: geopackage-core-java   Source File: GriddedCoverageDao.java    License: 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 11
Source Project: geopackage-core-java   Source File: GriddedTileDao.java    License: 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 12
Source Project: geopackage-core-java   Source File: GeometryColumnsSfSqlDao.java    License: 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 13
Source Project: q-municate-android   Source File: MessageDataManager.java    License: 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 14
Source Project: ormlite-jdbc   Source File: JdbcBaseDaoImplTest.java    License: 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 15
Source Project: ormlite-jdbc   Source File: JdbcBaseDaoImplTest.java    License: 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 16
Source Project: ormlite-core   Source File: BaseDaoImplTest.java    License: 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 17
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 18
Source Project: AndroidBase   Source File: OrmLiteDao.java    License: 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 19
Source Project: AndroidBase   Source File: OrmLiteDao.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 通过表列名来删除
 *
 * @param map key是列名,value是列对应的值
 * @return
 */
public boolean deleteByColumnName(Map<String, Object> map) throws SQLException {
    DeleteBuilder deleteBuilder = ormLiteDao.deleteBuilder();
    Where where = deleteBuilder.where();
    where.isNotNull("id");
    for (Map.Entry<String, Object> entry : map.entrySet()) {
        where.and().eq(entry.getKey(), entry.getValue());
    }
    return deleteBuilder.delete() > 0;
}
 
Example 20
Source Project: android-project-wo2b   Source File: RockyDao.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 删除所有数据
 * 
 * @return
 */
public int deleteAll()
{
	DeleteBuilder<Model, ?> deleteBuilder = mRuntimeDao.deleteBuilder();
	try
	{
		return deleteBuilder.delete();
	}
	catch (SQLException e)
	{
		e.printStackTrace();
	}

	return -1;
}
 
Example 21
@Override
protected MitroRPC processCommand(MitroRequestContext context) throws IOException, SQLException, MitroServletException {
  RPC.RemoveAllPendingGroupApprovalsForScopeRequest in = gson.fromJson(context.jsonRequest, RPC.RemoveAllPendingGroupApprovalsForScopeRequest.class);
  
  // TODO: verify auth
  
  DeleteBuilder<DBPendingGroup, Integer> deleter = context.manager.pendingGroupDao.deleteBuilder();
  deleter.where().eq(DBPendingGroup.SCOPE_NAME, new SelectArg(in.scope));
  deleter.delete();
  
  context.manager.addAuditLog(DBAudit.ACTION.REMOVE_PENDING_GROUP_SYNC, context.requestor, null, /*group*/null, null, in.scope);
  return new MitroRPC();
}
 
Example 22
@Test
public void emptyOrgMemberRemove() throws SQLException, MitroServletException, IOException, CyclicGroupError {
  // remove all secrets from the organization
  DeleteBuilder<DBGroupSecret, Integer> deleteBuilder = manager.groupSecretDao.deleteBuilder();
  deleteBuilder.where().in(DBGroupSecret.SVS_ID_NAME, orgSecret.getId(), orphanedOrgSecret.getId());
  assertEquals(4, deleteBuilder.delete());

  // remove member from an "empty" organization
  // had a bug where we attempted an IN query on an empty list
  rqst.membersToRemove = new ArrayList<>();
  rqst.membersToRemove.add(members.iterator().next().getName());
  getMutateResponse(testIdentity);
}
 
Example 23
Source Project: geopackage-core-java   Source File: FeatureTileLinkDao.java    License: MIT License 5 votes vote down vote up
/**
 * Delete by table name, either feature or tile table name
 * 
 * @param tableName
 *            table name, feature or tile
 * @return rows deleted
 * @throws SQLException
 *             upon failure
 */
public int deleteByTableName(String tableName) throws SQLException {
	DeleteBuilder<FeatureTileLink, FeatureTileLinkKey> db = deleteBuilder();

	db.where().eq(FeatureTileLink.COLUMN_FEATURE_TABLE_NAME, tableName)
			.or().eq(FeatureTileLink.COLUMN_TILE_TABLE_NAME, tableName);

	PreparedDelete<FeatureTileLink> deleteQuery = db.prepare();
	int deleted = delete(deleteQuery);
	return deleted;
}
 
Example 24
Source Project: geopackage-core-java   Source File: FeatureTileLinkDao.java    License: MIT License 5 votes vote down vote up
/**
 * Delete all feature tile links
 * 
 * @return rows deleted
 * @throws SQLException
 *             upon failure
 * @since 1.1.5
 */
public int deleteAll() throws SQLException {

	int count = 0;

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

	return count;
}
 
Example 25
Source Project: geopackage-core-java   Source File: GeometryIndexDao.java    License: MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public int delete(GeometryIndex data) throws SQLException {
	DeleteBuilder<GeometryIndex, GeometryIndexKey> db = deleteBuilder();

	db.where().eq(GeometryIndex.COLUMN_TABLE_NAME, data.getTableName())
			.and().eq(GeometryIndex.COLUMN_GEOM_ID, data.getGeomId());

	PreparedDelete<GeometryIndex> deleteQuery = db.prepare();
	int deleted = delete(deleteQuery);
	return deleted;
}
 
Example 26
Source Project: geopackage-core-java   Source File: GeometryIndexDao.java    License: 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 27
Source Project: geopackage-core-java   Source File: TableIndexDao.java    License: 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 28
Source Project: geopackage-core-java   Source File: GeometryColumnsDao.java    License: 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 29
Source Project: geopackage-core-java   Source File: GeometryColumnsSqlMmDao.java    License: MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public int delete(GeometryColumnsSqlMm data) throws SQLException {
	DeleteBuilder<GeometryColumnsSqlMm, TableColumnKey> db = deleteBuilder();

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

	PreparedDelete<GeometryColumnsSqlMm> deleteQuery = db.prepare();
	int deleted = delete(deleteQuery);
	return deleted;
}
 
Example 30
Source Project: geopackage-core-java   Source File: DataColumnsDao.java    License: 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;
}