Search in sources :

Example 1 with PrimaryKey

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);
}
Also used : ValueList(eu.esdihumboldt.hale.common.core.io.ValueList) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Value(eu.esdihumboldt.hale.common.core.io.Value) PrimaryKey(eu.esdihumboldt.hale.common.schema.model.constraint.type.PrimaryKey)

Example 2 with PrimaryKey

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;
}
Also used : DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) UserColumn(mil.nga.geopackage.user.UserColumn) DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) QName(javax.xml.namespace.QName) PrimaryKey(eu.esdihumboldt.hale.common.schema.model.constraint.type.PrimaryKey) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Aggregations

PrimaryKey (eu.esdihumboldt.hale.common.schema.model.constraint.type.PrimaryKey)2 QName (javax.xml.namespace.QName)2 Value (eu.esdihumboldt.hale.common.core.io.Value)1 ValueList (eu.esdihumboldt.hale.common.core.io.ValueList)1 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)1 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)1 DefaultPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition)1 DefaultTypeDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)1 ArrayList (java.util.ArrayList)1 UserColumn (mil.nga.geopackage.user.UserColumn)1 LineString (org.locationtech.jts.geom.LineString)1 MultiLineString (org.locationtech.jts.geom.MultiLineString)1