use of org.eclipse.persistence.tools.oracleddl.metadata.ObjectTableType in project eclipselink by eclipse-ee4j.
the class JPAMetadataGenerator method processArrayType.
/**
* Generate array type metadata based on the given VArray or ObjectTable type.
*/
protected OracleArrayTypeMetadata processArrayType(DatabaseType dbType) {
OracleArrayTypeMetadata arrayType = new OracleArrayTypeMetadata();
arrayType.setName(dbType.getTypeName());
arrayType.setJavaType(getGeneratedJavaClassName(dbType.getTypeName(), defaultPackage));
if (dbType.isVArrayType()) {
arrayType.setNestedType(processTypeName(((VArrayType) dbType).getEnclosedType().getTypeName()));
} else {
// assumes ObjectTable
arrayType.setNestedType(((ObjectTableType) dbType).getEnclosedType().getTypeName());
}
// avoid double-processing
getProcessedTypes().add(arrayType.getName());
// generate an EmbeddableAccessor for this type
generateEmbeddable(arrayType, (CompositeDatabaseTypeWithEnclosedType) dbType);
return arrayType;
}
use of org.eclipse.persistence.tools.oracleddl.metadata.ObjectTableType in project eclipselink by eclipse-ee4j.
the class JPAMetadataGenerator method addEmbeddableAttributes.
/**
* Process a list of FieldTypes, creating an attribute for each - the created
* XMLAttributes are set on the given EmbeddableAccessor.
*
* @see org.eclipse.persistence.internal.jpa.metadata.accessors.classes.XMLAttributes
*/
protected void addEmbeddableAttributes(EmbeddableAccessor embeddable, List<FieldType> fields) {
for (FieldType fld : fields) {
DatabaseType enclosedType = fld.getEnclosedType();
if (!enclosedType.isComposite() || enclosedType.isTYPEType()) {
// basic
String typeName = enclosedType.isTYPEType() ? enclosedType.getTypeName() : fld.getTypeName();
BasicAccessor basic = generateBasicAccessor(fld.getFieldName().toLowerCase(), fld.getFieldName(), getClassNameFromJDBCTypeName(typeName, dbPlatform));
embeddable.getAttributes().getBasics().add(basic);
} else if (enclosedType.isPLSQLType()) {
// record or collection
PLSQLType plsqlType = (PLSQLType) enclosedType;
String typeName = getQualifiedTypeName(plsqlType);
EmbeddedAccessor embedded = new EmbeddedAccessor();
embedded.setName(fld.getFieldName().toLowerCase());
embedded.setAttributeType(getGeneratedJavaClassName(typeName));
embeddable.getAttributes().getEmbeddeds().add(embedded);
} else if (enclosedType.isVArrayType() || enclosedType.isObjectTableType()) {
// array
ArrayAccessor array = null;
// target class is reference class name for Object Table, and structure name for Varray
if (enclosedType.isVArrayType()) {
array = generateArrayAccessor(fld.getFieldName().toLowerCase(), fld.getFieldName(), enclosedType.getTypeName());
} else {
ObjectTableType otType = (ObjectTableType) enclosedType;
array = generateArrayAccessor(fld.getFieldName().toLowerCase(), fld.getFieldName(), otType.getEnclosedType().getTypeName(), getGeneratedJavaClassName(otType.getEnclosedType().getTypeName(), defaultPackage));
}
embeddable.getAttributes().getArrays().add(array);
} else if (enclosedType.isObjectType()) {
// struct
StructureAccessor structure = generateStructureAccessor(fld.getFieldName().toLowerCase(), fld.getFieldName(), getGeneratedJavaClassName(enclosedType.getTypeName(), defaultPackage));
embeddable.getAttributes().getStructures().add(structure);
} else if (enclosedType.isTYPEType()) {
TYPEType tType = (TYPEType) enclosedType;
BasicAccessor basic = generateBasicAccessor(fld.getFieldName().toLowerCase(), fld.getFieldName(), getClassNameFromJDBCTypeName(tType.getTypeName(), dbPlatform));
embeddable.getAttributes().getBasics().add(basic);
}
}
}
use of org.eclipse.persistence.tools.oracleddl.metadata.ObjectTableType 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.ObjectTableType 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.ObjectTableType 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