mil.nga.geopackage.attributes.AttributesDao Java Examples
The following examples show how to use
mil.nga.geopackage.attributes.AttributesDao.
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: GeoPackageImpl.java From geopackage-android with MIT License | 6 votes |
/** * {@inheritDoc} */ @Override public AttributesDao getAttributesDao(String tableName) { ContentsDao dao = getContentsDao(); Contents contents = null; try { contents = dao.queryForId(tableName); } catch (SQLException e) { throw new GeoPackageException("Failed to retrieve " + Contents.class.getSimpleName() + " for table name: " + tableName, e); } if (contents == null) { throw new GeoPackageException( "No Contents Table exists for table name: " + tableName); } return getAttributesDao(contents); }
Example #2
Source File: GeoPackageImpl.java From geopackage-java with MIT License | 6 votes |
/** * {@inheritDoc} */ @Override public AttributesDao getAttributesDao(String tableName) { ContentsDao dao = getContentsDao(); Contents contents = null; try { contents = dao.queryForId(tableName); } catch (SQLException e) { throw new GeoPackageException( "Failed to retrieve " + Contents.class.getSimpleName() + " for table name: " + tableName, e); } if (contents == null) { throw new GeoPackageException( "No Contents Table exists for table name: " + tableName); } return getAttributesDao(contents); }
Example #3
Source File: GeoPackageImpl.java From geopackage-java with MIT License | 6 votes |
/** * {@inheritDoc} */ @Override public AttributesDao getAttributesDao(Contents contents) { if (contents == null) { throw new GeoPackageException("Non null " + Contents.class.getSimpleName() + " is required to create " + AttributesDao.class.getSimpleName()); } if (contents.getDataType() != ContentsDataType.ATTRIBUTES) { throw new GeoPackageException(Contents.class.getSimpleName() + " is required to be of type " + ContentsDataType.ATTRIBUTES + ". Actual: " + contents.getDataTypeString()); } // Read the existing table and create the dao AttributesTableReader tableReader = new AttributesTableReader( contents.getTableName()); final AttributesTable attributesTable = tableReader.readTable(database); attributesTable.setContents(contents); AttributesDao dao = new AttributesDao(getName(), database, attributesTable); return dao; }
Example #4
Source File: FeatureStyleExtension.java From geopackage-android with MIT License | 5 votes |
/** * Get a style DAO * * @return style DAO */ public StyleDao getStyleDao() { StyleDao styleDao = null; if (geoPackage.isTable(StyleTable.TABLE_NAME)) { AttributesDao attributesDao = getGeoPackage().getAttributesDao( StyleTable.TABLE_NAME); styleDao = new StyleDao(attributesDao); relatedTables.setContents(styleDao.getTable()); } return styleDao; }
Example #5
Source File: AttributesUtils.java From geopackage-java with MIT License | 5 votes |
/** * Test delete * * @param geoPackage * GeoPackage * @throws SQLException * upon error */ public static void testDelete(GeoPackage geoPackage) throws SQLException { List<String> tables = geoPackage.getAttributesTables(); if (!tables.isEmpty()) { for (String tableName : tables) { AttributesDao dao = geoPackage.getAttributesDao(tableName); TestCase.assertNotNull(dao); AttributesResultSet cursor = dao.queryForAll(); int count = cursor.getCount(); if (count > 0) { // Choose random attribute int random = (int) (Math.random() * count); cursor.moveToPosition(random); AttributesRow attributesRow = cursor.getRow(); cursor.close(); // Delete row TestCase.assertEquals(1, dao.delete(attributesRow)); // Verify deleted AttributesRow queryAttributesRow = dao .queryForIdRow(attributesRow.getId()); TestCase.assertNull(queryAttributesRow); cursor = dao.queryForAll(); TestCase.assertEquals(count - 1, cursor.getCount()); cursor.close(); } cursor.close(); } } }
Example #6
Source File: GeoPackageImpl.java From geopackage-android with MIT License | 5 votes |
/** * {@inheritDoc} */ @Override public AttributesDao getAttributesDao(Contents contents) { if (contents == null) { throw new GeoPackageException("Non null " + Contents.class.getSimpleName() + " is required to create " + AttributesDao.class.getSimpleName()); } if (contents.getDataType() != ContentsDataType.ATTRIBUTES) { throw new GeoPackageException(Contents.class.getSimpleName() + " is required to be of type " + ContentsDataType.ATTRIBUTES + ". Actual: " + contents.getDataTypeString()); } // Read the existing table and create the dao AttributesTableReader tableReader = new AttributesTableReader( contents.getTableName()); final AttributesTable attributesTable = tableReader.readTable(database); attributesTable.setContents(contents); AttributesDao dao = new AttributesDao(getName(), database, attributesTable); // Register the table name (with and without quotes) to wrap cursors with the attributes cursor registerCursorWrapper(attributesTable.getTableName(), new GeoPackageCursorWrapper() { @Override public Cursor wrapCursor(Cursor cursor) { return new AttributesCursor(attributesTable, cursor); } }); return dao; }
Example #7
Source File: AttributesUtils.java From geopackage-android with MIT License | 5 votes |
/** * Test delete * * @param geoPackage GeoPackage * @throws SQLException upon error */ public static void testDelete(GeoPackage geoPackage) throws SQLException { List<String> tables = geoPackage.getAttributesTables(); if (!tables.isEmpty()) { for (String tableName : tables) { AttributesDao dao = geoPackage.getAttributesDao(tableName); TestCase.assertNotNull(dao); AttributesCursor cursor = dao.queryForAll(); int count = cursor.getCount(); if (count > 0) { // Choose random attribute int random = (int) (Math.random() * count); cursor.moveToPosition(random); AttributesRow attributesRow = cursor.getRow(); cursor.close(); // Delete row TestCase.assertEquals(1, dao.delete(attributesRow)); // Verify deleted AttributesRow queryAttributesRow = dao .queryForIdRow(attributesRow.getId()); TestCase.assertNull(queryAttributesRow); cursor = dao.queryForAll(); TestCase.assertEquals(count - 1, cursor.getCount()); cursor.close(); } cursor.close(); } } }
Example #8
Source File: FeatureStyleExtension.java From geopackage-java with MIT License | 5 votes |
/** * Get a style DAO * * @return style DAO */ public StyleDao getStyleDao() { StyleDao styleDao = null; if (geoPackage.isTable(StyleTable.TABLE_NAME)) { AttributesDao attributesDao = getGeoPackage() .getAttributesDao(StyleTable.TABLE_NAME); styleDao = new StyleDao(attributesDao); relatedTables.setContents(styleDao.getTable()); } return styleDao; }
Example #9
Source File: GeoPackageExample.java From geopackage-java with MIT License | 4 votes |
private static void createAttributes(GeoPackage geoPackage) { List<AttributesColumn> columns = new ArrayList<AttributesColumn>(); columns.add(AttributesColumn.createColumn(TEXT_COLUMN, GeoPackageDataType.TEXT, false, "")); columns.add(AttributesColumn.createColumn(REAL_COLUMN, GeoPackageDataType.REAL)); columns.add(AttributesColumn.createColumn(BOOLEAN_COLUMN, GeoPackageDataType.BOOLEAN)); columns.add(AttributesColumn.createColumn(BLOB_COLUMN, GeoPackageDataType.BLOB)); columns.add(AttributesColumn.createColumn(INTEGER_COLUMN, GeoPackageDataType.INTEGER)); columns.add(AttributesColumn.createColumn(TEXT_LIMITED_COLUMN, GeoPackageDataType.TEXT, (long) UUID.randomUUID().toString().length())); columns.add(AttributesColumn.createColumn(BLOB_LIMITED_COLUMN, GeoPackageDataType.BLOB, (long) UUID.randomUUID().toString().getBytes().length)); columns.add(AttributesColumn.createColumn(DATE_COLUMN, GeoPackageDataType.DATE)); columns.add(AttributesColumn.createColumn(DATETIME_COLUMN, GeoPackageDataType.DATETIME)); AttributesTable attributesTable = geoPackage .createAttributesTableWithId("attributes", columns); AttributesDao attributesDao = geoPackage .getAttributesDao(attributesTable.getTableName()); for (int i = 0; i < 10; i++) { AttributesRow newRow = attributesDao.newRow(); newRow.setValue(TEXT_COLUMN, UUID.randomUUID().toString()); newRow.setValue(REAL_COLUMN, Math.random() * 5000.0); newRow.setValue(BOOLEAN_COLUMN, Math.random() < .5 ? false : true); newRow.setValue(BLOB_COLUMN, UUID.randomUUID().toString().getBytes()); newRow.setValue(INTEGER_COLUMN, (int) (Math.random() * 500)); newRow.setValue(TEXT_LIMITED_COLUMN, UUID.randomUUID().toString()); newRow.setValue(BLOB_LIMITED_COLUMN, UUID.randomUUID().toString().getBytes()); newRow.setValue(DATE_COLUMN, new Date()); newRow.setValue(DATETIME_COLUMN, new Date()); attributesDao.create(newRow); } }
Example #10
Source File: AttributesUtils.java From geopackage-java with MIT License | 4 votes |
/** * Test update * * @param geoPackage * GeoPackage * @throws SQLException * upon error */ public static void testUpdate(GeoPackage geoPackage) throws SQLException { List<String> tables = geoPackage.getAttributesTables(); if (!tables.isEmpty()) { for (String tableName : tables) { if (tableName.equals(PropertiesExtension.TABLE_NAME)) { continue; } AttributesDao dao = geoPackage.getAttributesDao(tableName); testUpdate(dao); } } }
Example #11
Source File: PropertiesExtension.java From geopackage-java with MIT License | 4 votes |
/** * {@inheritDoc} */ @Override protected AttributesDao getDao() { return getGeoPackage().getAttributesDao(TABLE_NAME); }
Example #12
Source File: GeoPackageExample.java From geopackage-android with MIT License | 4 votes |
private static void createAttributes(GeoPackage geoPackage) { List<AttributesColumn> columns = new ArrayList<AttributesColumn>(); columns.add(AttributesColumn.createColumn(TEXT_COLUMN, GeoPackageDataType.TEXT, false, "")); columns.add(AttributesColumn.createColumn(REAL_COLUMN, GeoPackageDataType.REAL)); columns.add(AttributesColumn.createColumn(BOOLEAN_COLUMN, GeoPackageDataType.BOOLEAN)); columns.add(AttributesColumn.createColumn(BLOB_COLUMN, GeoPackageDataType.BLOB)); columns.add(AttributesColumn.createColumn(INTEGER_COLUMN, GeoPackageDataType.INTEGER)); columns.add(AttributesColumn.createColumn(TEXT_LIMITED_COLUMN, GeoPackageDataType.TEXT, (long) UUID.randomUUID().toString() .length())); columns.add(AttributesColumn.createColumn(BLOB_LIMITED_COLUMN, GeoPackageDataType.BLOB, (long) UUID.randomUUID().toString() .getBytes().length)); columns.add(AttributesColumn.createColumn(DATE_COLUMN, GeoPackageDataType.DATE)); columns.add(AttributesColumn.createColumn(DATETIME_COLUMN, GeoPackageDataType.DATETIME)); AttributesTable attributesTable = geoPackage .createAttributesTableWithId("attributes", columns); AttributesDao attributesDao = geoPackage .getAttributesDao(attributesTable.getTableName()); for (int i = 0; i < 10; i++) { AttributesRow newRow = attributesDao.newRow(); newRow.setValue(TEXT_COLUMN, UUID.randomUUID().toString()); newRow.setValue(REAL_COLUMN, Math.random() * 5000.0); newRow.setValue(BOOLEAN_COLUMN, Math.random() < .5 ? false : true); newRow.setValue(BLOB_COLUMN, UUID.randomUUID().toString() .getBytes()); newRow.setValue(INTEGER_COLUMN, (int) (Math.random() * 500)); newRow.setValue(TEXT_LIMITED_COLUMN, UUID.randomUUID().toString()); newRow.setValue(BLOB_LIMITED_COLUMN, UUID.randomUUID().toString() .getBytes()); newRow.setValue(DATE_COLUMN, new Date()); newRow.setValue(DATETIME_COLUMN, new Date()); attributesDao.create(newRow); } }
Example #13
Source File: AttributesUtils.java From geopackage-android with MIT License | 4 votes |
/** * Test update * * @param geoPackage GeoPackage * @throws SQLException upon error */ public static void testUpdate(GeoPackage geoPackage) throws SQLException { List<String> tables = geoPackage.getAttributesTables(); if (!tables.isEmpty()) { for (String tableName : tables) { if (tableName.equals(PropertiesExtension.TABLE_NAME)) { continue; } AttributesDao dao = geoPackage.getAttributesDao(tableName); testUpdate(dao); } } }
Example #14
Source File: PropertiesExtension.java From geopackage-android with MIT License | 4 votes |
/** * {@inheritDoc} */ @Override protected AttributesDao getDao() { return getGeoPackage().getAttributesDao(TABLE_NAME); }
Example #15
Source File: StyleDao.java From geopackage-java with MIT License | 2 votes |
/** * Constructor * * @param dao * user custom data access object */ public StyleDao(AttributesDao dao) { super(dao.getDatabase(), dao.getDb(), new StyleTable(dao.getTable())); }
Example #16
Source File: GeoPackage.java From geopackage-android with MIT License | 2 votes |
/** * Get an Attributes DAO from a table name * * @param tableName table name * @return attributes dao * @since 1.3.1 */ public AttributesDao getAttributesDao(String tableName);
Example #17
Source File: GeoPackage.java From geopackage-java with MIT License | 2 votes |
/** * Get an Attributes DAO from Contents * * @param contents * contents * @return attributes dao * @since 1.2.1 */ public AttributesDao getAttributesDao(Contents contents);
Example #18
Source File: GeoPackage.java From geopackage-java with MIT License | 2 votes |
/** * Get an Attributes DAO from a table name * * @param tableName * table name * @return attributes dao * @since 1.2.1 */ public AttributesDao getAttributesDao(String tableName);
Example #19
Source File: GeoPackage.java From geopackage-android with MIT License | 2 votes |
/** * Get an Attributes DAO from Contents * * @param contents contents * @return attributes dao * @since 1.3.1 */ public AttributesDao getAttributesDao(Contents contents);
Example #20
Source File: StyleDao.java From geopackage-android with MIT License | 2 votes |
/** * Constructor * * @param dao user custom data access object */ public StyleDao(AttributesDao dao) { super(dao.getDatabase(), dao.getDb(), new StyleTable(dao.getTable())); }