use of org.eclipse.persistence.tools.oracleddl.metadata.ObjectType 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.tools.oracleddl.metadata.ObjectType in project eclipselink by eclipse-ee4j.
the class XmlEntityMappingsGenerator method processCompositeTypes.
/**
* Returns a list of ComplexTypeMetadata instances generated based on a list of
* CompositeDatabaseTypes. The given non-empty list should contain one or
* more of the following types:
* <ul>
* <li>PLSQLCollectionType
* <li>PLSQLRecordType
* <li>ObjectTableType
* <li>ObjectType
* <li>VArrayType
* </ul>
*/
protected static List<ComplexTypeMetadata> processCompositeTypes(List<CompositeDatabaseType> complexTypes, Project orProject) {
List<String> processedTypeNames = new ArrayList<String>();
List<ComplexTypeMetadata> processedTypes = new ArrayList<ComplexTypeMetadata>();
// process composite types
for (CompositeDatabaseType cdbType : complexTypes) {
ComplexTypeMetadata complexTypeMetadata = processDatabaseType(cdbType, orProject);
if (complexTypeMetadata != null) {
processedTypeNames.add(complexTypeMetadata.getName());
processedTypes.add(complexTypeMetadata);
}
}
// now handle processing composite enclosed types
for (CompositeDatabaseType cdbType : complexTypes) {
if (cdbType.getEnclosedType() != null && cdbType.getEnclosedType().isComposite()) {
CompositeDatabaseType enclosedType = (CompositeDatabaseType) cdbType.getEnclosedType();
ComplexTypeMetadata complexTypeMetadata = processDatabaseType(enclosedType, orProject, processedTypeNames);
if (complexTypeMetadata != null) {
processedTypeNames.add(complexTypeMetadata.getName());
processedTypes.add(complexTypeMetadata);
if (enclosedType.isObjectType()) {
for (FieldType ft : ((ObjectType) enclosedType).getFields()) {
if (ft.isComposite()) {
complexTypeMetadata = processDatabaseType(ft, orProject, processedTypeNames);
if (complexTypeMetadata != null) {
processedTypeNames.add(complexTypeMetadata.getName());
processedTypes.add(complexTypeMetadata);
}
}
}
} else if (enclosedType.isVArrayType()) {
VArrayType vType = (VArrayType) enclosedType;
if (vType.getEnclosedType().isComposite()) {
complexTypeMetadata = processDatabaseType((CompositeDatabaseType) vType.getEnclosedType(), orProject, processedTypeNames);
if (complexTypeMetadata != null) {
processedTypeNames.add(complexTypeMetadata.getName());
processedTypes.add(complexTypeMetadata);
}
}
}
}
}
}
return processedTypes;
}
use of org.eclipse.persistence.tools.oracleddl.metadata.ObjectType in project eclipselink by eclipse-ee4j.
the class OracleHelper method addToOXProjectForObjectTypeArg.
/**
* Build descriptor and mappings for an Object type argument. The
* newly created descriptor will be added to the given OX project.
*/
protected void addToOXProjectForObjectTypeArg(DatabaseType dbType, Project oxProject, String objectName, String objectAlias) {
XMLDescriptor xdesc = (XMLDescriptor) oxProject.getDescriptorForAlias(objectAlias);
if (xdesc == null) {
xdesc = buildAndAddNewXMLDescriptor(oxProject, objectAlias, objectName, nct.generateSchemaAlias(dbType.getTypeName()), buildCustomQName(objectName, dbwsBuilder).getNamespaceURI());
}
ObjectType oType = (ObjectType) dbType;
for (FieldType field : oType.getFields()) {
// custom transformer may exclude some fields
if (nct.styleForElement(field.getFieldName()) == ElementStyle.NONE) {
continue;
}
String lFieldName = field.getFieldName().toLowerCase();
if (xdesc.getMappingForAttributeName(lFieldName) == null) {
if (field.isComposite()) {
String targetTypeName2 = field.getEnclosedType().getTypeName();
String alias = getGeneratedAlias(targetTypeName2);
XMLDescriptor xdesc2 = (XMLDescriptor) oxProject.getDescriptorForAlias(alias);
boolean buildDescriptor = xdesc2 == null;
if (buildDescriptor) {
xdesc2 = buildAndAddNewXMLDescriptor(oxProject, alias, nct.generateSchemaAlias(targetTypeName2), buildCustomQName(targetTypeName2, dbwsBuilder).getNamespaceURI());
}
// handle ObjectType field
if (field.getEnclosedType().isObjectType()) {
if (buildDescriptor) {
// need to update the java class name on the descriptor to include package (project) name
xdesc2.setJavaClassName(getGeneratedJavaClassName(alias, dbwsBuilder.getProjectName()));
addToOXProjectForObjectTypeArg(field.getEnclosedType(), oxProject, xdesc2.getJavaClassName(), alias);
}
buildAndAddXMLCompositeObjectMapping(xdesc, lFieldName, xdesc2.getJavaClassName());
} else if (field.getEnclosedType().isVArrayType()) {
// handle VArray field
if (buildDescriptor) {
// need to update the java class name on the descriptor to include package (project) name
xdesc2.setJavaClassName(getGeneratedJavaClassName(alias, dbwsBuilder.getProjectName()));
addToOXProjectForVArrayArg(field.getEnclosedType(), oxProject, xdesc2.getJavaClassName(), alias);
}
buildAndAddXMLCompositeDirectCollectionMapping(xdesc, lFieldName, lFieldName + SLASH + TEXT, getAttributeClassForDatabaseType(field.getEnclosedType()));
} else if (field.getEnclosedType().isObjectTableType()) {
// handle ObjectTableType field
if (buildDescriptor) {
// need to update the java class name on the descriptor to include package (project) name
xdesc2.setJavaClassName(getGeneratedJavaClassName(alias, dbwsBuilder.getProjectName()));
// make sure the descriptor is built for the enclosed ObjectType
addToOXProjectForObjectTableTypeArg(field.getEnclosedType(), oxProject, targetTypeName2, alias);
}
ObjectTableType tableType = (ObjectTableType) field.getEnclosedType();
if (tableType.getEnclosedType().isComposite()) {
String nestedTypeAlias = getGeneratedAlias(((ObjectTableType) field.getEnclosedType()).getEnclosedType().getTypeName());
String nestedTypeName = getGeneratedJavaClassName(nestedTypeAlias, dbwsBuilder.getProjectName());
buildAndAddXMLCompositeCollectionMapping(xdesc, lFieldName, lFieldName + SLASH + ITEM_MAPPING_NAME, nestedTypeName);
} else {
buildAndAddXMLCompositeDirectCollectionMapping(xdesc, lFieldName, lFieldName + SLASH + TEXT, getAttributeClassForDatabaseType(tableType));
}
}
} else {
// direct mapping
addDirectMappingForFieldType(xdesc, lFieldName, field);
}
}
}
}
use of org.eclipse.persistence.tools.oracleddl.metadata.ObjectType in project eclipselink by eclipse-ee4j.
the class OracleHelper method addToOXProjectForObjectTableTypeArg.
/**
* Build descriptor and mappings for an OracleTableType argument. The
* newly created descriptor will be added to the given OX project.
*/
protected void addToOXProjectForObjectTableTypeArg(DatabaseType dbType, Project oxProject, String objectTableName, String objectTableAlias) {
XMLDescriptor xdesc = (XMLDescriptor) oxProject.getDescriptorForAlias(objectTableAlias);
if (xdesc == null) {
xdesc = buildAndAddNewXMLDescriptor(oxProject, objectTableAlias, objectTableName + COLLECTION_WRAPPER_SUFFIX, nct.generateSchemaAlias(dbType.getTypeName()), buildCustomQName(objectTableName, dbwsBuilder).getNamespaceURI());
}
boolean itemsMappingFound = xdesc.getMappingForAttributeName(ITEMS_MAPPING_ATTRIBUTE_NAME) == null ? false : true;
if (!itemsMappingFound) {
DatabaseType nType = ((ObjectTableType) dbType).getEnclosedType();
if (nType.isObjectType()) {
ObjectType oType = (ObjectType) nType;
String nestedTypeAlias = getGeneratedAlias(oType.getTypeName());
String nestedTypeName = getGeneratedJavaClassName(nestedTypeAlias, dbwsBuilder.getProjectName());
addToOXProjectForObjectTypeArg(oType, oxProject, nestedTypeName, nestedTypeAlias);
// ObjectType is composite
buildAndAddXMLCompositeCollectionMapping(xdesc, nestedTypeName);
} else {
buildAndAddXMLCompositeDirectCollectionMapping(xdesc, ITEMS_MAPPING_ATTRIBUTE_NAME, ITEM_MAPPING_NAME + SLASH + TEXT, getAttributeClassForDatabaseType(nType));
}
}
}
use of org.eclipse.persistence.tools.oracleddl.metadata.ObjectType in project eclipselink by eclipse-ee4j.
the class OracleHelper method addToORProjectForPLSQLRecordArg.
/**
* Build descriptor and mappings for a PL/SQL record argument. The newly
* created descriptor will be added to the given OR project.
*/
@SuppressWarnings("rawtypes")
protected void addToORProjectForPLSQLRecordArg(DatabaseType dbType, Project orProject, String recordName, String recordAlias, String targetTypeName, String catalogPattern) {
ObjectRelationalDataTypeDescriptor ordtDesc = (ObjectRelationalDataTypeDescriptor) orProject.getDescriptorForAlias(recordAlias);
if (ordtDesc == null) {
ordtDesc = buildAndAddNewObjectRelationalDataTypeDescriptor(orProject, recordAlias, recordName.toLowerCase());
}
// handle fields
PLSQLRecordType plsqlRecType = (PLSQLRecordType) dbType;
for (FieldType fType : plsqlRecType.getFields()) {
String fieldName = fType.getFieldName();
String lFieldName = fieldName.toLowerCase();
// handle field ordering
boolean found = false;
Vector orderedFields = ordtDesc.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) {
ordtDesc.addFieldOrdering(fieldName);
}
if (ordtDesc.getMappingForAttributeName(lFieldName) == null) {
if (fType.isComposite()) {
if (fType.getEnclosedType().isPLSQLRecordType()) {
buildAndAddStructureMapping(ordtDesc, lFieldName, fieldName, recordName.toLowerCase());
} else if (fType.getEnclosedType().isPLSQLCollectionType()) {
PLSQLCollectionType tableType = (PLSQLCollectionType) fType.getEnclosedType();
if (tableType.getEnclosedType().isComposite()) {
buildAndAddObjectArrayMapping(ordtDesc, lFieldName, fieldName, (catalogPattern + "." + tableType.getTypeName()).toLowerCase() + COLLECTION_WRAPPER_SUFFIX, getStructureNameForField(fType, catalogPattern));
} else {
buildAndAddArrayMapping(ordtDesc, lFieldName, fieldName, getStructureNameForField(fType, catalogPattern));
}
} else if (fType.getEnclosedType().isObjectType()) {
buildAndAddStructureMapping(ordtDesc, lFieldName, fieldName, getGeneratedJavaClassName(fType.getEnclosedType().getTypeName(), dbwsBuilder.getProjectName()));
} else if (fType.getEnclosedType().isVArrayType()) {
if (((VArrayType) fType.getEnclosedType()).getEnclosedType().isComposite()) {
buildAndAddObjectArrayMapping(ordtDesc, lFieldName, fieldName, getGeneratedJavaClassName(((VArrayType) fType.getEnclosedType()).getEnclosedType().getTypeName(), dbwsBuilder.getProjectName()), getStructureNameForField(fType, null));
} else {
buildAndAddArrayMapping(ordtDesc, lFieldName, fieldName, getStructureNameForField(fType, null));
}
} else if (fType.getEnclosedType().isObjectTableType()) {
ObjectTableType nestedType = (ObjectTableType) fType.getEnclosedType();
if (nestedType.getEnclosedType().isComposite()) {
ObjectType oType = (ObjectType) nestedType.getEnclosedType();
String oTypeAlias = oType.getTypeName().toLowerCase();
String oTypeName = getGeneratedJavaClassName(oTypeAlias, dbwsBuilder.getProjectName());
// ObjectType is composite
buildAndAddObjectArrayMapping(ordtDesc, lFieldName, fieldName, oTypeName, oTypeAlias.toUpperCase());
} else {
buildAndAddArrayMapping(ordtDesc, lFieldName, fieldName, nestedType.getTypeName().toUpperCase());
}
} else if (fType.getEnclosedType().isTYPEType()) {
// handle %TYPE
TYPEType typeType = (TYPEType) fType.getEnclosedType();
if (typeType.getEnclosedType().isFieldType()) {
// direct mapping
AbstractDirectMapping absDirectMapping = (AbstractDirectMapping) ordtDesc.addDirectMapping(lFieldName, fieldName);
try {
absDirectMapping.setAttributeClassificationName(getClassFromJDBCType(fType.getTypeName(), dbwsBuilder.getDatabasePlatform()).getName());
} catch (Exception x) {
}
}
}
} else {
// direct mapping
DirectToFieldMapping dfm = new DirectToFieldMapping();
dfm.setFieldName(fieldName);
dfm.setAttributeName(lFieldName);
dfm.setAttributeClassification(getAttributeClassForDatabaseType(fType.getEnclosedType()));
ordtDesc.addMapping(dfm);
}
}
}
}
Aggregations