Java Code Examples for mil.nga.geopackage.extension.ExtensionsDao#query()

The following examples show how to use mil.nga.geopackage.extension.ExtensionsDao#query() . 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: 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 2
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);

			}
		}
	}
}