Search in sources :

Example 16 with DefaultTypeDefinition

use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition 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)

Example 17 with DefaultTypeDefinition

use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition 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 18 with DefaultTypeDefinition

use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition 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 19 with DefaultTypeDefinition

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

the class JDBCSchemaReader method getOrCreateColumnType.

/**
 * Get or create the type definition for the given column.
 *
 * @param column the column
 * @param overallNamespace the database namespace
 * @param types the type index
 * @param connection the database connection
 * @param tableType the type definition of the table the column is part of
 * @param reporter the reporter
 * @param catalog the catalog for access to other column types
 * @return the type definition for the column type
 */
public static TypeDefinition getOrCreateColumnType(BaseColumn<?> column, final String overallNamespace, DefaultSchema types, Connection connection, TypeDefinition tableType, IOReporter reporter, Catalog catalog) {
    // XXX what about shared types?
    // TODO the size/width info (VARCHAR(_30_)) is in column, the
    // columntype/-name is not sufficient
    // getType();
    ColumnDataType columnType = column.getColumnDataType();
    String localName = columnType.getName();
    QName typeName = new QName(overallNamespace, localName);
    // check for geometry type
    GeometryTypeInfo geomType = GeometryTypeExtension.getInstance().getTypeInfo(columnType.getName(), connection);
    @SuppressWarnings("rawtypes") GeometryAdvisor geomAdvisor = null;
    if (geomType != null) {
        geomAdvisor = geomType.getGeometryAdvisor();
        // determine if a type specifically for this column is needed
        if (!geomAdvisor.isFixedType(columnType)) {
            // must use a specific type definition for this column
            // -> use a type name based on the column
            // new namespace is the table and column name
            String ns = tableType.getName().getNamespaceURI() + '/' + tableType.getName().getLocalPart() + '/' + unquote(column.getName());
            typeName = new QName(ns, localName);
        }
    }
    // check for existing type
    TypeDefinition existing = types.getType(typeName);
    if (existing != null)
        return existing;
    // create new type
    DefaultTypeDefinition type = new DefaultTypeDefinition(typeName);
    type.setConstraint(HasValueFlag.ENABLED);
    CustomType cust = CustomTypeExtension.getInstance().getCustomType(localName, connection);
    /*
		 * Oracle jdbc was returning sqltype -6 for NUMBER data type, but it is
		 * bound to boolean by Types.java class. Configured the sqltype 6 for
		 * NUMBER data type.
		 */
    if (cust != null) {
        type.setConstraint(SQLType.get(cust.getSQLType()));
    } else {
        type.setConstraint(SQLType.get(columnType.getJavaSqlType().getJavaSqlType()));
    }
    if (geomType != null && geomAdvisor != null) {
        // configure geometry type
        @SuppressWarnings("unchecked") Class<? extends Geometry> geomClass = geomAdvisor.configureGeometryColumnType(connection, column, type, reporter);
        type.setConstraint(GeometryType.get(geomClass));
        // always a single geometry
        type.setConstraint(Binding.get(GeometryProperty.class));
        // remember advisor for type (used in instance writer)
        type.setConstraint(geomType.getConstraint());
    } else {
        // configure type
        Class<?> binding = null;
        if (cust != null) {
            binding = cust.getBinding();
        } else {
            if (column.getColumnDataType().getJavaSqlType().getJavaSqlType() == Types.ARRAY) {
                // TODO let this be handled by a possible advisor?
                /*
					 * Special handling for arrays.
					 * 
					 * Challenges:
					 * 
					 * - find the type of contained items
					 * 
					 * - determine dimensions and size
					 */
                Class<?> elementBinding;
                // determine type/binding of contained items
                ColumnDataType cdt = column.getColumnDataType();
                ColumnDataType itemType = null;
                String dbTypeName = cdt.getDatabaseSpecificTypeName();
                // prefix and look up type
                if (dbTypeName.startsWith("_")) {
                    String testName = dbTypeName.substring(1);
                    itemType = catalog.getSystemColumnDataType(testName);
                }
                if (itemType == null) {
                    // generic binding
                    elementBinding = Object.class;
                    reporter.error(new IOMessageImpl("Could not determine element type for array column", null));
                } else {
                    elementBinding = itemType.getTypeMappedClass();
                // TODO support custom bindings?
                // XXX probably needed for Oracle?
                }
                // dimensions and size cannot be determined from schema
                // crawler it seems - would need database specific queries
                // (if the info is available at all)
                /*
					 * Postgres:
					 * 
					 * Dimensions and size are not part of the schema, they can
					 * only be determined for a value.
					 */
                // XXX for now, stick to what we can determine
                int dimension = SQLArray.UNKNOWN_DIMENSION;
                String specificTypeName = (itemType != null) ? (itemType.getDatabaseSpecificTypeName()) : (null);
                type.setConstraint(new SQLArray(elementBinding, specificTypeName, dimension, null));
                // set binding
                if (dimension <= 1) {
                    // XXX for now, use this representation also if
                    // dimension is not known
                    // 1-dimensional -> as multiple occurrences
                    binding = elementBinding;
                } else {
                    // XXX use collection or something similar instead?
                    binding = Object.class;
                }
            } else {
                binding = column.getColumnDataType().getTypeMappedClass();
            }
        }
        type.setConstraint(Binding.get(binding));
        type.setConstraint(HasValueFlag.ENABLED);
    }
    if (columnType.getRemarks() != null && !columnType.getRemarks().isEmpty())
        type.setDescription(columnType.getRemarks());
    types.addType(type);
    return type;
}
Also used : CustomType(eu.esdihumboldt.hale.io.jdbc.extension.internal.CustomType) GeometryProperty(eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty) QName(javax.xml.namespace.QName) ColumnDataType(schemacrawler.schema.ColumnDataType) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) GeometryTypeInfo(eu.esdihumboldt.hale.io.jdbc.extension.internal.GeometryTypeInfo) SQLArray(eu.esdihumboldt.hale.io.jdbc.constraints.SQLArray)

Example 20 with DefaultTypeDefinition

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

the class JDBCSchemaReader method getOrCreateTableType.

/**
 * Get or create the type definition for the given table.
 *
 * @param schema the schema in which the table exists
 * @param table the table
 * @param overallNamespace the database namespace
 * @param namespace the schema namespace
 * @param types the type index
 * @param connection the database connection
 * @param reporter the reporter
 * @param catalog the catalog for access to other column types
 * @return the type definition for the given table
 */
private TypeDefinition getOrCreateTableType(schemacrawler.schema.Schema schema, Table table, String overallNamespace, String namespace, DefaultSchema types, Connection connection, IOReporter reporter, Catalog catalog) {
    QName typeName = new QName(namespace, unquote(table.getName()));
    // check for existing type
    TypeDefinition existingType = types.getType(typeName);
    if (existingType != null)
        return existingType;
    // create new type
    DefaultTypeDefinition type = new DefaultTypeDefinition(typeName);
    // set description if available
    if (table.getRemarks() != null && !table.getRemarks().isEmpty())
        type.setDescription(table.getRemarks());
    // configure type
    type.setConstraint(MappableFlag.ENABLED);
    type.setConstraint(MappingRelevantFlag.ENABLED);
    type.setConstraint(HasValueFlag.DISABLED);
    // set schema and table name
    DatabaseTable tableConstraint = new DatabaseTable(unquote(schema.getName()), unquote(table.getName()), useQuote);
    type.setConstraint(tableConstraint);
    // set SQL query constraint
    String query = "SELECT * FROM " + tableConstraint.getFullTableName();
    type.setConstraint(new SQLQuery(query));
    // set primary key if possible
    PrimaryKey key = null;
    try {
        key = table.getPrimaryKey();
    } catch (Exception e) {
        reporter.warn(new IOMessageImpl("Could not read primary key metadata for table: " + table.getFullName(), e));
    }
    if (key != null) {
        List<IndexColumn> columns = key.getColumns();
        if (columns.size() > 1) {
            reporter.warn(new IOMessageImpl("Primary keys over multiple columns are not yet supported.", null));
        } else if (columns.size() == 1) {
            // create constraint, get property definition for original table
            // column (maybe could use index column, too)
            type.setConstraint(new eu.esdihumboldt.hale.common.schema.model.constraint.type.PrimaryKey(Collections.<QName>singletonList(getOrCreateProperty(schema, type, table.getColumn(columns.get(0).getName()), overallNamespace, namespace, types, connection, reporter, catalog).getName())));
        }
    }
    // TODO validation of constraints? Most are about several instances (i.
    // e. UNIQUE)
    types.addType(type);
    return type;
}
Also used : QName(javax.xml.namespace.QName) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) PrimaryKey(schemacrawler.schema.PrimaryKey) SQLQuery(eu.esdihumboldt.hale.io.jdbc.constraints.SQLQuery) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) SchemaCrawlerException(schemacrawler.schemacrawler.SchemaCrawlerException) SQLException(java.sql.SQLException) IOException(java.io.IOException) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) IndexColumn(schemacrawler.schema.IndexColumn) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) DatabaseTable(eu.esdihumboldt.hale.io.jdbc.constraints.DatabaseTable)

Aggregations

DefaultTypeDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)28 QName (javax.xml.namespace.QName)23 DefaultPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition)18 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)15 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)7 Filter (eu.esdihumboldt.hale.common.instance.model.Filter)5 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 DefaultGroupPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultGroupPropertyDefinition)4 DefaultSchema (eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchema)4 IOException (java.io.IOException)4 Test (org.junit.Test)4 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)3 MutableInstance (eu.esdihumboldt.hale.common.instance.model.MutableInstance)3 GeometryProperty (eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty)3 Cell (eu.esdihumboldt.hale.common.align.model.Cell)2 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)2 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)2 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)2