use of org.eclipse.persistence.tools.oracleddl.metadata.FieldType in project eclipselink by eclipse-ee4j.
the class BaseDBWSBuilderHelper method buildOROXProjects.
/**
* Builds OR/OX projects, descriptors {@literal &} mappings, based on a given list
* of types, as well as table(s) and secondary SQL.
*/
public void buildOROXProjects(NamingConventionTransformer nct, List<CompositeDatabaseType> types) {
// save for later
this.nct = nct;
String projectName = dbwsBuilder.getProjectName();
Project orProject = new Project();
orProject.setName(projectName + UNDERSCORE + DBWS_OR_LABEL);
Project oxProject = null;
if (dbTables.isEmpty() && !dbwsBuilder.hasBuildSqlOperations()) {
dbwsBuilder.logMessage(FINEST, "No tables specified");
oxProject = new SimpleXMLFormatProject();
} else {
oxProject = new Project();
}
oxProject.setName(projectName + UNDERSCORE + DBWS_OX_LABEL);
for (TableType dbTable : dbTables) {
String tableName = dbTable.getTableName();
RelationalDescriptor desc = buildORDescriptor(tableName, dbwsBuilder.getProjectName(), dbwsBuilder.requireCRUDOperations, nct);
orProject.addDescriptor(desc);
XMLDescriptor xdesc = buildOXDescriptor(tableName, dbwsBuilder.getProjectName(), dbwsBuilder.getTargetNamespace(), nct);
oxProject.addDescriptor(xdesc);
for (FieldType dbColumn : dbTable.getColumns()) {
String columnName = dbColumn.getFieldName();
ElementStyle style = nct.styleForElement(columnName);
if (style == NONE) {
continue;
}
dbwsBuilder.logMessage(FINE, "Building mappings for " + tableName + DOT + columnName);
DirectToFieldMapping orFieldMapping = buildORFieldMappingFromColumn(dbColumn, desc, dbwsBuilder.getDatabasePlatform(), nct);
desc.addMapping(orFieldMapping);
XMLDirectMapping oxFieldMapping = buildOXFieldMappingFromColumn(dbColumn, dbwsBuilder.getDatabasePlatform(), nct);
if (oxFieldMapping instanceof XMLBinaryDataMapping) {
xdesc.getNamespaceResolver().put(XML_MIME_PREFIX, XML_MIME_URL);
}
xdesc.addMapping(oxFieldMapping);
// check for switch from Byte[] to byte[]
if (oxFieldMapping.getAttributeClassificationName() == APBYTE.getName()) {
orFieldMapping.setAttributeClassificationName(APBYTE.getName());
}
}
setUpFindQueries(nct, tableName, desc);
}
finishUpProjects(orProject, oxProject, types);
}
use of org.eclipse.persistence.tools.oracleddl.metadata.FieldType 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.FieldType 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.FieldType 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.FieldType in project eclipselink by eclipse-ee4j.
the class JPAMetadataGenerator method processObjectType.
/**
* Generate object type metadata based on the given ObjectType.
*/
protected OracleObjectTypeMetadata processObjectType(ObjectType oType) {
OracleObjectTypeMetadata objectType = new OracleObjectTypeMetadata();
objectType.setName(oType.getTypeName());
objectType.setJavaType(getGeneratedJavaClassName(oType.getTypeName(), defaultPackage));
// process the object type's fields
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);
if (ft.isComposite()) {
processCompositeType(ft.getEnclosedType());
}
}
objectType.setFields(fields);
// avoid double-processing
getProcessedTypes().add(objectType.getName());
// generate an EmbeddableAccessor for this type
generateEmbeddable(objectType, oType);
return objectType;
}
Aggregations