mil.nga.geopackage.attributes.AttributesRow Java Examples

The following examples show how to use mil.nga.geopackage.attributes.AttributesRow. 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: StyleDao.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Query for the style row from a style mapping row
 *
 * @param styleMappingRow style mapping row
 * @return style row
 */
public StyleRow queryForRow(StyleMappingRow styleMappingRow) {
    StyleRow styleRow = null;

    AttributesRow attributesRow = queryForIdRow(styleMappingRow
            .getRelatedId());
    if (attributesRow != null) {
        styleRow = getRow(attributesRow);
    }

    return styleRow;
}
 
Example #2
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 #3
Source File: StyleDao.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Query for the style row from a style mapping row
 * 
 * @param styleMappingRow
 *            style mapping row
 * @return style row
 */
public StyleRow queryForRow(StyleMappingRow styleMappingRow) {
	StyleRow styleRow = null;

	AttributesRow attributesRow = queryForIdRow(
			styleMappingRow.getRelatedId());
	if (attributesRow != null) {
		styleRow = getRow(attributesRow);
	}

	return styleRow;
}
 
Example #4
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 #5
Source File: PropertiesExtension.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected AttributesRow newRow() {
    return getDao().newRow();
}
 
Example #6
Source File: AttributesUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Validate an attributes row
 *
 * @param columns
 * @param attributesRow
 */
private static void validateAttributesRow(String[] columns,
                                          AttributesRow attributesRow) {
    TestCase.assertEquals(columns.length, attributesRow.columnCount());

    for (int i = 0; i < attributesRow.columnCount(); i++) {
        AttributesColumn column = attributesRow.getTable().getColumns()
                .get(i);
        GeoPackageDataType dataType = column.getDataType();
        TestCase.assertEquals(i, column.getIndex());
        TestCase.assertEquals(columns[i], attributesRow.getColumnName(i));
        TestCase.assertEquals(i, attributesRow.getColumnIndex(columns[i]));
        int rowType = attributesRow.getRowColumnType(i);
        Object value = attributesRow.getValue(i);

        switch (rowType) {

            case ResultUtils.FIELD_TYPE_INTEGER:
                TestUtils.validateIntegerValue(value, column.getDataType());
                break;

            case ResultUtils.FIELD_TYPE_FLOAT:
                TestUtils.validateFloatValue(value, column.getDataType());
                break;

            case ResultUtils.FIELD_TYPE_STRING:
                if (dataType == GeoPackageDataType.DATE || dataType == GeoPackageDataType.DATETIME) {
                    TestCase.assertTrue(value instanceof Date);
                    Date date = (Date) value;
                    DateConverter converter = DateConverter.converter(dataType);
                    String dateString = converter.stringValue(date);
                    TestCase.assertEquals(date.getTime(), converter.dateValue(dateString).getTime());
                } else {
                    TestCase.assertTrue(value instanceof String);
                }
                break;

            case ResultUtils.FIELD_TYPE_BLOB:
                TestCase.assertTrue(value instanceof byte[]);
                break;

            case ResultUtils.FIELD_TYPE_NULL:
                TestCase.assertNull(value);
                break;

        }
    }

    TestCase.assertTrue(attributesRow.getId() >= 0);
}
 
Example #7
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 #8
Source File: PropertiesExtension.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected AttributesRow newRow() {
	return getDao().newRow();
}
 
Example #9
Source File: AttributesUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Validate an attributes row
 * 
 * @param columns
 * @param attributesRow
 */
private static void validateAttributesRow(String[] columns,
		AttributesRow attributesRow) {
	TestCase.assertEquals(columns.length, attributesRow.columnCount());

	for (int i = 0; i < attributesRow.columnCount(); i++) {
		AttributesColumn column = attributesRow.getTable().getColumns()
				.get(i);
		GeoPackageDataType dataType = column.getDataType();
		TestCase.assertEquals(i, column.getIndex());
		TestCase.assertEquals(columns[i], attributesRow.getColumnName(i));
		TestCase.assertEquals(i, attributesRow.getColumnIndex(columns[i]));
		int rowType = attributesRow.getRowColumnType(i);
		Object value = attributesRow.getValue(i);

		switch (rowType) {

		case ResultUtils.FIELD_TYPE_INTEGER:
			TestUtils.validateIntegerValue(value, column.getDataType());
			break;

		case ResultUtils.FIELD_TYPE_FLOAT:
			TestUtils.validateFloatValue(value, column.getDataType());
			break;

		case ResultUtils.FIELD_TYPE_STRING:
			if (dataType == GeoPackageDataType.DATE
					|| dataType == GeoPackageDataType.DATETIME) {
				TestCase.assertTrue(value instanceof Date);
				Date date = (Date) value;
				DateConverter converter = DateConverter.converter(dataType);
				String dateString = converter.stringValue(date);
				TestCase.assertEquals(date.getTime(),
						converter.dateValue(dateString).getTime());
			} else {
				TestCase.assertTrue(value instanceof String);
			}
			break;

		case ResultUtils.FIELD_TYPE_BLOB:
			TestCase.assertTrue(value instanceof byte[]);
			break;

		case ResultUtils.FIELD_TYPE_NULL:
			TestCase.assertNull(value);
			break;

		}
	}

	TestCase.assertTrue(attributesRow.getId() >= 0);
}
 
Example #10
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);

		}
	}
 
Example #11
Source File: StyleDao.java    From geopackage-android with MIT License 2 votes vote down vote up
/**
 * Get a style row from the attributes row
 *
 * @param row attributes row
 * @return style row
 */
public StyleRow getRow(AttributesRow row) {
    return new StyleRow(row);
}
 
Example #12
Source File: StyleRow.java    From geopackage-android with MIT License 2 votes vote down vote up
/**
 * Constructor
 *
 * @param attributesRow attributes row
 */
public StyleRow(AttributesRow attributesRow) {
    super(attributesRow);
}
 
Example #13
Source File: StyleDao.java    From geopackage-java with MIT License 2 votes vote down vote up
/**
 * Get a style row from the attributes row
 * 
 * @param row
 *            attributes row
 * @return style row
 */
public StyleRow getRow(AttributesRow row) {
	return new StyleRow(row);
}
 
Example #14
Source File: StyleRow.java    From geopackage-java with MIT License 2 votes vote down vote up
/**
 * Constructor
 * 
 * @param attributesRow
 *            attributes row
 */
public StyleRow(AttributesRow attributesRow) {
	super(attributesRow);
}