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);
}
}
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));
}
}
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();
}
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(", ");
}
}
}
}
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;
}
Aggregations