com.j256.ormlite.stmt.PreparedDelete Java Examples

The following examples show how to use com.j256.ormlite.stmt.PreparedDelete. 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: 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 #2
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 #3
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 #4
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 #5
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 #6
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 #7
Source File: RuntimeExceptionDaoTest.java    From ormlite-core with 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 #8
Source File: RxBaseDaoImpl.java    From AndroidStarter with 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 #9
Source File: RuntimeExceptionDao.java    From ormlite-core with 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 #10
Source File: BaseDaoImpl.java    From ormlite-core with 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 #11
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 #12
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;
}
 
Example #13
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 #14
Source File: GeometryColumnsSqlMmDao.java    From geopackage-core-java with 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 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 #16
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 #17
Source File: GeometryIndexDao.java    From geopackage-core-java with 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 #18
Source File: FeatureTileLinkDao.java    From geopackage-core-java with 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 #19
Source File: FeatureTileLinkDao.java    From geopackage-core-java with 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 #20
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 #21
Source File: ExtensionsUtils.java    From geopackage-java with 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 File: ExtensionsUtils.java    From geopackage-android with 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 #23
Source File: GeometryColumnsUtils.java    From geopackage-android with 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 #24
Source File: MetadataReferenceUtils.java    From geopackage-android with 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 #25
Source File: TileMatrixSetUtils.java    From geopackage-java with 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 #26
Source File: TileMatrixUtils.java    From geopackage-java with 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 File: DataColumnConstraintsUtils.java    From geopackage-java with 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 #28
Source File: DataColumnsUtils.java    From geopackage-java with 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 #29
Source File: MetadataReferenceUtils.java    From geopackage-java with 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 #30
Source File: GeometryColumnsUtils.java    From geopackage-java with 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);

			}
		}
	}
}