use of org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType in project eclipselink by eclipse-ee4j.
the class BaseDBWSBuilderHelper method buildTypesList.
/**
* Uses a custom visitor to traverse each procedure/function argument and build
* a list of required Types. Only on instance of a given type will exist in
* the list.
*/
public List<CompositeDatabaseType> buildTypesList(List<OperationModel> operations) {
EnclosedTypeVisitor etVisitor = new EnclosedTypeVisitor();
for (OperationModel opModel : operations) {
if (opModel.isProcedureOperation()) {
ProcedureOperationModel procedureOperation = (ProcedureOperationModel) opModel;
if (procedureOperation.isPLSQLProcedureOperation() || procedureOperation.isAdvancedJDBCProcedureOperation()) {
for (ProcedureType procType : procedureOperation.getDbStoredProcedures()) {
// build list of arguments to process (i.e. build descriptors for)
List<ArgumentType> args = new ArrayList<ArgumentType>();
// return argument
if (procType.isFunctionType()) {
// assumes that a function MUST have a return type
args.add(((FunctionType) procType).getReturnArgument());
}
args.addAll(procType.getArguments());
// now visit each argument
for (ArgumentType arg : args) {
// handle ROWTYPETypes
if (arg.getEnclosedType().isROWTYPEType()) {
ROWTYPEType rType = (ROWTYPEType) arg.getEnclosedType();
TableType tableType = (TableType) rType.getEnclosedType();
PLSQLRecordType plsqlRec = new PLSQLRecordType(rType.getTypeName());
plsqlRec.setParentType(new PLSQLPackageType());
for (FieldType col : tableType.getColumns()) {
FieldType ft = new FieldType(col.getFieldName());
ft.setEnclosedType(col.getEnclosedType());
plsqlRec.addField(ft);
}
arg.setEnclosedType(plsqlRec);
}
// now visit each, adding types (only one instance of each) to the list
if (arg.isComposite()) {
etVisitor.visit((CompositeDatabaseType) arg);
}
}
}
}
}
}
// gather Complex types to hand into XMLEntityMappingsGenerator
List<CompositeDatabaseType> types = etVisitor.getCompositeDatabaseTypes();
for (CompositeDatabaseType type : types) {
complextypes.add(type);
}
return etVisitor.getCompositeDatabaseTypes();
}
use of org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType in project eclipselink by eclipse-ee4j.
the class JPAMetadataGenerator method generateXmlEntityMappings.
/**
* Generate an XMLEntityMappings instance based on a given list of meta-model database types.
*
* @param databaseTypes the list of meta-model database types to be used to generate an XMLEntityMappings
* @see org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType
*/
public XMLEntityMappings generateXmlEntityMappings(List<CompositeDatabaseType> databaseTypes) {
List<ProcedureType> procedures = new ArrayList<ProcedureType>();
List<TableType> tables = new ArrayList<TableType>();
// populate lists of TableTypes and ProcedureTypes
for (CompositeDatabaseType dbType : databaseTypes) {
if (dbType.isTableType()) {
tables.add((TableType) dbType);
} else if (dbType.isProcedureType()) {
procedures.add((ProcedureType) dbType);
}
}
// handle stored procedure overloading
handleOverloading(procedures);
// process TableTypes
for (TableType table : tables) {
EntityAccessor entity = processTableType(table);
xmlEntityMappings.getEntities().add(entity);
}
// process ProcedureTypes
for (ProcedureType procedure : procedures) {
// PL/SQL stored procedures and functions will have a PLSQLPackageType as its parent
PLSQLPackageType pkgType = procedure.getParentType();
if (pkgType != null) {
// handle PL/SQL
if (procedure.isFunctionType()) {
xmlEntityMappings.getNamedPLSQLStoredFunctionQueries().add(processPLSQLFunctionType((FunctionType) procedure, pkgType));
} else {
xmlEntityMappings.getNamedPLSQLStoredProcedureQueries().add(processPLSQLProcedureType(procedure, pkgType));
}
} else {
// handle top-level (non-PL/SQL) functions and procedures
if (procedure.isFunctionType()) {
xmlEntityMappings.getNamedStoredFunctionQueries().add(processFunctionType((FunctionType) procedure));
} else {
xmlEntityMappings.getNamedStoredProcedureQueries().add(processProcedureType(procedure));
}
}
}
return xmlEntityMappings;
}
use of org.eclipse.persistence.tools.oracleddl.metadata.CompositeDatabaseType 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.CompositeDatabaseType in project eclipselink by eclipse-ee4j.
the class OracleHelper method addToOROXProjectsForComplexTypes.
/**
* Create OR/OX projects for complex types, i.e. PLSQLTypes, VArray, etc.
*/
@Override
public void addToOROXProjectsForComplexTypes(List<CompositeDatabaseType> types, Project orProject, Project oxProject) {
for (DatabaseType dbType : types) {
String name;
String alias;
if (dbType.isPLSQLType()) {
// set type name to upper case to avoid runtime SQLException
dbType.setTypeName(dbType.getTypeName().toUpperCase());
String catalogPattern = ((PLSQLType) dbType).getParentType().getPackageName();
String targetTypeName;
// for types enclosed in a ROWTYPEType, package doesn't apply
if (catalogPattern == null) {
name = dbType.getTypeName();
targetTypeName = dbType.getTypeName();
} else {
name = catalogPattern + DOT + dbType.getTypeName();
targetTypeName = catalogPattern + UNDERSCORE + dbType.getTypeName();
}
alias = targetTypeName.toLowerCase();
// remove '%' from target, alias, and name
name = name.replace(PERCENT, UNDERSCORE);
targetTypeName = targetTypeName.replace(PERCENT, UNDERSCORE);
alias = alias.replace(PERCENT, UNDERSCORE);
// handle PL/SQL record type
if (dbType.isPLSQLRecordType()) {
addToOXProjectForPLSQLRecordArg(dbType, oxProject, name, alias, targetTypeName, catalogPattern);
addToORProjectForPLSQLRecordArg(dbType, orProject, name, alias, targetTypeName, catalogPattern);
} else // handle PL/SQL collection type
{
addToOXProjectForPLSQLTableArg(dbType, oxProject, name, alias, targetTypeName, catalogPattern);
addToORProjectForPLSQLTableArg(dbType, orProject, name, alias, targetTypeName, catalogPattern);
}
} else {
// Advanced JDBC types need the (Java) package name prepended to the type name
if (Util.isTypeComplex(dbType)) {
name = getGeneratedJavaClassName(dbType.getTypeName(), dbwsBuilder.getProjectName());
} else {
name = dbType.getTypeName();
}
alias = getGeneratedAlias(dbType.getTypeName());
// handle VArray type
if (dbType.isVArrayType()) {
addToOXProjectForVArrayArg(dbType, oxProject, name, alias);
addToORProjectForVArrayArg(dbType, orProject, name, alias);
} else // handle ObjectType type
if (dbType.isObjectType()) {
addToOXProjectForObjectTypeArg(dbType, oxProject, name, alias);
addToORProjectForObjectTypeArg(dbType, orProject, name, alias);
} else // handle ObjectTable type
if (dbType.isObjectTableType()) {
addToOXProjectForObjectTableTypeArg(dbType, oxProject, name, alias);
addToORProjectForObjectTableTypeArg(dbType, orProject, name, alias);
}
}
}
}
Aggregations