Search in sources :

Example 1 with AggregateCollectionMapping

use of org.eclipse.persistence.mappings.AggregateCollectionMapping in project eclipselink by eclipse-ee4j.

the class ConverterAccessor method process.

/**
 * INTERNAL:
 * Process this converter for the given mapping.
 */
public void process(DatabaseMapping mapping, boolean isForMapKey, String attributeName, boolean disableConversion) {
    ConverterClass converterClass = new ConverterClass(getJavaClassName(), isForMapKey, fieldClassification.getName(), disableConversion);
    converterClass.setSession(getProject().getSession());
    if (mapping.isDirectMapMapping() && isForMapKey) {
        ((DirectMapMapping) mapping).setKeyConverter(converterClass);
    } else if (mapping.isDirectCollectionMapping()) {
        ((DirectCollectionMapping) mapping).setValueConverter(converterClass);
    } else if (mapping.isDirectToFieldMapping()) {
        ((AbstractDirectMapping) mapping).setConverter(converterClass);
    } else if (mapping.isAggregateObjectMapping()) {
        ((AggregateObjectMapping) mapping).addConverter(converterClass, attributeName);
    } else if (mapping.isAggregateCollectionMapping()) {
        ((AggregateCollectionMapping) mapping).addConverter(converterClass, attributeName);
    }
}
Also used : AbstractDirectMapping(org.eclipse.persistence.mappings.foundation.AbstractDirectMapping) AggregateCollectionMapping(org.eclipse.persistence.mappings.AggregateCollectionMapping) ConverterClass(org.eclipse.persistence.mappings.converters.ConverterClass) DirectMapMapping(org.eclipse.persistence.mappings.DirectMapMapping)

Example 2 with AggregateCollectionMapping

use of org.eclipse.persistence.mappings.AggregateCollectionMapping in project eclipselink by eclipse-ee4j.

the class ElementCollectionAccessor method processDirectEmbeddableCollectionMapping.

/**
 * INTERNAL:
 */
protected void processDirectEmbeddableCollectionMapping(MetadataDescriptor referenceDescriptor) {
    // Initialize our mapping.
    DatabaseMapping mapping = getOwningDescriptor().getClassDescriptor().newAggregateCollectionMapping();
    // Process common direct collection metadata. This must be done
    // before any field processing since field processing requires that
    // the collection table be processed before hand.
    process(mapping);
    // Make sure to mark the descriptor as an embeddable collection descriptor.
    referenceDescriptor.setIsEmbeddable();
    processContainerPolicyAndIndirection((ContainerMapping) mapping);
    if (mapping instanceof AggregateCollectionMapping) {
        AggregateCollectionMapping collectionMapping = (AggregateCollectionMapping) mapping;
        // Process the fetch type and set the correct indirection on the mapping.
        // Process the mappings from the embeddable to setup the field name
        // translations. Before we do that lets process the attribute and
        // association overrides that are available to us and that may be used
        // to override any field name translations.
        processMappingsFromEmbeddable(referenceDescriptor, null, collectionMapping, getAttributeOverrides(m_attributeOverrides), getAssociationOverrides(m_associationOverrides), "");
        processMappingValueConverters(getDescriptor());
    } else if (mapping.isAbstractCompositeCollectionMapping()) {
        ((AbstractCompositeCollectionMapping) mapping).setField(getDatabaseField(getDescriptor().getPrimaryTable(), MetadataLogger.COLUMN));
    }
}
Also used : AggregateCollectionMapping(org.eclipse.persistence.mappings.AggregateCollectionMapping) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping)

Example 3 with AggregateCollectionMapping

use of org.eclipse.persistence.mappings.AggregateCollectionMapping in project eclipselink by eclipse-ee4j.

the class TestUpdateEntityAggregateMapMapping method setup.

@Override
public void setup() {
    AggregateCollectionMapping mapping = (AggregateCollectionMapping) getSession().getProject().getDescriptor(EntityAggregateMapHolder.class).getMappingForAttributeName("entityToAggregateMap");
    keyMapping = (ForeignReferenceMapping) ((MappedKeyMapContainerPolicy) mapping.getContainerPolicy()).getKeyMapping();
    oldKeyPrivateOwnedValue = keyMapping.isPrivateOwned();
    keyMapping.setIsPrivateOwned(usePrivateOwned);
    super.setup();
}
Also used : AggregateCollectionMapping(org.eclipse.persistence.mappings.AggregateCollectionMapping) MappedKeyMapContainerPolicy(org.eclipse.persistence.internal.queries.MappedKeyMapContainerPolicy)

Example 4 with AggregateCollectionMapping

use of org.eclipse.persistence.mappings.AggregateCollectionMapping in project eclipselink by eclipse-ee4j.

the class SQLSelectStatement method appendHierarchicalQueryClauseToWriter.

/**
 * This method will append the Hierarchical Query Clause to the end of the
 * select statement
 */
public void appendHierarchicalQueryClauseToWriter(ExpressionSQLPrinter printer) throws IOException {
    Expression startWith = getStartWithExpression();
    Expression connectBy = getConnectByExpression();
    List<Expression> orderSiblingsBy = getOrderSiblingsByExpressions();
    // Create the START WITH CLAUSE
    if (startWith != null) {
        printer.getWriter().write(" START WITH ");
        startWith.printSQL(printer);
    }
    if (connectBy != null) {
        if (!connectBy.isQueryKeyExpression()) {
            throw QueryException.illFormedExpression(connectBy);
        }
        printer.getWriter().write(" CONNECT BY ");
        DatabaseMapping mapping = ((QueryKeyExpression) connectBy).getMapping();
        ClassDescriptor descriptor = mapping.getDescriptor();
        // only works for these kinds of mappings. The data isn't hierarchical otherwise
        // Should also check that the source class and target class are the same.
        Map<DatabaseField, DatabaseField> foreignKeys = null;
        if (mapping.isOneToManyMapping()) {
            OneToManyMapping otm = (OneToManyMapping) mapping;
            foreignKeys = otm.getTargetForeignKeysToSourceKeys();
        } else if (mapping.isOneToOneMapping()) {
            OneToOneMapping oto = (OneToOneMapping) mapping;
            foreignKeys = oto.getSourceToTargetKeyFields();
        } else if (mapping.isAggregateCollectionMapping()) {
            AggregateCollectionMapping acm = (AggregateCollectionMapping) mapping;
            foreignKeys = acm.getTargetForeignKeyToSourceKeys();
        } else {
            throw QueryException.invalidQueryKeyInExpression(connectBy);
        }
        DatabaseTable defaultTable = descriptor.getDefaultTable();
        String tableName = "";
        // determine which table name to use
        if (requiresAliases()) {
            tableName = getBuilder().aliasForTable(defaultTable).getName();
        } else {
            tableName = defaultTable.getNameDelimited(printer.getPlatform());
        }
        if ((foreignKeys != null) && !foreignKeys.isEmpty()) {
            // get the source and target fields.
            Iterator<DatabaseField> sourceKeys = foreignKeys.keySet().iterator();
            // only one, use the simplest version without ugly bracets
            if (foreignKeys.size() > 1) {
                printer.getWriter().write("((");
            }
            DatabaseField source = sourceKeys.next();
            DatabaseField target = foreignKeys.get(source);
            ReadAllQuery.Direction direction = getDirection() != null ? getDirection() : ReadAllQuery.Direction.getDefault(mapping);
            if (direction == CHILD_TO_PARENT) {
                printer.getWriter().write("PRIOR " + tableName + "." + source.getNameDelimited(printer.getPlatform()));
                printer.getWriter().write(" = " + tableName + "." + target.getNameDelimited(printer.getPlatform()));
            } else {
                printer.getWriter().write(tableName + "." + source.getNameDelimited(printer.getPlatform()));
                printer.getWriter().write(" = PRIOR " + tableName + "." + target.getNameDelimited(printer.getPlatform()));
            }
            while (sourceKeys.hasNext()) {
                printer.getWriter().write(") AND (");
                source = sourceKeys.next();
                target = foreignKeys.get(source);
                if (direction == CHILD_TO_PARENT) {
                    printer.getWriter().write("PRIOR " + tableName + "." + source.getNameDelimited(printer.getPlatform()));
                    printer.getWriter().write(" = " + tableName + "." + target.getNameDelimited(printer.getPlatform()));
                } else {
                    printer.getWriter().write(tableName + "." + source.getNameDelimited(printer.getPlatform()));
                    printer.getWriter().write(" = PRIOR " + tableName + "." + target.getNameDelimited(printer.getPlatform()));
                }
            }
            if (foreignKeys.size() > 1) {
                printer.getWriter().write("))");
            }
        }
    }
    if ((orderSiblingsBy != null) && !orderSiblingsBy.isEmpty()) {
        printer.getWriter().write(" ORDER SIBLINGS BY ");
        for (Iterator<Expression> iterator = orderSiblingsBy.iterator(); iterator.hasNext(); ) {
            Expression expression = iterator.next();
            expression.printSQL(printer);
            if (iterator.hasNext()) {
                printer.getWriter().write(", ");
            }
        }
    }
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) OneToManyMapping(org.eclipse.persistence.mappings.OneToManyMapping) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) AggregateCollectionMapping(org.eclipse.persistence.mappings.AggregateCollectionMapping) Expression(org.eclipse.persistence.expressions.Expression) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) DecoratedDatabaseTable(org.eclipse.persistence.internal.history.DecoratedDatabaseTable) DatabaseTable(org.eclipse.persistence.internal.helper.DatabaseTable) OneToOneMapping(org.eclipse.persistence.mappings.OneToOneMapping)

Example 5 with AggregateCollectionMapping

use of org.eclipse.persistence.mappings.AggregateCollectionMapping in project eclipselink by eclipse-ee4j.

the class AgentBuilderTablesTest method verifyDescriptorWithAggColMappingsAndChildren.

String verifyDescriptorWithAggColMappingsAndChildren(ClassDescriptor desc, boolean tableNameShouldStartWithBuilder, String attributeName) {
    String localErrorMsg = verifyDescriptorWithChildren(desc, tableNameShouldStartWithBuilder, attributeName);
    boolean hasAggregateCollectionMapping = false;
    Iterator<DatabaseMapping> itMappings = desc.getMappings().iterator();
    while (itMappings.hasNext()) {
        DatabaseMapping mapping = itMappings.next();
        if (mapping.isAggregateCollectionMapping()) {
            AggregateCollectionMapping acMapping = (AggregateCollectionMapping) mapping;
            localErrorMsg += verifyDescriptorWithAggColMappingsAndChildren(acMapping.getReferenceDescriptor(), tableNameShouldStartWithBuilder, attributeName + "." + acMapping.getAttributeName());
        }
    }
    return localErrorMsg;
}
Also used : AggregateCollectionMapping(org.eclipse.persistence.mappings.AggregateCollectionMapping) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping)

Aggregations

AggregateCollectionMapping (org.eclipse.persistence.mappings.AggregateCollectionMapping)10 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)6 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)4 OneToOneMapping (org.eclipse.persistence.mappings.OneToOneMapping)4 Vector (java.util.Vector)3 ManyToManyMapping (org.eclipse.persistence.mappings.ManyToManyMapping)3 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)2 DatabaseTable (org.eclipse.persistence.internal.helper.DatabaseTable)2 NonSynchronizedVector (org.eclipse.persistence.internal.helper.NonSynchronizedVector)2 DirectMapMapping (org.eclipse.persistence.mappings.DirectMapMapping)2 RelationTableMechanism (org.eclipse.persistence.mappings.RelationTableMechanism)2 JoinTable (com.blazebit.persistence.spi.JoinTable)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 EclipseLinkException (org.eclipse.persistence.exceptions.EclipseLinkException)1 Expression (org.eclipse.persistence.expressions.Expression)1 SQLDeleteAllStatementForTempTable (org.eclipse.persistence.internal.expressions.SQLDeleteAllStatementForTempTable)1