Search in sources :

Example 1 with ObjectRelationalDataTypeDescriptor

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

the class OracleHelper method addToORProjectForVArrayArg.

/**
 * Build descriptor and mappings for a VArray argument.  The newly
 * created descriptor will be added to the given OX project.
 */
protected void addToORProjectForVArrayArg(DatabaseType dbType, Project orProject, String arrayName, String arrayAlias) {
    DatabaseType nestedDbType = ((VArrayType) dbType).getEnclosedType();
    String referenceTypeAlias = getGeneratedAlias(nestedDbType.getTypeName());
    String referenceTypeName = getGeneratedJavaClassName(referenceTypeAlias, dbwsBuilder.getProjectName());
    ObjectRelationalDataTypeDescriptor ordt = (ObjectRelationalDataTypeDescriptor) orProject.getDescriptorForAlias(arrayAlias);
    if (ordt == null) {
        ordt = buildAndAddNewObjectRelationalDataTypeDescriptor(orProject, arrayAlias, arrayName + COLLECTION_WRAPPER_SUFFIX);
        // before we add this descriptor, check if the nested type's descriptor
        // should be built and added first
        ClassDescriptor refdesc = orProject.getDescriptorForAlias(referenceTypeAlias);
        if (refdesc == null) {
            if (nestedDbType.isObjectType()) {
                addToORProjectForObjectTypeArg(nestedDbType, orProject, referenceTypeName, referenceTypeAlias);
            }
        }
    }
    boolean itemsMappingFound = ordt.getMappingForAttributeName(ITEMS_MAPPING_ATTRIBUTE_NAME) == null ? false : true;
    if (!itemsMappingFound) {
        if (nestedDbType.isComposite()) {
            buildAndAddObjectArrayMapping(ordt, ITEMS_MAPPING_ATTRIBUTE_NAME, ITEMS_MAPPING_FIELD_NAME, referenceTypeName, arrayName);
        } else {
            buildAndAddArrayMapping(ordt, ITEMS_MAPPING_ATTRIBUTE_NAME, ITEMS_MAPPING_FIELD_NAME, arrayAlias.toUpperCase(), nestedDbType.getTypeName());
        }
    }
}
Also used : VArrayType(org.eclipse.persistence.tools.oracleddl.metadata.VArrayType) CompositeDatabaseType(org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType) ComplexDatabaseType(org.eclipse.persistence.internal.helper.ComplexDatabaseType) DatabaseType(org.eclipse.persistence.tools.oracleddl.metadata.DatabaseType) Util.getAttributeClassForDatabaseType(org.eclipse.persistence.tools.dbws.Util.getAttributeClassForDatabaseType) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) Util.qNameFromString(org.eclipse.persistence.tools.dbws.Util.qNameFromString) ObjectRelationalDataTypeDescriptor(org.eclipse.persistence.mappings.structures.ObjectRelationalDataTypeDescriptor)

Example 2 with ObjectRelationalDataTypeDescriptor

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

the class OracleHelper method buildAndAddNewObjectRelationalDataTypeDescriptor.

/**
 * Build an ObjectRelationalDataTypeDescriptor based on a given descriptor
 * alias and java class name, and add it to the given OR Project.
 */
protected ObjectRelationalDataTypeDescriptor buildAndAddNewObjectRelationalDataTypeDescriptor(Project orProject, String alias, String javaClassName) {
    ObjectRelationalDataTypeDescriptor ordesc = buildNewObjectRelationalDataTypeDescriptor(alias, javaClassName);
    orProject.addDescriptor(ordesc);
    return ordesc;
}
Also used : ObjectRelationalDataTypeDescriptor(org.eclipse.persistence.mappings.structures.ObjectRelationalDataTypeDescriptor)

Example 3 with ObjectRelationalDataTypeDescriptor

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

the class OracleHelper method addToORProjectForObjectTypeArg.

/**
 * Build descriptor and mappings for an Object type argument.  The
 * newly created descriptor will be added to the given OX project.
 */
@SuppressWarnings("rawtypes")
protected void addToORProjectForObjectTypeArg(DatabaseType dbType, Project orProject, String objectName, String objectAlias) {
    ObjectRelationalDataTypeDescriptor ordt = (ObjectRelationalDataTypeDescriptor) orProject.getDescriptorForAlias(objectAlias);
    if (ordt == null) {
        ordt = buildAndAddNewObjectRelationalDataTypeDescriptor(orProject, objectAlias, objectName);
    }
    ObjectType oType = (ObjectType) dbType;
    for (FieldType fType : oType.getFields()) {
        String fieldName = fType.getFieldName();
        String lFieldName = fieldName.toLowerCase();
        // handle field ordering
        boolean found = false;
        Vector orderedFields = ordt.getOrderedFields();
        for (Iterator i = orderedFields.iterator(); i.hasNext(); ) {
            Object o = i.next();
            if (o instanceof DatabaseField) {
                DatabaseField field = (DatabaseField) o;
                if (field.getName().equalsIgnoreCase(fieldName)) {
                    found = true;
                    break;
                }
            }
        }
        if (!found) {
            ordt.addFieldOrdering(fieldName);
        }
        if (ordt.getMappingForAttributeName(lFieldName) == null) {
            if (fType.isComposite()) {
                String targetTypeName2 = fType.getEnclosedType().getTypeName();
                String alias = getGeneratedAlias(targetTypeName2);
                ObjectRelationalDataTypeDescriptor ordt2 = (ObjectRelationalDataTypeDescriptor) orProject.getDescriptorForAlias(alias);
                boolean buildDescriptor = ordt2 == null;
                if (buildDescriptor) {
                    ordt2 = buildAndAddNewObjectRelationalDataTypeDescriptor(orProject, alias);
                }
                // handle ObjectType field
                if (fType.getEnclosedType().isObjectType()) {
                    if (buildDescriptor) {
                        // need to update the java class name on the descriptor to include package (project) name
                        ordt2.setJavaClassName(getGeneratedJavaClassName(alias, dbwsBuilder.getProjectName()));
                        addToORProjectForObjectTypeArg(fType.getEnclosedType(), orProject, ordt2.getJavaClassName(), alias);
                    }
                    buildAndAddStructureMapping(ordt, lFieldName, fieldName, ordt2.getJavaClassName());
                } else if (fType.getEnclosedType().isVArrayType()) {
                    // handle VArray field
                    if (buildDescriptor) {
                        // need to update the java class name on the descriptor to include package (project) name
                        ordt2.setJavaClassName(getGeneratedJavaClassName(alias, dbwsBuilder.getProjectName()));
                        addToORProjectForVArrayArg(fType.getEnclosedType(), orProject, ordt2.getJavaClassName(), alias);
                    }
                    buildAndAddArrayMapping(ordt, lFieldName, fieldName, getStructureNameForField(fType, null));
                } else if (fType.getEnclosedType().isObjectTableType()) {
                    if (buildDescriptor) {
                        // need to update the java class name on the descriptor to include package (project) name
                        ordt2.setJavaClassName(getGeneratedJavaClassName(alias, dbwsBuilder.getProjectName()));
                        // make sure the descriptor is built for the enclosed ObjectType
                        addToORProjectForObjectTableTypeArg(fType.getEnclosedType(), orProject, targetTypeName2, alias);
                    }
                    if (((ObjectTableType) fType.getEnclosedType()).getEnclosedType().isComposite()) {
                        ObjectType nestedType = (ObjectType) ((ObjectTableType) fType.getEnclosedType()).getEnclosedType();
                        String nestedTypeAlias = getGeneratedAlias(nestedType.getTypeName());
                        String nestedTypeName = getGeneratedJavaClassName(nestedTypeAlias, dbwsBuilder.getProjectName());
                        buildAndAddObjectArrayMapping(ordt, lFieldName, fieldName, nestedTypeName, nestedTypeAlias.toUpperCase());
                    } else {
                        buildAndAddArrayMapping(ordt, lFieldName, fieldName, alias.toUpperCase());
                    }
                }
            } else {
                // direct mapping
                DirectToFieldMapping dfm = new DirectToFieldMapping();
                dfm.setFieldName(fieldName);
                dfm.setAttributeName(lFieldName);
                dfm.setAttributeClassification(getAttributeClassForDatabaseType(fType.getEnclosedType()));
                ordt.addMapping(dfm);
            }
        }
    }
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) ObjectType(org.eclipse.persistence.tools.oracleddl.metadata.ObjectType) OracleObjectType(org.eclipse.persistence.platform.database.oracle.jdbc.OracleObjectType) ObjectRelationalDatabaseField(org.eclipse.persistence.mappings.structures.ObjectRelationalDatabaseField) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) Iterator(java.util.Iterator) Util.qNameFromString(org.eclipse.persistence.tools.dbws.Util.qNameFromString) Vector(java.util.Vector) ObjectRelationalDataTypeDescriptor(org.eclipse.persistence.mappings.structures.ObjectRelationalDataTypeDescriptor) FieldType(org.eclipse.persistence.tools.oracleddl.metadata.FieldType)

Example 4 with ObjectRelationalDataTypeDescriptor

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

the class OracleHelper method buildNewObjectRelationalDataTypeDescriptor.

/**
 * Build an ObjectRelationalDataTypeDescriptor based on a given
 * descriptor alias and java class name.
 */
protected ObjectRelationalDataTypeDescriptor buildNewObjectRelationalDataTypeDescriptor(String alias, String javaClassName) {
    ObjectRelationalDataTypeDescriptor ordt = new ObjectRelationalDataTypeDescriptor();
    ordt.setStructureName(alias.toUpperCase());
    ordt.descriptorIsAggregate();
    // we have a map of created descriptors, keyed on javaClassName, which - along with a
    // list of referenceClassNames (set upon reference mapping creation) - will allow us
    // to set aggregate descriptors as required.
    createdORDescriptors.put(javaClassName, ordt);
    ordt.setAlias(alias);
    ordt.setJavaClassName(javaClassName);
    ordt.getQueryManager();
    return ordt;
}
Also used : ObjectRelationalDataTypeDescriptor(org.eclipse.persistence.mappings.structures.ObjectRelationalDataTypeDescriptor)

Example 5 with ObjectRelationalDataTypeDescriptor

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

the class DatabaseCall method buildOutputRow.

/**
 * INTERNAL:
 * Return Record containing output fields and values.
 * Called only if shouldBuildOutputRow method returns true.
 */
public AbstractRecord buildOutputRow(CallableStatement statement, DatabaseAccessor accessor, AbstractSession session) throws SQLException {
    AbstractRecord row = new DatabaseRecord();
    int size = this.parameters.size();
    for (int index = 0; index < size; index++) {
        Object parameter = this.parameters.get(index);
        if (parameter instanceof OutputParameterForCallableStatement) {
            OutputParameterForCallableStatement outParameter = (OutputParameterForCallableStatement) parameter;
            if (!outParameter.isCursor() || !isCursorOutputProcedure()) {
                Object value = getOutputParameterValue(statement, index, session);
                DatabaseField field = outParameter.getOutputField();
                if (value instanceof Struct) {
                    ClassDescriptor descriptor = session.getDescriptor(field.getType());
                    if ((descriptor != null) && descriptor.isObjectRelationalDataTypeDescriptor()) {
                        AbstractRecord nestedRow = ((ObjectRelationalDataTypeDescriptor) descriptor).buildRowFromStructure((Struct) value);
                        ReadObjectQuery query = new ReadObjectQuery();
                        query.setSession(session);
                        value = descriptor.getObjectBuilder().buildNewInstance();
                        descriptor.getObjectBuilder().buildAttributesIntoObject(value, null, nestedRow, query, null, null, false, this.getQuery().getSession());
                    }
                } else if ((value instanceof Array) && (field.isObjectRelationalDatabaseField())) {
                    value = ObjectRelationalDataTypeDescriptor.buildContainerFromArray((Array) value, (ObjectRelationalDatabaseField) field, session);
                } else if (value instanceof ResultSet) {
                    // Support multiple out cursors, put list of records in row.
                    ResultSet resultSet = (ResultSet) value;
                    setFields(null);
                    matchFieldOrder(resultSet, accessor, session);
                    value = accessor.processResultSet(resultSet, this, statement, session);
                }
                row.put(field, value);
            }
        }
    }
    return row;
}
Also used : Array(java.sql.Array) DatabaseRecord(org.eclipse.persistence.sessions.DatabaseRecord) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) ReadObjectQuery(org.eclipse.persistence.queries.ReadObjectQuery) ObjectRelationalDatabaseField(org.eclipse.persistence.mappings.structures.ObjectRelationalDatabaseField) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) AbstractRecord(org.eclipse.persistence.internal.sessions.AbstractRecord) ResultSet(java.sql.ResultSet) ObjectRelationalDataTypeDescriptor(org.eclipse.persistence.mappings.structures.ObjectRelationalDataTypeDescriptor) Struct(java.sql.Struct)

Aggregations

ObjectRelationalDataTypeDescriptor (org.eclipse.persistence.mappings.structures.ObjectRelationalDataTypeDescriptor)20 DirectToFieldMapping (org.eclipse.persistence.mappings.DirectToFieldMapping)9 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)6 ObjectRelationalDatabaseField (org.eclipse.persistence.mappings.structures.ObjectRelationalDatabaseField)6 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)5 Util.qNameFromString (org.eclipse.persistence.tools.dbws.Util.qNameFromString)5 ComplexDatabaseType (org.eclipse.persistence.internal.helper.ComplexDatabaseType)3 DatabaseLogin (org.eclipse.persistence.sessions.DatabaseLogin)3 Project (org.eclipse.persistence.sessions.Project)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 StringReader (java.io.StringReader)2 Array (java.sql.Array)2 SQLException (java.sql.SQLException)2 Struct (java.sql.Struct)2 Iterator (java.util.Iterator)2 Vector (java.util.Vector)2 DBWSModel (org.eclipse.persistence.dbws.DBWSModel)2 DBWSModelProject (org.eclipse.persistence.dbws.DBWSModelProject)2 ObjectPersistenceWorkbenchXMLProject (org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceWorkbenchXMLProject)2 XRServiceFactory (org.eclipse.persistence.internal.xr.XRServiceFactory)2