Java Code Examples for mil.nga.geopackage.GeoPackage#isTable()

The following examples show how to use mil.nga.geopackage.GeoPackage#isTable() . 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: SQLExecAlterTable.java    From geopackage-java with MIT License 6 votes vote down vote up
/**
 * Check for a drop table statement and execute
 * 
 * @param database
 *            database
 * @param sql
 *            SQL statement
 * @return result if dropped table, null if not
 */
private static SQLExecResult dropTable(GeoPackage database, String sql) {

	SQLExecResult result = null;

	Matcher matcher = DROP_TABLE_PATTERN.matcher(sql);
	if (matcher.matches() && SQLExec.isGeoPackage(database)) {
		String tableName = CoreSQLUtils
				.quoteUnwrap(matcher.group(TABLE_NAME_GROUP));
		if (tableName != null) {
			tableName = tableName.trim();
			if (!database.isTable(tableName)) {
				throw new GeoPackageException(
						"Table does not exist: " + tableName);
			}
			database.deleteTable(tableName.trim());
			result = new SQLExecResult();
		}
	}

	return result;
}
 
Example 2
Source File: TransactionTest.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Test an ORMLite transaction
 *
 * @param geoPackage GeoPackage
 * @param successful true for a successful transaction
 * @throws SQLException upon error
 */
private void testORMLite(final GeoPackage geoPackage,
                         final boolean successful) throws SQLException {

    final String tableName = "test_table";

    final Contents contents = new Contents();
    contents.setTableName(tableName);
    contents.setDataType(ContentsDataType.ATTRIBUTES);

    if (!geoPackage.isTable(tableName)) {
        geoPackage.execSQL("CREATE TABLE " + tableName
                + " (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)");
    }

    final SpatialReferenceSystemDao srsDao = geoPackage
            .getSpatialReferenceSystemDao();
    final ContentsDao contentsDao = geoPackage.getContentsDao();

    long srsCount = srsDao.countOf();
    long contentsCount = contentsDao.countOf();

    Callable<Void> callable = new Callable<Void>() {
        public Void call() throws Exception {

            SpatialReferenceSystem srs = srsDao.createWgs84Geographical3D();

            contents.setSrs(srs);
            contentsDao.create(contents);

            if (!successful) {
                throw new SQLException();
            }

            return null;
        }
    };

    try {
        geoPackage.callInTransaction(callable);
    } catch (SQLException e) {
        if (successful) {
            TestCase.fail(e.getMessage());
        }
    }

    TestCase.assertEquals(successful ? srsCount + 1 : srsCount,
            srsDao.countOf());
    TestCase.assertEquals(successful ? contentsCount + 1 : contentsCount,
            contentsDao.countOf());

    TestCase.assertEquals(successful,
            geoPackage.isAttributeTable(tableName));

}
 
Example 3
Source File: TransactionTest.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Test an ORMLite transaction
 * 
 * @param geoPackage
 *            GeoPackage
 * @param successful
 *            true for a successful transaction
 * @throws SQLException
 *             upon error
 */
private void testORMLite(final GeoPackage geoPackage,
		final boolean successful) throws SQLException {

	final String tableName = "test_table";

	final Contents contents = new Contents();
	contents.setTableName(tableName);
	contents.setDataType(ContentsDataType.ATTRIBUTES);

	if (!geoPackage.isTable(tableName)) {
		geoPackage.execSQL("CREATE TABLE " + tableName
				+ " (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)");
	}

	final SpatialReferenceSystemDao srsDao = geoPackage
			.getSpatialReferenceSystemDao();
	final ContentsDao contentsDao = geoPackage.getContentsDao();

	long srsCount = srsDao.countOf();
	long contentsCount = contentsDao.countOf();

	Callable<Void> callable = new Callable<Void>() {
		public Void call() throws Exception {

			SpatialReferenceSystem srs = srsDao.createWgs84Geographical3D();

			contents.setSrs(srs);
			contentsDao.create(contents);

			if (!successful) {
				throw new SQLException();
			}

			return null;
		}
	};

	try {
		geoPackage.callInTransaction(callable);
	} catch (SQLException e) {
		if (successful) {
			TestCase.fail(e.getMessage());
		}
	}

	TestCase.assertEquals(successful ? srsCount + 1 : srsCount,
			srsDao.countOf());
	TestCase.assertEquals(successful ? contentsCount + 1 : contentsCount,
			contentsDao.countOf());

	TestCase.assertEquals(successful,
			geoPackage.isAttributeTable(tableName));

}