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

The following examples show how to use mil.nga.geopackage.GeoPackage#getAttributesDao() . 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: AttributesUtils.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * 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 2
Source File: AttributesUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * 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 3
Source File: AttributesUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * 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 4
Source File: GeoPackageExample.java    From geopackage-android with MIT License 4 votes vote down vote up
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 5
Source File: AttributesUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * 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 6
Source File: GeoPackageExample.java    From geopackage-java with MIT License 4 votes vote down vote up
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);

		}
	}