Search in sources :

Example 11 with DefaultPropertyDefinition

use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition in project hale by halestudio.

the class JDBCSchemaReader method getOrCreateProperty.

/**
 * Gets or creates a property definition for the given column. Its type
 * definition is created, too, if necessary.
 *
 * @param schema the schema the table belongs to
 * @param tableType the type definition of the parent table this column
 *            belongs too
 * @param column the column to get or create a property definition for
 * @param overallNamespace the database namespace
 * @param namespace the schema namespace
 * @param typeIndex the type index
 * @param connection the database connection
 * @param reporter the reporter
 * @param catalog the catalog for access to other column types
 * @return the property definition for the given column
 */
private DefaultPropertyDefinition getOrCreateProperty(schemacrawler.schema.Schema schema, TypeDefinition tableType, Column column, String overallNamespace, String namespace, DefaultSchema typeIndex, Connection connection, IOReporter reporter, Catalog catalog) {
    QName name = new QName(unquote(column.getName()));
    // check for existing property definition
    ChildDefinition<?> existing = tableType.getChild(name);
    if (existing != null) {
        return (DefaultPropertyDefinition) existing;
    }
    // create new one
    // determine the column type
    TypeDefinition columnType = getOrCreateColumnType(column, overallNamespace, typeIndex, connection, tableType, reporter, catalog);
    SQLArray arrayInfo = columnType.getConstraint(SQLArray.class);
    // create the property
    DefaultPropertyDefinition property = new DefaultPropertyDefinition(name, tableType, columnType);
    // configure property
    if (column.getRemarks() != null && !column.getRemarks().isEmpty()) {
        property.setDescription(column.getRemarks());
    }
    property.setConstraint(NillableFlag.get(column.isNullable()));
    // XXX Default value is read as string from the meta data.
    // This is probably not really a problem, but should be noted!
    // XXX In particular the default value can be a function call like for
    // example GETDATE().
    String defaultValue = column.getDefaultValue();
    if (arrayInfo.isArray() && arrayInfo.getDimension() <= 1) {
        // dimension is not known (0)
        if (!arrayInfo.hasSize(0)) {
            property.setConstraint(Cardinality.CC_ANY_NUMBER);
        } else {
            // XXX what is appropriate as minimum?
            long min = 0;
            long max = arrayInfo.getSize(0);
            property.setConstraint(Cardinality.get(min, max));
        }
    } else if (defaultValue != null) {
        property.setConstraint(new DefaultValue(defaultValue));
        property.setConstraint(Cardinality.CC_OPTIONAL);
    } else
        property.setConstraint(Cardinality.CC_EXACTLY_ONCE);
    // incremented or not
    if (column.isAutoIncremented()) {
        property.setConstraint(AutoGenerated.get(true));
    } else {
        property.setConstraint(AutoGenerated.get(false));
    }
    // since they can have multiple columns
    if (column.isPartOfForeignKey()) {
        Column referenced = column.getReferencedColumn();
        // StackOverFlow exception.
        if (!(referenced.getParent().equals(column.getParent()) && referenced.equals(column))) {
            // Referenced table can be in different schema.
            // creation of referenced column's table should not be with same
            // Schema or Namespace. It should be with referenced table's
            // Schema and namespace.
            String referencedNameSpace = getReferencedTableNamespace(referenced.getParent(), overallNamespace);
            property.setConstraint(new Reference(getOrCreateTableType(referenced.getParent().getSchema(), referenced.getParent(), overallNamespace, referencedNameSpace, typeIndex, connection, reporter, catalog)));
        }
    }
    return property;
}
Also used : DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) DefaultValue(eu.esdihumboldt.hale.io.jdbc.constraints.DefaultValue) ResultsColumn(schemacrawler.schema.ResultsColumn) Column(schemacrawler.schema.Column) BaseColumn(schemacrawler.schema.BaseColumn) IndexColumn(schemacrawler.schema.IndexColumn) QName(javax.xml.namespace.QName) Reference(eu.esdihumboldt.hale.common.schema.model.constraint.property.Reference) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) SQLArray(eu.esdihumboldt.hale.io.jdbc.constraints.SQLArray)

Example 12 with DefaultPropertyDefinition

use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition in project hale by halestudio.

the class SQLSchemaReader method getOrCreateProperty.

/**
 * Gets or creates a property definition for the given column. Its type
 * definition is created, too, if necessary.
 *
 * @param tableType the type definition of the parent table this column
 *            belongs too
 * @param column the column to get or create a property definition for
 * @param namespace the schema namespace
 * @param typeIndex the type index
 * @param connection the database connection
 * @param reporter the reporter
 * @param catalog the database information
 * @return the property definition for the given column
 */
private DefaultPropertyDefinition getOrCreateProperty(TypeDefinition tableType, ResultsColumn column, String namespace, DefaultSchema typeIndex, Connection connection, IOReporter reporter, Catalog catalog) {
    QName name = new QName(unquote(column.getName()));
    // check for existing property definition
    ChildDefinition<?> existing = tableType.getChild(name);
    if (existing != null)
        return (DefaultPropertyDefinition) existing;
    // create new one
    // determine the column type
    TypeDefinition columnType = JDBCSchemaReader.getOrCreateColumnType(column, namespace, typeIndex, connection, tableType, reporter, catalog);
    SQLArray arrayInfo = columnType.getConstraint(SQLArray.class);
    // create the property
    DefaultPropertyDefinition property = new DefaultPropertyDefinition(name, tableType, columnType);
    // configure property
    if (column.getRemarks() != null && !column.getRemarks().isEmpty()) {
        property.setDescription(column.getRemarks());
    }
    property.setConstraint(NillableFlag.get(column.isNullable()));
    if (arrayInfo.isArray() && arrayInfo.getDimension() <= 1) {
        // dimension is not known (0)
        if (!arrayInfo.hasSize(0)) {
            property.setConstraint(Cardinality.CC_ANY_NUMBER);
        } else {
            // XXX what is appropriate as minimum?
            long min = 0;
            long max = arrayInfo.getSize(0);
            property.setConstraint(Cardinality.get(min, max));
        }
    } else {
        property.setConstraint(Cardinality.CC_EXACTLY_ONCE);
    }
    return property;
}
Also used : DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) QName(javax.xml.namespace.QName) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) SQLArray(eu.esdihumboldt.hale.io.jdbc.constraints.SQLArray)

Example 13 with DefaultPropertyDefinition

use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition in project hale by halestudio.

the class PropertyFunctionScriptPage method createDummyEntity.

private EntityDefinition createDummyEntity(DefaultCustomPropertyFunctionEntity entity, SchemaSpaceID ssid) {
    DefaultTypeDefinition parent = new DefaultTypeDefinition(new QName("dummy"));
    DefaultPropertyDefinition property = new DefaultPropertyDefinition(new QName(entity.getName()), parent, createDummyType(entity));
    property.setConstraint(Cardinality.get(entity.getMinOccurrence(), entity.getMaxOccurrence()));
    return new PropertyEntityDefinition(parent, Collections.singletonList(new ChildContext(property)), ssid, null);
}
Also used : DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) QName(javax.xml.namespace.QName) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext)

Example 14 with DefaultPropertyDefinition

use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition in project hale by halestudio.

the class CQLFilterDialogFactory method openDialog.

@Override
public Filter openDialog(Shell shell, EntityDefinition entityDef, String title, String message) {
    TypeEntityDefinition parentType;
    if (entityDef.getPropertyPath().isEmpty())
        parentType = AlignmentUtil.getTypeEntity(entityDef);
    else {
        Definition<?> def = entityDef.getDefinition();
        TypeDefinition propertyType = ((PropertyDefinition) def).getPropertyType();
        // create a dummy type for the filter
        TypeDefinition dummyType = new DefaultTypeDefinition(new QName("ValueFilterDummy"));
        // create dummy type entity
        Condition condition = AlignmentUtil.getContextCondition(entityDef);
        Filter filter = condition == null ? null : condition.getFilter();
        parentType = new TypeEntityDefinition(dummyType, entityDef.getSchemaSpace(), filter);
        // with the property type being contained as value
        // property
        new DefaultPropertyDefinition(new QName("value"), dummyType, propertyType);
        // and the parent type as parent property
        new DefaultPropertyDefinition(new QName("parent"), dummyType, ((PropertyDefinition) def).getParentType());
    }
    CQLFilterDialog dialog = new CQLFilterDialog(shell, parentType, title, message);
    if (dialog.open() == CQLFilterDialog.OK) {
        return dialog.getFilter();
    }
    return null;
}
Also used : DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) Condition(eu.esdihumboldt.hale.common.align.model.Condition) DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) Filter(eu.esdihumboldt.hale.common.instance.model.Filter) QName(javax.xml.namespace.QName) DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)

Example 15 with DefaultPropertyDefinition

use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition in project hale by halestudio.

the class CustomTypeContentHelper method applyElementsMode.

private static void applyElementsMode(PropertyDefinition propDef, DefinitionGroup propParent, CustomTypeContent config, XmlIndex index) {
    // build new property type based on config
    DefaultTypeDefinition type = new DefaultTypeDefinition(new QName(propDef.getIdentifier(), "customElementsContentType"), false);
    type.setConstraint(MappableFlag.DISABLED);
    DefaultGroupPropertyDefinition choice = new DefaultGroupPropertyDefinition(new QName(propDef.getIdentifier(), "customElementsContentChoice"), type, false);
    choice.setConstraint(new DisplayName("elements"));
    choice.setConstraint(ChoiceFlag.ENABLED);
    choice.setConstraint(Cardinality.CC_ANY_NUMBER);
    for (QName elementName : config.getElements()) {
        XmlElement element = index.getElements().get(elementName);
        if (element != null) {
            DefaultPropertyDefinition elementProp = new DefaultPropertyDefinition(elementName, choice, element.getType());
            elementProp.setConstraint(Cardinality.CC_EXACTLY_ONCE);
            elementProp.setConstraint(NillableFlag.DISABLED);
        } else {
            log.error("Element {} could not be found when creating custom type content", elementName);
        }
    }
    replaceTypeForProperty(propDef, propParent, type);
}
Also used : DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) DefaultGroupPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultGroupPropertyDefinition) QName(javax.xml.namespace.QName) DisplayName(eu.esdihumboldt.hale.common.schema.model.constraint.DisplayName) XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement)

Aggregations

DefaultPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition)20 DefaultTypeDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)18 QName (javax.xml.namespace.QName)18 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)10 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)6 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)4 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)4 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)4 DefaultSchema (eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchema)4 IOException (java.io.IOException)4 Filter (eu.esdihumboldt.hale.common.instance.model.Filter)3 MutableInstance (eu.esdihumboldt.hale.common.instance.model.MutableInstance)3 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)2 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)2 DefaultInstance (eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstance)2 DefaultGroupPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultGroupPropertyDefinition)2 PropertyType (eu.esdihumboldt.hale.io.csv.PropertyType)2 SQLArray (eu.esdihumboldt.hale.io.jdbc.constraints.SQLArray)2 XmlElement (eu.esdihumboldt.hale.io.xsd.model.XmlElement)2 AnonymousXmlType (eu.esdihumboldt.hale.io.xsd.reader.internal.AnonymousXmlType)2