mil.nga.geopackage.db.GeoPackageDataType Java Examples

The following examples show how to use mil.nga.geopackage.db.GeoPackageDataType. 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: RTreeIndexCoreExtension.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * Get the RTree Table
 * 
 * @param featureTable
 *            feature table
 * @return RTree table
 */
protected UserCustomTable getRTreeTable(FeatureTable featureTable) {

	List<UserCustomColumn> columns = new ArrayList<>();
	columns.add(UserCustomColumn.createPrimaryKeyColumn(COLUMN_ID));
	columns.add(UserCustomColumn.createColumn(COLUMN_MIN_X,
			GeoPackageDataType.FLOAT));
	columns.add(UserCustomColumn.createColumn(COLUMN_MAX_X,
			GeoPackageDataType.FLOAT));
	columns.add(UserCustomColumn.createColumn(COLUMN_MIN_Y,
			GeoPackageDataType.FLOAT));
	columns.add(UserCustomColumn.createColumn(COLUMN_MAX_Y,
			GeoPackageDataType.FLOAT));

	String rTreeTableName = getRTreeTableName(featureTable.getTableName(),
			featureTable.getGeometryColumnName());

	UserCustomTable userCustomTable = new UserCustomTable(rTreeTableName,
			columns);

	return userCustomTable;
}
 
Example #2
Source File: UserColumn.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * Validate that if max is set, the data type is text or blob
 */
private void validateMax() {

	if (max != null) {
		if (dataType == null) {
			throw new GeoPackageException(
					"Column max is only supported for data typed columns. column: "
							+ name + ", max: " + max);
		} else if (dataType != GeoPackageDataType.TEXT
				&& dataType != GeoPackageDataType.BLOB) {
			throw new GeoPackageException(
					"Column max is only supported for "
							+ GeoPackageDataType.TEXT.name() + " and "
							+ GeoPackageDataType.BLOB.name()
							+ " columns. column: " + name + ", max: " + max
							+ ", type: " + dataType.name());
		}
	}

}
 
Example #3
Source File: UserCoreRow.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * Validate the value and its actual value types against the column data
 * type class
 * 
 * @param column
 *            column
 * @param value
 *            value
 * @param valueTypes
 *            value types
 */
protected void validateValue(TColumn column, Object value,
		Class<?>... valueTypes) {

	GeoPackageDataType dataType = column.getDataType();
	Class<?> dataTypeClass = dataType.getClassType();

	boolean valid = false;
	for (Class<?> valueType : valueTypes) {
		if (valueType.equals(dataTypeClass)) {
			valid = true;
			break;
		}
	}

	if (!valid) {
		throw new GeoPackageException("Illegal value. Column: "
				+ column.getName() + ", Value: " + value
				+ ", Expected Type: " + dataTypeClass.getSimpleName()
				+ ", Actual Type: " + valueTypes[0].getSimpleName());
	}

}
 
Example #4
Source File: TestUtils.java    From geopackage-java with MIT License 6 votes vote down vote up
/**
 * Validate the float value with the data type
 * 
 * @param value
 * @param dataType
 */
public static void validateFloatValue(Object value,
		GeoPackageDataType dataType) {

	switch (dataType) {

	case FLOAT:
		TestCase.assertTrue(value instanceof Float);
		break;
	case DOUBLE:
	case REAL:
		TestCase.assertTrue(value instanceof Double);
		break;
	default:
		throw new GeoPackageException(
				"Data Type " + dataType + " is not a float type");
	}
}
 
Example #5
Source File: IconTable.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * Create the style columns
 * 
 * @return columns
 */
private static List<UserCustomColumn> createColumns() {

	List<UserCustomColumn> columns = new ArrayList<>();
	columns.addAll(createRequiredColumns());

	columns.add(UserCustomColumn.createColumn(COLUMN_NAME,
			GeoPackageDataType.TEXT));
	columns.add(UserCustomColumn.createColumn(COLUMN_DESCRIPTION,
			GeoPackageDataType.TEXT));
	columns.add(UserCustomColumn.createColumn(COLUMN_WIDTH,
			GeoPackageDataType.REAL));
	columns.add(UserCustomColumn.createColumn(COLUMN_HEIGHT,
			GeoPackageDataType.REAL));
	columns.add(UserCustomColumn.createColumn(COLUMN_ANCHOR_U,
			GeoPackageDataType.REAL));
	columns.add(UserCustomColumn.createColumn(COLUMN_ANCHOR_V,
			GeoPackageDataType.REAL));

	return columns;
}
 
Example #6
Source File: TestUtils.java    From geopackage-android with MIT License 6 votes vote down vote up
/**
 * Validate the float value with the data type
 *
 * @param value
 * @param dataType
 * @return
 */
public static void validateFloatValue(Object value,
                                      GeoPackageDataType dataType) {

    switch (dataType) {

        case FLOAT:
            TestCase.assertTrue(value instanceof Float);
            break;
        case DOUBLE:
        case REAL:
            TestCase.assertTrue(value instanceof Double);
            break;
        default:
            throw new GeoPackageException("Data Type " + dataType
                    + " is not a float type");
    }
}
 
Example #7
Source File: StyleTable.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * Create the style columns
 * 
 * @return columns
 */
private static List<AttributesColumn> createColumns() {

	List<AttributesColumn> columns = new ArrayList<>();

	columns.add(AttributesColumn.createPrimaryKeyColumn(COLUMN_ID));
	columns.add(AttributesColumn.createColumn(COLUMN_NAME,
			GeoPackageDataType.TEXT));
	columns.add(AttributesColumn.createColumn(COLUMN_DESCRIPTION,
			GeoPackageDataType.TEXT));
	columns.add(AttributesColumn.createColumn(COLUMN_COLOR,
			GeoPackageDataType.TEXT));
	columns.add(AttributesColumn.createColumn(COLUMN_OPACITY,
			GeoPackageDataType.REAL));
	columns.add(AttributesColumn.createColumn(COLUMN_WIDTH,
			GeoPackageDataType.REAL));
	columns.add(AttributesColumn.createColumn(COLUMN_FILL_COLOR,
			GeoPackageDataType.TEXT));
	columns.add(AttributesColumn.createColumn(COLUMN_FILL_OPACITY,
			GeoPackageDataType.REAL));

	return columns;
}
 
Example #8
Source File: UserMappingDao.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Get the unique base ids
 *
 * @return list of unique base ids
 * @since 3.2.0
 */
public List<Long> uniqueBaseIds() {
	return querySingleColumnTypedResults(
			"SELECT DISTINCT "
					+ CoreSQLUtils
							.quoteWrap(UserMappingTable.COLUMN_BASE_ID)
					+ " FROM " + CoreSQLUtils.quoteWrap(getTableName()),
			null, GeoPackageDataType.INTEGER);
}
 
Example #9
Source File: GeoPackageTestUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Get additional feature columns to create
 * 
 * @return
 */
public static List<FeatureColumn> getFeatureColumns() {
	List<FeatureColumn> columns = new ArrayList<FeatureColumn>();

	columns.add(FeatureColumn.createColumn(7, "test_text_limited",
			GeoPackageDataType.TEXT, 5L));
	columns.add(FeatureColumn.createColumn(8, "test_blob_limited",
			GeoPackageDataType.BLOB, 7L));
	columns.add(FeatureColumn.createColumn(9, "test_date",
			GeoPackageDataType.DATE));
	columns.add(FeatureColumn.createColumn(10, "test_datetime",
			GeoPackageDataType.DATETIME));
	columns.add(FeatureColumn.createColumn(2, "test_text",
			GeoPackageDataType.TEXT, false, ""));
	columns.add(FeatureColumn.createColumn(3, "test_real",
			GeoPackageDataType.REAL));
	columns.add(FeatureColumn.createColumn(4, "test_boolean",
			GeoPackageDataType.BOOLEAN));

	FeatureColumn blobColumn = FeatureColumn.createColumn("test_blob",
			GeoPackageDataType.BLOB);
	columns.add(blobColumn);
	// Let the index for this column be automatically set to 5
	// blobColumn.setIndex(5);

	// Test setting an index after column creation but before table creation
	FeatureColumn integerColumn = FeatureColumn.createColumn("test_integer",
			GeoPackageDataType.INTEGER);
	columns.add(integerColumn);
	integerColumn.setIndex(6);

	return columns;
}
 
Example #10
Source File: TestUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Build an example feature table
 * 
 * @param tableName
 * @param geometryColumn
 * @param geometryType
 * @return feature table
 */
public static FeatureTable buildFeatureTable(String tableName,
		String geometryColumn, GeometryType geometryType) {

	List<FeatureColumn> columns = new ArrayList<FeatureColumn>();

	columns.add(FeatureColumn.createPrimaryKeyColumn(0, "id"));
	columns.add(FeatureColumn.createColumn(7, "test_text_limited",
			GeoPackageDataType.TEXT, 5L));
	columns.add(FeatureColumn.createColumn(8, "test_blob_limited",
			GeoPackageDataType.BLOB, 7L));
	columns.add(FeatureColumn.createColumn(9, "test_date",
			GeoPackageDataType.DATE));
	columns.add(FeatureColumn.createColumn(10, "test_datetime",
			GeoPackageDataType.DATETIME));
	columns.add(FeatureColumn.createGeometryColumn(1, geometryColumn,
			geometryType));
	columns.add(FeatureColumn.createColumn(2, "test_text",
			GeoPackageDataType.TEXT, false, ""));
	columns.add(FeatureColumn.createColumn(3, "test_real",
			GeoPackageDataType.REAL));
	columns.add(FeatureColumn.createColumn(4, "test_boolean",
			GeoPackageDataType.BOOLEAN));
	columns.add(FeatureColumn.createColumn(5, "test_blob",
			GeoPackageDataType.BLOB));
	columns.add(FeatureColumn.createColumn(6, TEST_INTEGER_COLUMN,
			GeoPackageDataType.INTEGER));

	FeatureTable table = new FeatureTable(tableName, geometryColumn,
			columns);

	return table;
}
 
Example #11
Source File: FeatureColumn.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Attempt to get the geometry type of the table column
 * 
 * @param tableColumn
 *            table column
 * @return geometry type
 */
private static GeometryType getGeometryType(TableColumn tableColumn) {
	GeometryType geometryType = null;
	if (tableColumn.isDataType(GeoPackageDataType.BLOB)) {
		geometryType = GeometryType.findName(tableColumn.getType());
	}
	return geometryType;
}
 
Example #12
Source File: PropertiesCoreExtension.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Get or create the extension
 * 
 * @return extension
 */
public Extensions getOrCreate() {

	// Create the attributes table
	if (!geoPackage.isTable(TABLE_NAME)) {

		AttributesColumn propertyColumn = AttributesColumn.createColumn(
				COLUMN_PROPERTY, GeoPackageDataType.TEXT, true, null);
		AttributesColumn valueColumn = AttributesColumn
				.createColumn(COLUMN_VALUE, GeoPackageDataType.TEXT);

		List<AttributesColumn> additionalColumns = new ArrayList<>();
		additionalColumns.add(propertyColumn);
		additionalColumns.add(valueColumn);

		List<Constraint> constraints = new ArrayList<>();
		constraints.add(new UniqueConstraint(propertyColumn, valueColumn));

		geoPackage.createAttributesTableWithId(TABLE_NAME,
				additionalColumns, constraints);
	}

	Extensions extension = getOrCreate(EXTENSION_NAME, TABLE_NAME, null,
			EXTENSION_DEFINITION, ExtensionScopeType.READ_WRITE);

	return extension;
}
 
Example #13
Source File: FeatureCoreGenerator.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Get the type for the object value
 * 
 * @param value
 *            value
 * @return data type
 */
public static GeoPackageDataType getType(Object value) {

	GeoPackageDataType type = null;

	if (value instanceof String) {
		type = GeoPackageDataType.TEXT;
	} else if (value instanceof Boolean) {
		type = GeoPackageDataType.BOOLEAN;
	} else if (value instanceof Byte) {
		type = GeoPackageDataType.TINYINT;
	} else if (value instanceof Short) {
		type = GeoPackageDataType.SMALLINT;
	} else if (value instanceof Integer) {
		type = GeoPackageDataType.MEDIUMINT;
	} else if (value instanceof Long) {
		type = GeoPackageDataType.INT;
	} else if (value instanceof Float) {
		type = GeoPackageDataType.FLOAT;
	} else if (value instanceof Double) {
		type = GeoPackageDataType.DOUBLE;
	} else if (value instanceof byte[]) {
		type = GeoPackageDataType.BLOB;
	}

	if (type == null) {
		type = GeoPackageDataType.TEXT;
	}

	return type;
}
 
Example #14
Source File: TestUtils.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Validate the integer value with the data type
 *
 * @param value
 * @param dataType
 * @return
 */
public static void validateIntegerValue(Object value,
                                        GeoPackageDataType dataType) {

    switch (dataType) {

        case BOOLEAN:
            TestCase.assertTrue(value instanceof Boolean);
            break;
        case TINYINT:
            TestCase.assertTrue(value instanceof Byte);
            break;
        case SMALLINT:
            TestCase.assertTrue(value instanceof Short);
            break;
        case MEDIUMINT:
            TestCase.assertTrue(value instanceof Integer);
            break;
        case INT:
        case INTEGER:
            TestCase.assertTrue(value instanceof Long);
            break;
        default:
            throw new GeoPackageException("Data Type " + dataType
                    + " is not an integer type");
    }
}
 
Example #15
Source File: TestUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Validate the integer value with the data type
 * 
 * @param value
 * @param dataType
 */
public static void validateIntegerValue(Object value,
		GeoPackageDataType dataType) {

	switch (dataType) {

	case BOOLEAN:
		TestCase.assertTrue(value instanceof Boolean);
		break;
	case TINYINT:
		TestCase.assertTrue(value instanceof Byte);
		break;
	case SMALLINT:
		TestCase.assertTrue(value instanceof Short);
		break;
	case MEDIUMINT:
		TestCase.assertTrue(value instanceof Integer);
		break;
	case INT:
	case INTEGER:
		TestCase.assertTrue(value instanceof Long);
		break;
	default:
		throw new GeoPackageException(
				"Data Type " + dataType + " is not an integer type");
	}
}
 
Example #16
Source File: UserColumns.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Check for the expected data type
 * 
 * @param expected
 *            expected data type
 * @param column
 *            user column
 */
protected void typeCheck(GeoPackageDataType expected, TColumn column) {

	GeoPackageDataType actual = column.getDataType();
	if (actual == null || !actual.equals(expected)) {
		throw new GeoPackageException("Unexpected " + column.getName()
				+ " column data type was found for table '" + tableName
				+ "', expected: " + expected.name() + ", actual: "
				+ (actual != null ? actual.name() : "null"));
	}
}
 
Example #17
Source File: RelatedTablesUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Create additional user table columns
 * 
 * @param notNull
 *            columns not null value
 * @return additional user table columns
 */
public static List<UserCustomColumn> createAdditionalUserColumns(
		boolean notNull) {

	List<UserCustomColumn> columns = new ArrayList<>();

	// Add Dublin Core Metadata term columns
	columns.add(UserCustomColumn.createColumn(
			DublinCoreType.DATE.getName(), GeoPackageDataType.DATETIME,
			notNull));
	columns.add(UserCustomColumn.createColumn(
			DublinCoreType.DESCRIPTION.getName(), GeoPackageDataType.TEXT,
			notNull));
	columns.add(UserCustomColumn.createColumn(
			DublinCoreType.SOURCE.getName(), GeoPackageDataType.TEXT,
			notNull));
	columns.add(UserCustomColumn.createColumn(
			DublinCoreType.TITLE.getName(), GeoPackageDataType.TEXT,
			notNull));

	// Add test columns for common data types, some with limits
	columns.add(UserCustomColumn.createColumn("test_text",
			GeoPackageDataType.TEXT, notNull, ""));
	columns.add(UserCustomColumn.createColumn("test_real",
			GeoPackageDataType.REAL, notNull));
	columns.add(UserCustomColumn.createColumn("test_boolean",
			GeoPackageDataType.BOOLEAN, notNull));
	columns.add(UserCustomColumn.createColumn("test_blob",
			GeoPackageDataType.BLOB, notNull));
	columns.add(UserCustomColumn.createColumn("test_integer",
			GeoPackageDataType.INTEGER, notNull));
	columns.add(UserCustomColumn.createColumn("test_text_limited",
			GeoPackageDataType.TEXT, 5L, notNull, null));
	columns.add(UserCustomColumn.createColumn("test_blob_limited",
			GeoPackageDataType.BLOB, 7L, notNull, null));
	columns.add(UserCustomColumn.createColumn("test_date",
			GeoPackageDataType.DATE, notNull));
	columns.add(UserCustomColumn.createColumn("test_datetime",
			GeoPackageDataType.DATETIME, notNull));

	return columns;
}
 
Example #18
Source File: FeatureUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Validate a feature row
 *
 * @param columns
 * @param featureRow
 */
private static void validateFeatureRow(String[] columns,
                                       FeatureRow featureRow) {
    TestCase.assertEquals(columns.length, featureRow.columnCount());

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

        switch (rowType) {

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

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

            case Cursor.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 Cursor.FIELD_TYPE_BLOB:
                if (featureRow.getGeometryColumnIndex() == i) {
                    TestCase.assertTrue(value instanceof GeoPackageGeometryData);
                } else {
                    TestCase.assertTrue(value instanceof byte[]);
                }
                break;

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

        }
    }

    TestCase.assertTrue(featureRow.getId() >= 0);
}
 
Example #19
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 #20
Source File: RelatedTablesUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Create additional user table columns
 *
 * @param notNull columns not null value
 * @return additional user table columns
 */
public static List<UserCustomColumn> createAdditionalUserColumns(
        boolean notNull) {

    List<UserCustomColumn> columns = new ArrayList<>();

    // Add Dublin Core Metadata term columns
    columns.add(UserCustomColumn.createColumn(
            DublinCoreType.DATE.getName(), GeoPackageDataType.DATETIME,
            notNull));
    columns.add(UserCustomColumn.createColumn(
            DublinCoreType.DESCRIPTION.getName(), GeoPackageDataType.TEXT,
            notNull));
    columns.add(UserCustomColumn.createColumn(
            DublinCoreType.SOURCE.getName(), GeoPackageDataType.TEXT,
            notNull));
    columns.add(UserCustomColumn.createColumn(
            DublinCoreType.TITLE.getName(), GeoPackageDataType.TEXT,
            notNull));

    // Add test columns for common data types, some with limits
    columns.add(UserCustomColumn.createColumn("test_text",
            GeoPackageDataType.TEXT, notNull, ""));
    columns.add(UserCustomColumn.createColumn("test_real",
            GeoPackageDataType.REAL, notNull));
    columns.add(UserCustomColumn.createColumn("test_boolean",
            GeoPackageDataType.BOOLEAN, notNull));
    columns.add(UserCustomColumn.createColumn("test_blob",
            GeoPackageDataType.BLOB, notNull));
    columns.add(UserCustomColumn.createColumn("test_integer",
            GeoPackageDataType.INTEGER, notNull));
    columns.add(UserCustomColumn.createColumn("test_text_limited",
            GeoPackageDataType.TEXT, 5L, notNull, null));
    columns.add(UserCustomColumn.createColumn("test_blob_limited",
            GeoPackageDataType.BLOB, 7L, notNull, null));
    columns.add(UserCustomColumn.createColumn("test_date",
            GeoPackageDataType.DATE, notNull));
    columns.add(UserCustomColumn.createColumn("test_datetime",
            GeoPackageDataType.DATETIME, notNull));

    return columns;
}
 
Example #21
Source File: UserColumn.java    From geopackage-core-java with MIT License 4 votes vote down vote up
/**
 * Constructor
 * 
 * @param index
 *            column index
 * @param name
 *            column name
 * @param type
 *            string type
 * @param dataType
 *            data type
 * @param max
 *            max value
 * @param notNull
 *            not null flag
 * @param defaultValue
 *            default value
 * @param primaryKey
 *            primary key flag
 * @since 3.3.0
 */
protected UserColumn(int index, String name, String type,
		GeoPackageDataType dataType, Long max, boolean notNull,
		Object defaultValue, boolean primaryKey) {
	this.index = index;
	this.name = name;
	this.max = max;
	this.notNull = notNull;
	this.defaultValue = defaultValue;
	this.primaryKey = primaryKey;
	this.type = type;
	this.dataType = dataType;

	validateDataType(name, dataType);
	validateMax();

	addDefaultConstraints();
}
 
Example #22
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 #23
Source File: UserInvalidCursor.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Object getValue(int index, GeoPackageDataType dataType) {
    return cursor.getValue(index, dataType);
}
 
Example #24
Source File: UserCursor.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Object getValue(int index, GeoPackageDataType dataType) {
    return ResultUtils.getValue(invalidCursor == null ? this : invalidCursor, index, dataType);
}
 
Example #25
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 #26
Source File: TileColumns.java    From geopackage-core-java with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void updateColumns() {
	super.updateColumns();

	// Find the required columns

	Integer zoomLevel = getColumnIndex(ZOOM_LEVEL, false);
	if (!isCustom()) {
		missingCheck(zoomLevel, ZOOM_LEVEL);
	}
	if (zoomLevel != null) {
		typeCheck(GeoPackageDataType.INTEGER, getColumn(zoomLevel));
		zoomLevelIndex = zoomLevel;
	}

	Integer tileColumn = getColumnIndex(TILE_COLUMN, false);
	if (!isCustom()) {
		missingCheck(tileColumn, TILE_COLUMN);
	}
	if (tileColumn != null) {
		typeCheck(GeoPackageDataType.INTEGER, getColumn(tileColumn));
		tileColumnIndex = tileColumn;
	}

	Integer tileRow = getColumnIndex(TILE_ROW, false);
	if (!isCustom()) {
		missingCheck(tileRow, TILE_ROW);
	}
	if (tileRow != null) {
		typeCheck(GeoPackageDataType.INTEGER, getColumn(tileRow));
		tileRowIndex = tileRow;
	}

	Integer tileData = getColumnIndex(TILE_DATA, false);
	if (!isCustom()) {
		missingCheck(tileData, TILE_DATA);
	}
	if (tileData != null) {
		typeCheck(GeoPackageDataType.BLOB, getColumn(tileData));
		tileDataIndex = tileData;
	}

}
 
Example #27
Source File: FeatureUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Validate a feature row
 * 
 * @param columns
 * @param featureRow
 */
private static void validateFeatureRow(String[] columns,
		FeatureRow featureRow) {
	TestCase.assertEquals(columns.length, featureRow.columnCount());

	for (int i = 0; i < featureRow.columnCount(); i++) {
		FeatureColumn column = featureRow.getTable().getColumns().get(i);
		GeoPackageDataType dataType = column.getDataType();
		TestCase.assertEquals(i, column.getIndex());
		TestCase.assertEquals(columns[i], featureRow.getColumnName(i));
		TestCase.assertEquals(i, featureRow.getColumnIndex(columns[i]));
		int rowType = featureRow.getRowColumnType(i);
		Object value = featureRow.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:
			if (featureRow.getGeometryColumnIndex() == i) {
				TestCase.assertTrue(value instanceof GeoPackageGeometryData);
			} else {
				TestCase.assertTrue(value instanceof byte[]);
			}
			break;

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

		}
	}

	TestCase.assertTrue(featureRow.getId() >= 0);
}
 
Example #28
Source File: FeatureCoreGenerator.java    From geopackage-core-java with MIT License 4 votes vote down vote up
/**
 * Get the value for the object value with the data type
 * 
 * @param value
 *            value
 * @param type
 *            data type
 * @return default value
 */
public static Object getValue(Object value, GeoPackageDataType type) {

	if (value != null && type != null) {

		switch (type) {
		case TEXT:
		case DATE:
		case DATETIME:
			value = value.toString();
			break;
		case BOOLEAN:
			value = (Boolean) value;
			break;
		case TINYINT:
			value = (Byte) value;
			break;
		case SMALLINT:
			value = (Short) value;
			break;
		case MEDIUMINT:
			value = (Integer) value;
			break;
		case INT:
		case INTEGER:
			value = (Long) value;
			break;
		case FLOAT:
			value = (Float) value;
			break;
		case DOUBLE:
		case REAL:
			value = (Double) value;
			break;
		case BLOB:
			value = (byte[]) value;
			break;
		default:
			throw new GeoPackageException("Unsupported Data Type " + type);
		}

	}

	return value;
}
 
Example #29
Source File: FeatureColumn.java    From geopackage-core-java with MIT License 3 votes vote down vote up
/**
 * Constructor
 * 
 * @param index
 *            index
 * @param name
 *            name
 * @param dataType
 *            data type
 * @param max
 *            max value
 * @param notNull
 *            not null flag
 * @param defaultValue
 *            default value
 * @param primaryKey
 *            primary key flag
 * @param geometryType
 *            geometry type
 */
private FeatureColumn(int index, String name, GeoPackageDataType dataType,
		Long max, boolean notNull, Object defaultValue, boolean primaryKey,
		GeometryType geometryType) {
	super(index, name, getTypeName(name, dataType, geometryType), dataType,
			max, notNull, defaultValue, primaryKey);
	this.geometryType = geometryType;
}
 
Example #30
Source File: FeatureColumn.java    From geopackage-core-java with MIT License 3 votes vote down vote up
/**
 * Create a new column
 * 
 * @param index
 *            index
 * @param name
 *            name
 * @param type
 *            data type
 * @param max
 *            max value
 * @param notNull
 *            not null flag
 * @param defaultValue
 *            default value
 * @return feature column
 */
public static FeatureColumn createColumn(int index, String name,
		GeoPackageDataType type, Long max, boolean notNull,
		Object defaultValue) {
	return new FeatureColumn(index, name, type, max, notNull, defaultValue,
			false, null);
}