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

The following examples show how to use com.j256.ormlite.stmt.PreparedDelete. 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: 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 2
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 3
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 4
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 5
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 6
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 7
Source Project: AndroidStarter   Source File: RxBaseDaoImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Observable<Integer> rxDelete(final PreparedDelete<DataType> preparedDelete) {
    final Func0<Observable<Integer>> loFunc = () -> {
        try {
            return Observable.just(delete(preparedDelete));
        } catch (SQLException e) {
            return Observable.error(e);
        }
    };
    return Observable.defer(loFunc);
}
 
Example 8
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 9
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 10
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 11
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 12
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 13
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 14
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 15
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;
}
 
Example 16
Source Project: geopackage-core-java   Source File: TileMatrixDao.java    License: 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;
}
 
Example 17
Source Project: q-municate-android   Source File: QMUserCacheImpl.java    License: 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 18
Source Project: ormlite-core   Source File: BaseDaoImpl.java    License: ISC License 5 votes vote down vote up
@Override
public int delete(PreparedDelete<T> preparedDelete) throws SQLException {
	checkForInitialized();
	DatabaseConnection connection = connectionSource.getReadWriteConnection(tableInfo.getTableName());
	try {
		return statementExecutor.delete(connection, preparedDelete);
	} finally {
		connectionSource.releaseConnection(connection);
	}
}
 
Example 19
Source Project: ormlite-core   Source File: RuntimeExceptionDao.java    License: ISC License 5 votes vote down vote up
/**
 * @see Dao#delete(PreparedDelete)
 */
@Override
public int delete(PreparedDelete<T> preparedDelete) {
	try {
		return dao.delete(preparedDelete);
	} catch (SQLException e) {
		logMessage(e, "delete threw exception on: " + preparedDelete);
		throw new RuntimeException(e);
	}
}
 
Example 20
Source Project: ormlite-core   Source File: RuntimeExceptionDaoTest.java    License: ISC License 5 votes vote down vote up
@Test(expected = RuntimeException.class)
public void testDeletePreparedThrow() 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.delete((PreparedDelete<Foo>) null)).andThrow(new SQLException("Testing catch"));
	replay(dao);
	rtDao.delete((PreparedDelete<Foo>) null);
	verify(dao);
}
 
Example 21
Source Project: geopackage-android   Source File: ExtensionsUtils.java    License: MIT License 4 votes vote down vote up
/**
 * Test delete
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testDelete(GeoPackage geoPackage) throws SQLException {

	ExtensionsDao dao = geoPackage.getExtensionsDao();

	if (dao.isTableExists()) {
		List<Extensions> results = dao.queryForAll();

		if (!results.isEmpty()) {

			// Choose random metadata
			int random = (int) (Math.random() * results.size());
			Extensions extensions = results.get(random);

			// Delete the extensions
			dao.delete(extensions);

			// Verify deleted
			Extensions queryExtensions = dao.queryByExtension(
					extensions.getExtensionName(),
					extensions.getTableName(), extensions.getColumnName());
			TestCase.assertNull(queryExtensions);

			// Choose prepared deleted
			results = dao.queryForAll();
			if (!results.isEmpty()) {

				// Choose random metadata
				random = (int) (Math.random() * results.size());
				extensions = results.get(random);

				// Find which metadata to delete
				QueryBuilder<Extensions, Void> qb = dao.queryBuilder();
				qb.where().eq(Extensions.COLUMN_EXTENSION_NAME,
						extensions.getExtensionName());
				PreparedQuery<Extensions> query = qb.prepare();
				List<Extensions> queryResults = dao.query(query);
				int count = queryResults.size();

				// Delete
				DeleteBuilder<Extensions, Void> db = dao.deleteBuilder();
				db.where().eq(Extensions.COLUMN_EXTENSION_NAME,
						extensions.getExtensionName());
				PreparedDelete<Extensions> deleteQuery = db.prepare();
				int deleted = dao.delete(deleteQuery);

				TestCase.assertEquals(count, deleted);

			}
		}
	}
}
 
Example 22
Source Project: geopackage-android   Source File: GeometryColumnsUtils.java    License: MIT License 4 votes vote down vote up
/**
 * Test delete
 *
 * @param geoPackage
 * @throws SQLException
 */
public static void testDelete(GeoPackage geoPackage) throws SQLException {

    GeometryColumnsDao dao = geoPackage.getGeometryColumnsDao();

    if (dao.isTableExists()) {
        List<GeometryColumns> results = dao.queryForAll();

        if (!results.isEmpty()) {

            // Choose random geometry columns
            int random = (int) (Math.random() * results.size());
            GeometryColumns geometryColumns = results.get(random);

            // Delete the geometry columns
            dao.delete(geometryColumns);

            // Verify deleted
            GeometryColumns queryGeometryColumns = dao
                    .queryForId(geometryColumns.getId());
            TestCase.assertNull(queryGeometryColumns);

            // Prepared deleted
            results = dao.queryForAll();
            if (!results.isEmpty()) {

                // Choose random geometry columns
                random = (int) (Math.random() * results.size());
                geometryColumns = results.get(random);

                // Find which geometry columns to delete
                QueryBuilder<GeometryColumns, TableColumnKey> qb = dao
                        .queryBuilder();
                qb.where().eq(GeometryColumns.COLUMN_GEOMETRY_TYPE_NAME,
                        geometryColumns.getGeometryType().getName());
                PreparedQuery<GeometryColumns> query = qb.prepare();
                List<GeometryColumns> queryResults = dao.query(query);
                int count = queryResults.size();

                // Delete
                DeleteBuilder<GeometryColumns, TableColumnKey> db = dao
                        .deleteBuilder();
                db.where().eq(GeometryColumns.COLUMN_GEOMETRY_TYPE_NAME,
                        geometryColumns.getGeometryType().getName());
                PreparedDelete<GeometryColumns> deleteQuery = db.prepare();
                int deleted = dao.delete(deleteQuery);

                TestCase.assertEquals(count, deleted);

            }
        }
    }
}
 
Example 23
Source Project: geopackage-android   Source File: MetadataReferenceUtils.java    License: MIT License 4 votes vote down vote up
/**
 * Test delete
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testDelete(GeoPackage geoPackage) throws SQLException {

	MetadataReferenceDao dao = geoPackage.getMetadataReferenceDao();

	if (dao.isTableExists()) {
		List<MetadataReference> results = dao.queryForAll();

		if (!results.isEmpty()) {

			// Choose random metadata
			int random = (int) (Math.random() * results.size());
			MetadataReference metadataReference = results.get(random);

			// Delete the metadata reference
			dao.delete(metadataReference);

			// Verify deleted
			List<MetadataReference> queryMetadataReferenceList = dao
					.queryByMetadata(metadataReference.getFileId(),
							metadataReference.getParentId());
			TestCase.assertTrue(queryMetadataReferenceList.isEmpty());

			// Choose prepared deleted
			results = dao.queryForAll();
			if (!results.isEmpty()) {

				// Choose random metadata
				random = (int) (Math.random() * results.size());
				metadataReference = results.get(random);

				// Find which metadata to delete
				QueryBuilder<MetadataReference, Void> qb = dao
						.queryBuilder();
				qb.where().eq(MetadataReference.COLUMN_FILE_ID,
						metadataReference.getFileId());
				PreparedQuery<MetadataReference> query = qb.prepare();
				List<MetadataReference> queryResults = dao.query(query);
				int count = queryResults.size();

				// Delete
				DeleteBuilder<MetadataReference, Void> db = dao
						.deleteBuilder();
				db.where().eq(MetadataReference.COLUMN_FILE_ID,
						metadataReference.getFileId());
				PreparedDelete<MetadataReference> deleteQuery = db
						.prepare();
				int deleted = dao.delete(deleteQuery);

				TestCase.assertEquals(count, deleted);

			}
		}
	}
}
 
Example 24
Source Project: geopackage-android   Source File: DataColumnsUtils.java    License: MIT License 4 votes vote down vote up
/**
 * Test delete
 *
 * @param geoPackage
 * @throws SQLException
 */
public static void testDelete(GeoPackage geoPackage) throws SQLException {

	DataColumnsDao dao = geoPackage.getDataColumnsDao();
	if (dao.isTableExists()) {
		List<DataColumns> results = dao.queryForAll();

		if (!results.isEmpty()) {

			// Choose random data columns
			int random = (int) (Math.random() * results.size());
			DataColumns dataColumns = results.get(random);

			// Delete the data columns
			dao.delete(dataColumns);

			// Verify deleted
			DataColumns queryDataColumns = dao.queryForId(dataColumns
					.getId());
			TestCase.assertNull(queryDataColumns);

			// Prepared deleted
			results = dao.queryForAll();
			if (!results.isEmpty()) {

				// Choose random data columns
				random = (int) (Math.random() * results.size());
				dataColumns = results.get(random);

				// Find which data columns to delete
				QueryBuilder<DataColumns, TableColumnKey> qb = dao
						.queryBuilder();
				qb.where().eq(DataColumns.COLUMN_TABLE_NAME,
						dataColumns.getTableName());
				PreparedQuery<DataColumns> query = qb.prepare();
				List<DataColumns> queryResults = dao.query(query);
				int count = queryResults.size();

				// Delete
				DeleteBuilder<DataColumns, TableColumnKey> db = dao
						.deleteBuilder();
				db.where().eq(DataColumns.COLUMN_TABLE_NAME,
						dataColumns.getTableName());
				PreparedDelete<DataColumns> deleteQuery = db.prepare();
				int deleted = dao.delete(deleteQuery);

				TestCase.assertEquals(count, deleted);

			}
		}
	}
}
 
Example 25
Source Project: geopackage-android   Source File: DataColumnConstraintsUtils.java    License: MIT License 4 votes vote down vote up
/**
 * Test delete
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testDelete(GeoPackage geoPackage) throws SQLException {

	DataColumnConstraintsDao dao = geoPackage.getDataColumnConstraintsDao();
	DataColumnsDao dataColumnsDao = geoPackage.getDataColumnsDao();
	if (dao.isTableExists()) {
		List<DataColumnConstraints> results = dao.queryForAll();

		if (!results.isEmpty()) {

			// Choose random data column constraints
			int random = (int) (Math.random() * results.size());
			DataColumnConstraints dataColumnConstraints = results
					.get(random);

			int remainingConstraints = dao.queryByConstraintName(
					dataColumnConstraints.getConstraintName()).size();
			int dataColumns = dataColumnsDao.queryByConstraintName(
					dataColumnConstraints.getConstraintName()).size();

			// Delete the data column constraints
			dao.deleteCascade(dataColumnConstraints);

			// Verify deleted
			DataColumnConstraints queryDataColumns = dao.queryByUnique(
					dataColumnConstraints.getConstraintName(),
					dataColumnConstraints.getConstraintType(),
					dataColumnConstraints.getValue());
			TestCase.assertNull(queryDataColumns);

			// Verify cascade delete
			int afterRemainingConstraints = dao.queryByConstraintName(
					dataColumnConstraints.getConstraintName()).size();
			int afterDataColumns = dataColumnsDao.queryByConstraintName(
					dataColumnConstraints.getConstraintName()).size();

			TestCase.assertEquals(remainingConstraints - 1,
					afterRemainingConstraints);
			if (remainingConstraints == 1) {
				TestCase.assertEquals(0, afterDataColumns);
			} else {
				TestCase.assertEquals(dataColumns, afterDataColumns);
			}

			// Prepared deleted
			results = dao.queryForAll();
			if (!results.isEmpty()) {

				// Choose random data column constraints
				random = (int) (Math.random() * results.size());
				dataColumnConstraints = results.get(random);

				// Find which data column constraints to delete
				QueryBuilder<DataColumnConstraints, Void> qb = dao
						.queryBuilder();
				qb.where().eq(DataColumnConstraints.COLUMN_CONSTRAINT_NAME,
						dataColumnConstraints.getConstraintName());
				PreparedQuery<DataColumnConstraints> query = qb.prepare();
				List<DataColumnConstraints> queryResults = dao.query(query);
				int count = queryResults.size();

				// Delete
				DeleteBuilder<DataColumnConstraints, Void> db = dao
						.deleteBuilder();
				db.where().eq(DataColumnConstraints.COLUMN_CONSTRAINT_NAME,
						dataColumnConstraints.getConstraintName());
				PreparedDelete<DataColumnConstraints> deleteQuery = db
						.prepare();
				int deleted = dao.delete(deleteQuery);

				TestCase.assertEquals(count, deleted);

			}
		}
	}
}
 
Example 26
Source Project: geopackage-android   Source File: TileMatrixUtils.java    License: MIT License 4 votes vote down vote up
/**
 * Test delete
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testDelete(GeoPackage geoPackage) throws SQLException {

	TileMatrixDao dao = geoPackage.getTileMatrixDao();
	if (dao.isTableExists()) {
		List<TileMatrix> results = dao.queryForAll();

		if (!results.isEmpty()) {

			// Choose random tile matrix
			int random = (int) (Math.random() * results.size());
			TileMatrix tileMatrix = results.get(random);

			// Delete the tile matrix
			dao.delete(tileMatrix);

			// Verify deleted
			TileMatrix queryTileMatrix = dao.queryForId(tileMatrix.getId());
			TestCase.assertNull(queryTileMatrix);

			// Prepared deleted
			results = dao.queryForAll();
			if (!results.isEmpty()) {

				// Choose random tile matrix
				random = (int) (Math.random() * results.size());
				tileMatrix = results.get(random);

				// Find which tile matrix to delete
				QueryBuilder<TileMatrix, TileMatrixKey> qb = dao
						.queryBuilder();
				qb.where().eq(TileMatrix.COLUMN_ZOOM_LEVEL,
						tileMatrix.getZoomLevel());
				PreparedQuery<TileMatrix> query = qb.prepare();
				List<TileMatrix> queryResults = dao.query(query);
				int count = queryResults.size();

				// Delete
				DeleteBuilder<TileMatrix, TileMatrixKey> db = dao
						.deleteBuilder();
				db.where().eq(TileMatrix.COLUMN_ZOOM_LEVEL,
						tileMatrix.getZoomLevel());
				PreparedDelete<TileMatrix> deleteQuery = db.prepare();
				int deleted = dao.delete(deleteQuery);

				TestCase.assertEquals(count, deleted);

			}
		}
	}
}
 
Example 27
Source Project: geopackage-android   Source File: TileMatrixSetUtils.java    License: MIT License 4 votes vote down vote up
/**
 * Test delete
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testDelete(GeoPackage geoPackage) throws SQLException {

	TileMatrixSetDao dao = geoPackage.getTileMatrixSetDao();
	if (dao.isTableExists()) {
		List<TileMatrixSet> results = dao.queryForAll();

		if (!results.isEmpty()) {

			// Choose random tile matrix set
			int random = (int) (Math.random() * results.size());
			TileMatrixSet tileMatrixSet = results.get(random);

			// Delete the tile matrix set
			geoPackage.foreignKeys(false);
			dao.delete(tileMatrixSet);

			// Verify deleted
			TileMatrixSet queryTileMatrixSet = dao.queryForId(tileMatrixSet
					.getId());
			TestCase.assertNull(queryTileMatrixSet);

			// Prepared deleted
			results = dao.queryForAll();
			if (!results.isEmpty()) {

				// Choose random tile matrix set
				random = (int) (Math.random() * results.size());
				tileMatrixSet = results.get(random);

				// Find which tile matrix set to delete
				QueryBuilder<TileMatrixSet, String> qb = dao.queryBuilder();
				qb.where().eq(TileMatrixSet.COLUMN_SRS_ID,
						tileMatrixSet.getSrsId());
				PreparedQuery<TileMatrixSet> query = qb.prepare();
				List<TileMatrixSet> queryResults = dao.query(query);
				int count = queryResults.size();

				// Delete
				DeleteBuilder<TileMatrixSet, String> db = dao
						.deleteBuilder();
				db.where().eq(TileMatrixSet.COLUMN_SRS_ID,
						tileMatrixSet.getSrsId());
				PreparedDelete<TileMatrixSet> deleteQuery = db.prepare();
				int deleted = dao.delete(deleteQuery);

				TestCase.assertEquals(count, deleted);

			}
		}
	}
}
 
Example 28
Source Project: geopackage-java   Source File: ExtensionsUtils.java    License: MIT License 4 votes vote down vote up
/**
 * Test delete
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testDelete(GeoPackage geoPackage) throws SQLException {

	ExtensionsDao dao = geoPackage.getExtensionsDao();

	if (dao.isTableExists()) {
		List<Extensions> results = dao.queryForAll();

		if (!results.isEmpty()) {

			// Choose random metadata
			int random = (int) (Math.random() * results.size());
			Extensions extensions = results.get(random);

			// Delete the extensions
			dao.delete(extensions);

			// Verify deleted
			Extensions queryExtensions = dao.queryByExtension(
					extensions.getExtensionName(),
					extensions.getTableName(), extensions.getColumnName());
			TestCase.assertNull(queryExtensions);

			// Choose prepared deleted
			results = dao.queryForAll();
			if (!results.isEmpty()) {

				// Choose random metadata
				random = (int) (Math.random() * results.size());
				extensions = results.get(random);

				// Find which metadata to delete
				QueryBuilder<Extensions, Void> qb = dao.queryBuilder();
				qb.where().eq(Extensions.COLUMN_EXTENSION_NAME,
						extensions.getExtensionName());
				PreparedQuery<Extensions> query = qb.prepare();
				List<Extensions> queryResults = dao.query(query);
				int count = queryResults.size();

				// Delete
				DeleteBuilder<Extensions, Void> db = dao.deleteBuilder();
				db.where().eq(Extensions.COLUMN_EXTENSION_NAME,
						extensions.getExtensionName());
				PreparedDelete<Extensions> deleteQuery = db.prepare();
				int deleted = dao.delete(deleteQuery);

				TestCase.assertEquals(count, deleted);

			}
		}
	}
}
 
Example 29
Source Project: geopackage-java   Source File: GeometryColumnsUtils.java    License: MIT License 4 votes vote down vote up
/**
 * Test delete
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testDelete(GeoPackage geoPackage) throws SQLException {

	GeometryColumnsDao dao = geoPackage.getGeometryColumnsDao();

	if (dao.isTableExists()) {
		List<GeometryColumns> results = dao.queryForAll();

		if (!results.isEmpty()) {

			// Choose random geometry columns
			int random = (int) (Math.random() * results.size());
			GeometryColumns geometryColumns = results.get(random);

			// Delete the geometry columns
			dao.delete(geometryColumns);

			// Verify deleted
			GeometryColumns queryGeometryColumns = dao
					.queryForId(geometryColumns.getId());
			TestCase.assertNull(queryGeometryColumns);

			// Prepared deleted
			results = dao.queryForAll();
			if (!results.isEmpty()) {

				// Choose random geometry columns
				random = (int) (Math.random() * results.size());
				geometryColumns = results.get(random);

				// Find which geometry columns to delete
				QueryBuilder<GeometryColumns, TableColumnKey> qb = dao
						.queryBuilder();
				qb.where().eq(GeometryColumns.COLUMN_GEOMETRY_TYPE_NAME,
						geometryColumns.getGeometryType().getName());
				PreparedQuery<GeometryColumns> query = qb.prepare();
				List<GeometryColumns> queryResults = dao.query(query);
				int count = queryResults.size();

				// Delete
				DeleteBuilder<GeometryColumns, TableColumnKey> db = dao
						.deleteBuilder();
				db.where().eq(GeometryColumns.COLUMN_GEOMETRY_TYPE_NAME,
						geometryColumns.getGeometryType().getName());
				PreparedDelete<GeometryColumns> deleteQuery = db.prepare();
				int deleted = dao.delete(deleteQuery);

				TestCase.assertEquals(count, deleted);

			}
		}
	}
}
 
Example 30
Source Project: geopackage-java   Source File: MetadataReferenceUtils.java    License: MIT License 4 votes vote down vote up
/**
 * Test delete
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testDelete(GeoPackage geoPackage) throws SQLException {

	MetadataReferenceDao dao = geoPackage.getMetadataReferenceDao();

	if (dao.isTableExists()) {
		List<MetadataReference> results = dao.queryForAll();

		if (!results.isEmpty()) {

			// Choose random metadata
			int random = (int) (Math.random() * results.size());
			MetadataReference metadataReference = results.get(random);

			// Delete the metadata reference
			dao.delete(metadataReference);

			// Verify deleted
			List<MetadataReference> queryMetadataReferenceList = dao
					.queryByMetadata(metadataReference.getFileId(),
							metadataReference.getParentId());
			TestCase.assertTrue(queryMetadataReferenceList.isEmpty());

			// Choose prepared deleted
			results = dao.queryForAll();
			if (!results.isEmpty()) {

				// Choose random metadata
				random = (int) (Math.random() * results.size());
				metadataReference = results.get(random);

				// Find which metadata to delete
				QueryBuilder<MetadataReference, Void> qb = dao
						.queryBuilder();
				qb.where().eq(MetadataReference.COLUMN_FILE_ID,
						metadataReference.getFileId());
				PreparedQuery<MetadataReference> query = qb.prepare();
				List<MetadataReference> queryResults = dao.query(query);
				int count = queryResults.size();

				// Delete
				DeleteBuilder<MetadataReference, Void> db = dao
						.deleteBuilder();
				db.where().eq(MetadataReference.COLUMN_FILE_ID,
						metadataReference.getFileId());
				PreparedDelete<MetadataReference> deleteQuery = db
						.prepare();
				int deleted = dao.delete(deleteQuery);

				TestCase.assertEquals(count, deleted);

			}
		}
	}
}