Java Code Examples for mil.nga.geopackage.GeoPackage#execSQL()
The following examples show how to use
mil.nga.geopackage.GeoPackage#execSQL() .
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: TransactionTest.java From geopackage-android with MIT License | 5 votes |
/** * Test a transaction on the GeoPackage * * @param geoPackage GeoPackage * @param successful true for a successful transaction */ private void testGeoPackage(GeoPackage geoPackage, boolean successful) { int count = SQLiteMaster.countViewsOnTable(geoPackage.getConnection(), Contents.TABLE_NAME); geoPackage.beginTransaction(); try { geoPackage.execSQL("CREATE VIEW " + Contents.TABLE_NAME + "_view AS SELECT table_name AS tableName FROM " + Contents.TABLE_NAME); } catch (Exception e) { geoPackage.failTransaction(); TestCase.fail(e.getMessage()); } finally { if (successful) { geoPackage.endTransaction(); } else { geoPackage.failTransaction(); } } TestCase.assertEquals(successful ? count + 1 : count, SQLiteMaster .countViewsOnTable(geoPackage.getConnection(), Contents.TABLE_NAME)); }
Example 2
Source File: TransactionTest.java From geopackage-java with MIT License | 5 votes |
/** * Test a transaction on the GeoPackage * * @param geoPackage * GeoPackage * @param successful * true for a successful transaction * @throws SQLException * upon error */ private void testGeoPackage(GeoPackage geoPackage, boolean successful) throws SQLException { int count = SQLiteMaster.countViewsOnTable(geoPackage.getConnection(), Contents.TABLE_NAME); geoPackage.beginTransaction(); try { geoPackage.execSQL("CREATE VIEW " + Contents.TABLE_NAME + "_view AS SELECT table_name AS tableName FROM " + Contents.TABLE_NAME); } catch (Exception e) { geoPackage.failTransaction(); TestCase.fail(e.getMessage()); } finally { if (successful) { geoPackage.endTransaction(); } else { geoPackage.failTransaction(); } } TestCase.assertEquals(successful ? count + 1 : count, SQLiteMaster .countViewsOnTable(geoPackage.getConnection(), Contents.TABLE_NAME)); }
Example 3
Source File: TransactionTest.java From geopackage-android with MIT License | 4 votes |
/** * 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 4
Source File: TransactionTest.java From geopackage-java with MIT License | 4 votes |
/** * 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)); }