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