Java Code Examples for com.j256.ormlite.stmt.DeleteBuilder#prepare()
The following examples show how to use
com.j256.ormlite.stmt.DeleteBuilder#prepare() .
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 |
/** * {@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: GriddedTileDao.java From geopackage-core-java with MIT License | 6 votes |
/** * 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 3
Source File: GriddedCoverageDao.java From geopackage-core-java with MIT License | 6 votes |
/** * 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 4
Source File: FeatureTableCoreIndex.java From geopackage-core-java with MIT License | 6 votes |
/** * 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 5
Source File: FeatureTileLinkDao.java From geopackage-core-java with MIT License | 6 votes |
/** * {@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 6
Source File: TableIndexDao.java From geopackage-core-java with MIT License | 6 votes |
/** * 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: GeometryColumnsSqlMmDao.java From geopackage-core-java with MIT License | 5 votes |
/** * {@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 8
Source File: TileMatrixDao.java From geopackage-core-java with MIT License | 5 votes |
/** * {@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 9
Source File: TableIndexDao.java From geopackage-core-java with MIT License | 5 votes |
/** * 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 10
Source File: GeometryIndexDao.java From geopackage-core-java with MIT License | 5 votes |
/** * 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 11
Source File: GeometryIndexDao.java From geopackage-core-java with MIT License | 5 votes |
/** * {@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 12
Source File: TileMatrixUtils.java From geopackage-java with MIT License | 4 votes |
/** * 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 13
Source File: DataColumnConstraintsUtils.java From geopackage-java with MIT License | 4 votes |
/** * 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 14
Source File: GeometryColumnsUtils.java From geopackage-java with MIT License | 4 votes |
/** * 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 15
Source File: TileMatrixSetUtils.java From geopackage-android with MIT License | 4 votes |
/** * 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 16
Source File: TileMatrixUtils.java From geopackage-android with MIT License | 4 votes |
/** * 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 17
Source File: DataColumnConstraintsUtils.java From geopackage-android with MIT License | 4 votes |
/** * 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 18
Source File: MetadataReferenceUtils.java From geopackage-android with MIT License | 4 votes |
/** * 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 19
Source File: TileMatrixSetUtils.java From geopackage-java with MIT License | 4 votes |
/** * 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 20
Source File: DataColumnsDao.java From geopackage-core-java with MIT License | 3 votes |
/** * Delete by table name * * @param tableName * table name * @return rows deleted * @throws SQLException * upon failure * @since 3.2.0 */ public int deleteByTableName(String tableName) throws SQLException { DeleteBuilder<DataColumns, TableColumnKey> db = deleteBuilder(); db.where().eq(DataColumns.COLUMN_TABLE_NAME, tableName); PreparedDelete<DataColumns> deleteQuery = db.prepare(); int deleted = delete(deleteQuery); return deleted; }