use of eu.esdihumboldt.hale.common.schema.model.constraint.type.PrimaryKey in project hale by halestudio.
the class PrimaryKeyFactory method restore.
@Override
public PrimaryKey restore(Value value, Definition<?> definition, TypeResolver typeIndex, ClassResolver resolver) throws Exception {
ValueList list = value.as(ValueList.class);
List<QName> names = new ArrayList<>();
for (Value val : list) {
QName name = val.as(QName.class);
if (name != null) {
names.add(name);
} else {
throw new IllegalStateException("Failed to read name for primary key path");
}
}
return new PrimaryKey(names);
}
use of eu.esdihumboldt.hale.common.schema.model.constraint.type.PrimaryKey in project hale by halestudio.
the class GeopackageSchemaBuilder method buildType.
private TypeDefinition buildType(UserDao<?, ?, ?, ?> dao, GeometryColumns geomColumns, DefaultSchema schema) {
QName name = new QName(defaultNamespace, dao.getTableName());
DefaultTypeDefinition type = new DefaultTypeDefinition(name);
type.setConstraint(MappableFlag.ENABLED);
type.setConstraint(MappingRelevantFlag.ENABLED);
type.setConstraint(HasValueFlag.DISABLED);
type.setConstraint(AbstractFlag.DISABLED);
type.setConstraint(Binding.get(Instance.class));
UserTable<? extends UserColumn> table = dao.getTable();
// set primary key constraint
UserColumn pkColumn = table.getPkColumn();
if (pkColumn != null) {
type.setConstraint(new PrimaryKey(Collections.singletonList(new QName(pkColumn.getName()))));
}
for (String columnName : table.getColumnNames()) {
UserColumn column = table.getColumn(columnName);
QName propertyName = new QName(columnName);
// determine property type
TypeDefinition propertyType = getOrCreatePropertyType(column, geomColumns, schema);
DefaultPropertyDefinition property = new DefaultPropertyDefinition(propertyName, type, propertyType);
property.setConstraint(Cardinality.CC_EXACTLY_ONCE);
if (column.isNotNull()) {
property.setConstraint(NillableFlag.DISABLED);
} else {
property.setConstraint(NillableFlag.ENABLED);
}
}
return type;
}
Aggregations