use of org.eclipse.persistence.tools.oracleddl.metadata.FieldType in project eclipselink by eclipse-ee4j.
the class JPAMetadataGenerator method processPLSQLArgument.
/**
* Generate a PL/SQL parameter based on the given ArgumentType. For
* non-PL/SQL arguments the processArgument method should be used.
*/
protected PLSQLParameterMetadata processPLSQLArgument(ArgumentType arg) {
// for %ROWTYPE, we need to create a PL/SQL record that mirrors the Table
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);
}
PLSQLParameterMetadata param = new PLSQLParameterMetadata();
// handle cursor
if (arg.isPLSQLCursorType()) {
param.setDirection(OUT_CURSOR_STR);
}
// handle stored function return type
if (arg.getDirection() == ArgumentTypeDirection.RETURN) {
param.setName(arg.isPLSQLCursorType() ? CURSOR_STR : RESULT_STR);
} else {
// direction is already set for cursor type
if (!arg.isPLSQLCursorType()) {
param.setDirection(arg.getDirection().name());
}
param.setName(arg.getArgumentName());
}
String dbType = arg.getTypeName();
// handle composites
if (arg.isComposite()) {
DatabaseType enclosedType = arg.getEnclosedType();
// need to prepend the package name for most PL/SQL and Cursor types
if (enclosedType.isPLSQLType() || enclosedType.isPLSQLCursorType()) {
dbType = getQualifiedTypeName(enclosedType);
}
// process the composite enclosed type
processCompositeType(enclosedType, dbType);
}
param.setDatabaseType(processTypeName(dbType));
return param;
}
use of org.eclipse.persistence.tools.oracleddl.metadata.FieldType in project eclipselink by eclipse-ee4j.
the class JPAMetadataGenerator method processTableType.
/**
* Generate an EntityAccessor based on the given TableType.
*/
protected EntityAccessor processTableType(TableType tType) {
EntityAccessor entity = new EntityAccessor();
entity.setAccess(EL_ACCESS_VIRTUAL);
entity.setClassName(getEntityName(tType.getTableName(), defaultPackage));
// initialize the various lists - some used, some not
initializeXMLAttributeLists(entity);
// set the table name on the entity
TableMetadata table = new TableMetadata();
table.setName(tType.getTableName());
entity.setTable(table);
// process the table columns
for (FieldType fType : tType.getColumns()) {
BasicAccessor attribute;
// handle primary key
if (fType.pk()) {
attribute = new IdAccessor();
entity.getAttributes().getIds().add((IdAccessor) attribute);
} else {
attribute = new BasicAccessor();
entity.getAttributes().getBasics().add(attribute);
}
attribute.setName(fType.getFieldName().toLowerCase());
attribute.setAttributeType(getAttributeTypeNameForFieldType(fType, dbPlatform));
// set the column name
ColumnMetadata column = new ColumnMetadata();
column.setName(fType.getFieldName());
attribute.setColumn(column);
}
// may need to generated NamedNativeQueryMetadata for CRUD operations
generateCRUDMetadata(entity);
return entity;
}
use of org.eclipse.persistence.tools.oracleddl.metadata.FieldType in project eclipselink by eclipse-ee4j.
the class JPAMetadataGenerator method processPLSQLRecordType.
/**
* Process the given PLSQLRecordType and return a PLSQLRecordMetadata instance.
*/
protected PLSQLRecordMetadata processPLSQLRecordType(PLSQLRecordType plsqlRecordType) {
// for %ROWTYPE we create a 'place holder' PL/SQL Record - in this case there is no package name
String typeName = getQualifiedTypeName(plsqlRecordType);
String compatibleName = getQualifiedCompatibleTypeName(plsqlRecordType);
if (compatibleName.contains(PERCENT)) {
compatibleName = compatibleName.replace(PERCENT, UNDERSCORE);
}
PLSQLRecordMetadata plsqlRecord = new PLSQLRecordMetadata();
plsqlRecord.setName(typeName);
plsqlRecord.setCompatibleType(compatibleName);
if (typeName.endsWith(ROWTYPE_STR)) {
plsqlRecord.setJavaType(getGeneratedJavaClassName(compatibleName));
} else {
plsqlRecord.setJavaType(getGeneratedJavaClassName(typeName));
}
List<PLSQLParameterMetadata> fields = new ArrayList<PLSQLParameterMetadata>();
PLSQLParameterMetadata field;
for (FieldType fld : plsqlRecordType.getFields()) {
field = new PLSQLParameterMetadata();
field.setName(fld.getFieldName());
String dbType = processTypeName(fld.getTypeName());
if (fld.isComposite()) {
DatabaseType enclosedType = fld.getEnclosedType();
// may need to prepend package name
if (enclosedType.isPLSQLType()) {
dbType = ((PLSQLType) fld.getEnclosedType()).getParentType().getPackageName() + DOT + dbType;
}
processCompositeType(enclosedType, dbType);
}
field.setDatabaseType(dbType);
fields.add(field);
}
plsqlRecord.setFields(fields);
// avoid double-processing
getProcessedTypes().add(plsqlRecord.getName());
// generate an EmbeddableAccessor for this type
generateEmbeddable(plsqlRecord, plsqlRecordType);
return plsqlRecord;
}
use of org.eclipse.persistence.tools.oracleddl.metadata.FieldType in project eclipselink by eclipse-ee4j.
the class XmlEntityMappingsGenerator method processObjectType.
/**
* Process the given ObjectType and return an OracleObjectTypeMetadata instance.
*/
protected static ComplexTypeMetadata processObjectType(ObjectType oType, Project orProject) {
ClassDescriptor cDesc = orProject.getDescriptorForAlias(getGeneratedAlias(oType.getTypeName()));
OracleObjectTypeMetadata ootMetadata = new OracleObjectTypeMetadata();
ootMetadata.setName(oType.getTypeName());
ootMetadata.setJavaType(cDesc.getJavaClassName());
List<PLSQLParameterMetadata> fields = new ArrayList<PLSQLParameterMetadata>();
for (FieldType ft : oType.getFields()) {
PLSQLParameterMetadata fieldMetadata = new PLSQLParameterMetadata();
fieldMetadata.setName(ft.getFieldName());
fieldMetadata.setDatabaseType(processTypeName(ft.getTypeName()));
fields.add(fieldMetadata);
}
ootMetadata.setFields(fields);
return ootMetadata;
}
use of org.eclipse.persistence.tools.oracleddl.metadata.FieldType 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;
}
Aggregations