mil.nga.geopackage.db.table.Constraint Java Examples

The following examples show how to use mil.nga.geopackage.db.table.Constraint. 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: GeoPackageCoreImpl.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public AttributesTable createAttributesTable(String tableName,
		String idColumnName, List<AttributesColumn> additionalColumns,
		Collection<Constraint> constraints) {

	if (idColumnName == null) {
		idColumnName = "id";
	}

	List<AttributesColumn> columns = new ArrayList<AttributesColumn>();
	columns.add(AttributesColumn.createPrimaryKeyColumn(idColumnName));

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

	return createAttributesTable(tableName, columns, constraints);
}
 
Example #2
Source File: CoreSQLUtils.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * Create the column definition SQL in the format:
 * 
 * column_type[(max)] [NOT NULL] [PRIMARY KEY AUTOINCREMENT]
 * 
 * @param column
 *            user column
 * @return column definition SQL
 * @since 3.3.0
 */
public static String columnDefinition(UserColumn column) {

	StringBuilder sql = new StringBuilder();

	sql.append(column.getType());

	if (column.hasMax()) {
		sql.append("(").append(column.getMax()).append(")");
	}

	for (Constraint constraint : column.getConstraints()) {
		sql.append(" ");
		sql.append(constraint.buildSql());
	}

	return sql.toString();
}
 
Example #3
Source File: GeoPackageCoreImpl.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public AttributesTable createAttributesTableWithId(String tableName,
		List<AttributesColumn> additionalColumns,
		Collection<Constraint> constraints) {
	return createAttributesTable(tableName, null, additionalColumns,
			constraints);
}
 
Example #4
Source File: UserTable.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Copy Constructor
 * 
 * @param userTable
 *            user table
 * @since 3.3.0
 */
protected UserTable(UserTable<TColumn> userTable) {
	this.columns = userTable.columns.copy();
	constraints = new ArrayList<>();
	typedContraints = new HashMap<>();
	for (Constraint constraint : userTable.constraints) {
		addConstraint(constraint.copy());
	}
	this.contents = userTable.contents;
}
 
Example #5
Source File: UserTable.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Add constraint
 * 
 * @param constraint
 *            constraint
 * @since 3.3.0
 */
public void addConstraint(Constraint constraint) {
	constraints.add(constraint);
	List<Constraint> typeConstraints = typedContraints
			.get(constraint.getType());
	if (typeConstraints == null) {
		typeConstraints = new ArrayList<>();
		typedContraints.put(constraint.getType(), typeConstraints);
	}
	typeConstraints.add(constraint);
}
 
Example #6
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 #7
Source File: UserTable.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Clear the constraints
 * 
 * @return cleared constraints
 * @since 3.3.0
 */
public List<Constraint> clearConstraints() {
	List<Constraint> constraintsCopy = new ArrayList<>(constraints);
	constraints.clear();
	typedContraints.clear();
	return constraintsCopy;
}
 
Example #8
Source File: CoreSQLUtils.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Create the user defined table SQL
 * 
 * @param table
 *            user table
 * @param <TColumn>
 *            column type
 * @return create table SQL
 * @since 3.3.0
 */
public static <TColumn extends UserColumn> String createTableSQL(
		UserTable<TColumn> table) {

	// Build the create table sql
	StringBuilder sql = new StringBuilder();
	sql.append("CREATE TABLE ")
			.append(CoreSQLUtils.quoteWrap(table.getTableName()))
			.append(" (");

	// Add each column to the sql
	List<? extends UserColumn> columns = table.getColumns();
	for (int i = 0; i < columns.size(); i++) {
		UserColumn column = columns.get(i);
		if (i > 0) {
			sql.append(",");
		}
		sql.append("\n  ");
		sql.append(CoreSQLUtils.columnSQL(column));
	}

	// Add unique constraints
	for (Constraint constraint : table.getConstraints()) {
		sql.append(",\n  ");
		sql.append(constraint.buildSql());
	}

	sql.append("\n);");

	return sql.toString();
}
 
Example #9
Source File: UserTable.java    From geopackage-core-java with MIT License 3 votes vote down vote up
/**
 * Get the constraints of the provided type
 * 
 * @param type
 *            constraint type
 * @return constraints
 * @since 3.3.0
 */
public List<Constraint> getConstraints(ConstraintType type) {
	List<Constraint> constraints = typedContraints.get(type);
	if (constraints == null) {
		constraints = new ArrayList<>();
	}
	return constraints;
}
 
Example #10
Source File: GeoPackageCore.java    From geopackage-core-java with MIT License 2 votes vote down vote up
/**
 * Create a new attributes table and a new Contents
 * 
 * The attributes table will be created with columns.size() columns and must
 * include an integer id column
 * 
 * @param tableName
 *            table name
 * @param columns
 *            table columns to create
 * @param constraints
 *            constraints
 * @return attributes table
 * @since 3.3.0
 */
public AttributesTable createAttributesTable(String tableName,
		List<AttributesColumn> columns, Collection<Constraint> constraints);
 
Example #11
Source File: GeoPackageCore.java    From geopackage-core-java with MIT License 2 votes vote down vote up
/**
 * Create a new attributes table and a new Contents
 * 
 * The attributes table will be created with 1 + additionalColumns.size()
 * columns, an id column with the provided name and the provided additional
 * columns.
 * 
 * @param tableName
 *            table name
 * @param idColumnName
 *            id column name
 * @param additionalColumns
 *            additional attributes table columns to create in addition to
 *            id
 * @param constraints
 *            constraints
 * @return attributes table
 * @since 3.3.0
 */
public AttributesTable createAttributesTable(String tableName,
		String idColumnName, List<AttributesColumn> additionalColumns,
		Collection<Constraint> constraints);
 
Example #12
Source File: GeoPackageCore.java    From geopackage-core-java with MIT License 2 votes vote down vote up
/**
 * Create a new attributes table and a new Contents
 * 
 * The attributes table will be created with 1 + additionalColumns.size()
 * columns, an id column named "id" and the provided additional columns.
 * 
 * @param tableName
 *            table name
 * @param additionalColumns
 *            additional attributes table columns to create in addition to
 *            id
 * @param constraints
 *            constraints
 * @return attributes table
 * @since 3.3.0
 */
public AttributesTable createAttributesTableWithId(String tableName,
		List<AttributesColumn> additionalColumns,
		Collection<Constraint> constraints);
 
Example #13
Source File: UserColumn.java    From geopackage-core-java with MIT License 2 votes vote down vote up
/**
 * Add constraints
 * 
 * @param constraints
 *            constraints
 * @since 3.3.0
 */
public void addConstraints(Collection<Constraint> constraints) {
	for (Constraint constraint : constraints) {
		addConstraint(constraint);
	}
}
 
Example #14
Source File: UserColumn.java    From geopackage-core-java with MIT License 2 votes vote down vote up
/**
 * Add a constraint
 * 
 * @param constraint
 *            constraint
 * @since 3.3.0
 */
public void addConstraint(Constraint constraint) {
	constraints.add(constraint);
}
 
Example #15
Source File: UserColumn.java    From geopackage-core-java with MIT License 2 votes vote down vote up
/**
 * Clear the constraints
 * 
 * @return cleared constraints
 * @since 3.3.0
 */
public List<Constraint> clearConstraints() {
	List<Constraint> constraintsCopy = new ArrayList<>(constraints);
	constraints.clear();
	return constraintsCopy;
}
 
Example #16
Source File: UserColumn.java    From geopackage-core-java with MIT License 2 votes vote down vote up
/**
 * Get the constraints
 * 
 * @return constraints
 * @since 3.3.0
 */
public List<Constraint> getConstraints() {
	return constraints;
}
 
Example #17
Source File: UserTable.java    From geopackage-core-java with MIT License 2 votes vote down vote up
/**
 * Get the constraints
 * 
 * @return constraints
 * @since 3.3.0
 */
public List<Constraint> getConstraints() {
	return constraints;
}
 
Example #18
Source File: UserTable.java    From geopackage-core-java with MIT License 2 votes vote down vote up
/**
 * Add constraints
 * 
 * @param constraints
 *            constraints
 * @since 3.3.0
 */
public void addConstraints(Collection<Constraint> constraints) {
	for (Constraint constraint : constraints) {
		addConstraint(constraint);
	}
}