mil.nga.geopackage.user.custom.UserCustomColumn Java Examples

The following examples show how to use mil.nga.geopackage.user.custom.UserCustomColumn. 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: RelatedTablesUtils.java    From geopackage-android with MIT License 6 votes vote down vote up
/**
 * Create simple user columns
 *
 * @param notNull not null flag
 * @return columns
 */
public static List<UserCustomColumn> createSimpleUserColumns(boolean notNull) {

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

    List<UserCustomColumn> allAdditionalColumns = createAdditionalUserColumns(notNull);

    for (UserCustomColumn column : allAdditionalColumns) {
        if (SimpleAttributesTable.isSimple(column)) {
            simpleUserColumns.add(UserCustomColumn.createColumn(
                    column.getName(), column.getDataType(),
                    column.getMax(), column.isNotNull(),
                    column.getDefaultValue()));
        }
    }

    return simpleUserColumns;
}
 
Example #2
Source File: RelatedTablesUtils.java    From geopackage-java with MIT License 6 votes vote down vote up
/**
 * Validate a user row for expected Dublin Core Column
 * 
 * @param userRow
 *            user custom row
 * @param type
 *            Dublin Core Type
 */
public static void validateDublinCoreColumn(UserCustomRow userRow,
		DublinCoreType type) {

	UserCustomTable customTable = userRow.getTable();

	TestCase.assertTrue(DublinCoreMetadata.hasColumn(userRow.getTable(),
			type));
	TestCase.assertTrue(DublinCoreMetadata.hasColumn(userRow, type));
	UserCustomColumn column1 = DublinCoreMetadata.getColumn(customTable,
			type);
	UserCustomColumn column2 = DublinCoreMetadata.getColumn(userRow, type);
	TestCase.assertNotNull(column1);
	TestCase.assertNotNull(column2);
	TestCase.assertEquals(column1, column2);
	Object value = DublinCoreMetadata.getValue(userRow, type);
	TestCase.assertNotNull(value);

}
 
Example #3
Source File: RelatedTablesUtils.java    From geopackage-android with MIT License 6 votes vote down vote up
/**
 * Validate a user row for expected Dublin Core Column
 *
 * @param userRow user custom row
 * @param type    Dublin Core Type
 */
public static void validateDublinCoreColumn(UserCustomRow userRow,
                                            DublinCoreType type) {

    UserCustomTable customTable = userRow.getTable();

    TestCase.assertTrue(DublinCoreMetadata.hasColumn(userRow.getTable(),
            type));
    TestCase.assertTrue(DublinCoreMetadata.hasColumn(userRow, type));
    UserCustomColumn column1 = DublinCoreMetadata.getColumn(customTable,
            type);
    UserCustomColumn column2 = DublinCoreMetadata.getColumn(userRow, type);
    TestCase.assertNotNull(column1);
    TestCase.assertNotNull(column2);
    TestCase.assertEquals(column1, column2);
    Object value = DublinCoreMetadata.getValue(userRow, type);
    TestCase.assertNotNull(value);

}
 
Example #4
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 #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: RelatedTablesUtils.java    From geopackage-java with MIT License 6 votes vote down vote up
/**
 * Create simple user columns
 * 
 * @param notNull
 *            not null flag
 * @return columns
 */
public static List<UserCustomColumn> createSimpleUserColumns(boolean notNull) {

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

	List<UserCustomColumn> allAdditionalColumns = createAdditionalUserColumns(notNull);

	for (UserCustomColumn column : allAdditionalColumns) {
		if (SimpleAttributesTable.isSimple(column)) {
			simpleUserColumns.add(UserCustomColumn.createColumn(
					column.getName(), column.getDataType(),
					column.getMax(), column.isNotNull(),
					column.getDefaultValue()));
		}
	}

	return simpleUserColumns;
}
 
Example #7
Source File: SimpleAttributesTable.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * Validate that Simple Attributes columns to verify at least one non id
 * column exists and that all columns are simple data types
 */
private void validateColumns() {

	List<UserCustomColumn> columns = getColumns();
	if (columns.size() < 2) {
		throw new GeoPackageException(
				"Simple Attributes Tables require at least one non id column. Columns: "
						+ columns.size());
	}

	for (UserCustomColumn column : columns) {
		if (!isSimple(column)) {
			throw new GeoPackageException(
					"Simple Attributes Tables only support simple data types. Column: "
							+ column.getName() + ", Non Simple Data Type: "
							+ column.getDataType().name());
		}
	}
}
 
Example #8
Source File: GeoPackageExample.java    From geopackage-android with MIT License 6 votes vote down vote up
private static void createRelatedTablesFeaturesExtension(
        GeoPackage geoPackage, String tableName1, String tableName2) {

    RelatedTablesExtension relatedTables = new RelatedTablesExtension(
            geoPackage);

    List<UserCustomColumn> additionalMappingColumns = RelatedTablesUtils
            .createAdditionalUserColumns();

    UserMappingTable userMappingTable = UserMappingTable.create(tableName1
            + "_" + tableName2, additionalMappingColumns);
    ExtendedRelation relation = relatedTables.addFeaturesRelationship(
            tableName1, tableName2, userMappingTable);

    insertRelatedTablesFeaturesExtensionRows(geoPackage, relation);
}
 
Example #9
Source File: MediaTable.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Create the required table columns with the id column name
 * 
 * @param idColumnName
 *            id column name
 * @return user custom columns
 */
public static List<UserCustomColumn> createRequiredColumns(
		String idColumnName) {

	if (idColumnName == null) {
		idColumnName = COLUMN_ID;
	}

	List<UserCustomColumn> columns = new ArrayList<>();
	columns.add(createIdColumn(idColumnName));
	columns.add(createDataColumn());
	columns.add(createContentTypeColumn());

	return columns;
}
 
Example #10
Source File: SimpleAttributesTable.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Create the required table columns with id column name, starting at the
 * provided index
 * 
 * @param startingIndex
 *            starting index
 * @param idColumnName
 *            id column name
 * @return user custom columns
 */
public static List<UserCustomColumn> createRequiredColumns(
		int startingIndex, String idColumnName) {

	if (idColumnName == null) {
		idColumnName = COLUMN_ID;
	}

	List<UserCustomColumn> columns = new ArrayList<>();
	columns.add(createIdColumn(startingIndex++, idColumnName));

	return columns;
}
 
Example #11
Source File: MediaTable.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Create the required table columns with id column name, starting at the
 * provided index
 * 
 * @param startingIndex
 *            starting index
 * @param idColumnName
 *            id column name
 * @return user custom columns
 */
public static List<UserCustomColumn> createRequiredColumns(
		int startingIndex, String idColumnName) {

	if (idColumnName == null) {
		idColumnName = COLUMN_ID;
	}

	List<UserCustomColumn> columns = new ArrayList<>();
	columns.add(createIdColumn(startingIndex++, idColumnName));
	columns.add(createDataColumn(startingIndex++));
	columns.add(createContentTypeColumn(startingIndex++));

	return columns;
}
 
Example #12
Source File: StyleMappingTable.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Create the style mapping columns
 * 
 * @return columns
 */
private static List<UserCustomColumn> createColumns() {

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

	columns.add(UserCustomColumn.createColumn(COLUMN_GEOMETRY_TYPE_NAME,
			GeoPackageDataType.TEXT));

	return columns;
}
 
Example #13
Source File: SimpleAttributesTable.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Create the required table columns with the id column name
 * 
 * @param idColumnName
 *            id column name
 * @return user custom columns
 */
public static List<UserCustomColumn> createRequiredColumns(
		String idColumnName) {

	if (idColumnName == null) {
		idColumnName = COLUMN_ID;
	}

	List<UserCustomColumn> columns = new ArrayList<>();
	columns.add(createIdColumn(idColumnName));

	return columns;
}
 
Example #14
Source File: UserMappingTable.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Create a user mapping table with the minimum required columns followed by
 * the additional columns
 * 
 * @param tableName
 *            table name
 * @param additionalColumns
 *            additional columns
 * @return user mapping table
 */
public static UserMappingTable create(String tableName,
		List<UserCustomColumn> additionalColumns) {

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

	if (additionalColumns != null) {
		columns.addAll(additionalColumns);
	}

	return new UserMappingTable(tableName, columns);
}
 
Example #15
Source File: RelatedTablesCoreExtension.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Get the primary key of a table
 * 
 * @param tableName
 *            table name
 * @return the column name
 */
public String getPrimaryKeyColumnName(String tableName) {
	UserCustomTable table = UserCustomTableReader
			.readTable(geoPackage.getDatabase(), tableName);
	UserCustomColumn pkColumn = table.getPkColumn();
	if (pkColumn == null) {
		throw new GeoPackageException(
				"Found no primary key for table " + tableName);
	}
	return pkColumn.getName();
}
 
Example #16
Source File: MediaTable.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Create a media table with the id column and minimum required columns
 * followed by the additional columns
 * 
 * @param tableName
 *            table name
 * @param idColumnName
 *            id column name
 * @param additionalColumns
 *            additional columns
 * @return media table
 */
public static MediaTable create(String tableName, String idColumnName,
		List<UserCustomColumn> additionalColumns) {

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

	if (additionalColumns != null) {
		columns.addAll(additionalColumns);
	}

	return new MediaTable(tableName, columns, idColumnName);
}
 
Example #17
Source File: GeoPackageExample.java    From geopackage-android with MIT License 4 votes vote down vote up
private static void createRelatedTablesMediaExtension(Activity activity, Context testContext, GeoPackage geoPackage) throws IOException {

        RelatedTablesExtension relatedTables = new RelatedTablesExtension(
                geoPackage);

        List<UserCustomColumn> additionalMediaColumns = RelatedTablesUtils
                .createAdditionalUserColumns();
        MediaTable mediaTable = MediaTable.create("media",
                additionalMediaColumns);

        List<UserCustomColumn> additionalMappingColumns = RelatedTablesUtils
                .createAdditionalUserColumns();

        String tableName1 = "geometry1";
        UserMappingTable userMappingTable1 = UserMappingTable.create(tableName1
                + "_" + mediaTable.getTableName(), additionalMappingColumns);
        ExtendedRelation relation1 = relatedTables.addMediaRelationship(
                tableName1, mediaTable, userMappingTable1);

        insertRelatedTablesMediaExtensionRows(activity, testContext, geoPackage, relation1,
                "BIT Systems%", "BIT Systems", "BITSystems_Logo.png",
                "image/png", "BIT Systems Logo", "http://www.bit-sys.com");

        String tableName2 = "geometry2";
        UserMappingTable userMappingTable2 = UserMappingTable.create(tableName2
                + "_" + mediaTable.getTableName(), additionalMappingColumns);
        ExtendedRelation relation2 = relatedTables.addMediaRelationship(
                tableName2, mediaTable, userMappingTable2);

        insertRelatedTablesMediaExtensionRows(activity, testContext, geoPackage, relation2, "NGA%",
                "NGA", "NGA_Logo.png", "image/png", "NGA Logo",
                "http://www.nga.mil");
        insertRelatedTablesMediaExtensionRows(activity, testContext, geoPackage, relation2, "NGA",
                "NGA", "NGA.jpg", "image/jpeg", "Aerial View of NGA East",
                "http://www.nga.mil");

        if (CONTENTS_ID) {
            insertRelatedTablesMediaPreviewExtensionRows(activity, geoPackage,
                    relatedTables);
        }

    }
 
Example #18
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 #19
Source File: RelatedTablesUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Validate a user row
 *
 * @param columns array of columns
 * @param userRow user custom row
 */
public static void validateUserRow(String[] columns, UserCustomRow userRow) {

    TestCase.assertEquals(columns.length, userRow.columnCount());

    for (int i = 0; i < userRow.columnCount(); i++) {
        UserCustomColumn column = userRow.getTable().getColumns().get(i);
        GeoPackageDataType dataType = column.getDataType();
        TestCase.assertEquals(i, column.getIndex());
        TestCase.assertEquals(columns[i], userRow.getColumnName(i));
        TestCase.assertEquals(i, userRow.getColumnIndex(columns[i]));
        int rowType = userRow.getRowColumnType(i);
        Object value = userRow.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;

        }
    }

}
 
Example #20
Source File: RelatedTablesUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Validate a user row
 * 
 * @param columns
 *            array of columns
 * @param userRow
 *            user custom row
 */
public static void validateUserRow(String[] columns, UserCustomRow userRow) {

	TestCase.assertEquals(columns.length, userRow.columnCount());

	for (int i = 0; i < userRow.columnCount(); i++) {
		UserCustomColumn column = userRow.getTable().getColumns().get(i);
		GeoPackageDataType dataType = column.getDataType();
		TestCase.assertEquals(i, column.getIndex());
		TestCase.assertEquals(columns[i], userRow.getColumnName(i));
		TestCase.assertEquals(i, userRow.getColumnIndex(columns[i]));
		int rowType = userRow.getRowColumnType(i);
		Object value = userRow.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;

		}
	}

}
 
Example #21
Source File: GeoPackageExample.java    From geopackage-java with MIT License 4 votes vote down vote up
private static void createRelatedTablesTilesExtension(
		GeoPackage geoPackage) {

	String featureTable = "point2";
	String tileTable = "nga";

	RelatedTablesExtension relatedTables = new RelatedTablesExtension(
			geoPackage);

	List<UserCustomColumn> additionalMappingColumns = RelatedTablesUtils
			.createAdditionalUserColumns();

	UserMappingTable userMappingTable = UserMappingTable.create(
			featureTable + "_" + tileTable, additionalMappingColumns);
	ExtendedRelation relation = relatedTables.addTilesRelationship(
			featureTable, tileTable, userMappingTable);

	UserMappingDao userMappingDao = relatedTables.getMappingDao(relation);

	FeatureDao featureDao = geoPackage
			.getFeatureDao(relation.getBaseTableName());
	TileDao tileDao = geoPackage.getTileDao(relation.getRelatedTableName());

	FeatureResultSet featureResultSet = featureDao.queryForAll();
	while (featureResultSet.moveToNext()) {

		FeatureRow featureRow = featureResultSet.getRow();
		String featureName = featureRow.getValue(TEXT_COLUMN).toString();

		TileResultSet tileResultSet = tileDao
				.queryForTile(tileDao.getMinZoom());
		while (tileResultSet.moveToNext()) {

			TileRow tileRow = tileResultSet.getRow();

			UserMappingRow userMappingRow = userMappingDao.newRow();
			userMappingRow.setBaseId(featureRow.getId());
			userMappingRow.setRelatedId(tileRow.getId());
			RelatedTablesUtils.populateUserRow(userMappingDao.getTable(),
					userMappingRow, UserMappingTable.requiredColumns());
			DublinCoreMetadata.setValue(userMappingRow,
					DublinCoreType.TITLE, featureName);
			DublinCoreMetadata.setValue(userMappingRow,
					DublinCoreType.DESCRIPTION, featureName);
			DublinCoreMetadata.setValue(userMappingRow,
					DublinCoreType.SOURCE, featureName);
			userMappingDao.create(userMappingRow);
		}
		tileResultSet.close();

	}
	featureResultSet.close();

}
 
Example #22
Source File: GeoPackageExtensions.java    From geopackage-core-java with MIT License 4 votes vote down vote up
/**
 * Copy the Schema extensions for the table
 * 
 * @param geoPackage
 *            GeoPackage
 * @param table
 *            table name
 * @param newTable
 *            new table name
 * @since 3.3.0
 */
public static void copySchema(GeoPackageCore geoPackage, String table,
		String newTable) {

	try {

		if (geoPackage.isTable(DataColumns.TABLE_NAME)) {

			UserCustomTable dataColumnsTable = UserCustomTableReader
					.readTable(geoPackage.getDatabase(),
							DataColumns.TABLE_NAME);
			UserCustomColumn nameColumn = dataColumnsTable
					.getColumn(DataColumns.COLUMN_NAME);
			if (nameColumn.hasConstraints()) {
				nameColumn.clearConstraints();
				if (dataColumnsTable.hasConstraints()) {
					dataColumnsTable.clearConstraints();
					String constraintSql = GeoPackageTableCreator
							.readSQLScript(
									GeoPackageTableCreator.DATA_COLUMNS)
							.get(0);
					TableConstraints constraints = ConstraintParser
							.getConstraints(constraintSql);
					dataColumnsTable.addConstraints(
							constraints.getTableConstraints());
				}
				AlterTable.alterColumn(geoPackage.getDatabase(),
						dataColumnsTable, nameColumn);
			}

			CoreSQLUtils.transferTableContent(geoPackage.getDatabase(),
					DataColumns.TABLE_NAME, DataColumns.COLUMN_TABLE_NAME,
					newTable, table);

		}

	} catch (Exception e) {
		logger.log(Level.WARNING, "Failed to create Schema for table: "
				+ newTable + ", copied from table: " + table, e);
	}

}
 
Example #23
Source File: RelatedTablesUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Populate the user row additional column values
 * 
 * @param userTable
 *            user custom table
 * @param userRow
 *            user custom row
 * @param skipColumns
 *            columns to skip populating
 */
public static void populateUserRow(UserCustomTable userTable,
		UserCustomRow userRow, List<String> skipColumns) {

	Set<String> skipColumnsSet = new HashSet<>(skipColumns);

	for (UserCustomColumn column : userTable.getColumns()) {
		if (!skipColumnsSet.contains(column.getName())) {

			// Leave nullable columns null 20% of the time
			if (!column.isNotNull()
					&& DublinCoreType.fromName(column.getName()) == null) {
				if (Math.random() < 0.2) {
					continue;
				}
			}

			Object value = null;

			switch (column.getDataType()) {

			case TEXT:
				String text = UUID.randomUUID().toString();
				if (column.getMax() != null
						&& text.length() > column.getMax()) {
					text = text.substring(0, column.getMax().intValue());
				}
				value = text;
				break;
			case REAL:
			case DOUBLE:
				value = Math.random() * 5000.0;
				break;
			case BOOLEAN:
				value = Math.random() < .5 ? false : true;
				break;
			case INTEGER:
			case INT:
				value = (int) (Math.random() * 500);
				break;
			case BLOB:
				byte[] blob = UUID.randomUUID().toString().getBytes();
				if (column.getMax() != null
						&& blob.length > column.getMax()) {
					byte[] blobLimited = new byte[column.getMax()
							.intValue()];
					ByteBuffer.wrap(blob, 0, column.getMax().intValue())
							.get(blobLimited);
					blob = blobLimited;
				}
				value = blob;
				break;
			case DATE:
			case DATETIME:
				DateConverter converter = DateConverter.converter(column
						.getDataType());
				Date date = new Date();
				if (Math.random() < .5) {
					value = date;
				} else {
					value = converter.stringValue(date);
				}
				break;
			default:
				throw new UnsupportedOperationException(
						"Not implemented for data type: "
								+ column.getDataType());
			}

			userRow.setValue(column.getName(), value);

		}
	}
}
 
Example #24
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 #25
Source File: SimpleAttributesTable.java    From geopackage-core-java with MIT License 3 votes vote down vote up
/**
 * Constructor
 * 
 * @param tableName
 *            table name
 * @param columns
 *            list of columns
 * @param idColumnName
 *            id column name
 */
protected SimpleAttributesTable(String tableName,
		List<UserCustomColumn> columns, String idColumnName) {
	super(tableName, RELATION_TYPE.getName(), RELATION_TYPE.getDataType(),
			columns, requiredColumns(idColumnName));
	validateColumns();
}
 
Example #26
Source File: UserRelatedTable.java    From geopackage-core-java with MIT License 3 votes vote down vote up
/**
 * Constructor
 * 
 * @param tableName
 *            table name
 * @param relationName
 *            relation name
 * @param dataType
 *            contents data type
 * @param columns
 *            list of columns
 * @param requiredColumns
 *            list of required columns
 * @since 3.1.0
 */
public UserRelatedTable(String tableName, String relationName,
		String dataType, List<UserCustomColumn> columns,
		Collection<String> requiredColumns) {
	super(tableName, columns, requiredColumns);
	this.relationName = relationName;
	this.dataType = dataType;
}
 
Example #27
Source File: AlterTable.java    From geopackage-core-java with MIT License 3 votes vote down vote up
/**
 * Alter columns
 * 
 * @param db
 *            connection
 * @param tableName
 *            table name
 * @param columns
 *            columns
 * @param <T>
 *            user column type
 */
public static <T extends UserColumn> void alterColumns(
		GeoPackageCoreConnection db, String tableName,
		Collection<UserCustomColumn> columns) {
	UserCustomTable userTable = UserCustomTableReader.readTable(db,
			tableName);
	alterColumns(db, userTable, columns);
}
 
Example #28
Source File: IconRow.java    From geopackage-java with MIT License 2 votes vote down vote up
/**
 * Get the name column
 * 
 * @return name column
 */
public UserCustomColumn getNameColumn() {
	return getColumns().getColumn(IconTable.COLUMN_NAME);
}
 
Example #29
Source File: MediaTable.java    From geopackage-core-java with MIT License 2 votes vote down vote up
/**
 * Constructor
 * 
 * @param tableName
 *            table name
 * @param columns
 *            list of columns
 * @param idColumnName
 *            id column name
 */
protected MediaTable(String tableName, List<UserCustomColumn> columns,
		String idColumnName) {
	super(tableName, RELATION_TYPE.getName(), RELATION_TYPE.getDataType(),
			columns, requiredColumns(idColumnName));
}
 
Example #30
Source File: MediaTable.java    From geopackage-core-java with MIT License 2 votes vote down vote up
/**
 * Create a content type column
 * 
 * @param index
 *            column index
 * @return content type column
 */
public static UserCustomColumn createContentTypeColumn(int index) {
	return UserCustomColumn.createColumn(index, COLUMN_CONTENT_TYPE,
			GeoPackageDataType.TEXT, true);
}