use of org.eclipse.persistence.tools.oracleddl.metadata.PLSQLType in project eclipselink by eclipse-ee4j.
the class OracleHelper method buildDbArtifacts.
@Override
public void buildDbArtifacts() {
super.buildDbArtifacts();
// list of all directly-referenced packages
Set<PLSQLPackageType> directPackages = new HashSet<PLSQLPackageType>();
for (ProcedureType procedureType : dbStoredProcedures) {
for (ArgumentType argumentType : procedureType.getArguments()) {
DatabaseType argumentDataType = argumentType.getEnclosedType();
if (argumentDataType.isPLSQLType()) {
PLSQLType plsqlType = (PLSQLType) argumentDataType;
directPackages.add(plsqlType.getParentType());
}
}
}
// any indirectly-referenced packages?
final Set<PLSQLPackageType> indirectPackages = new HashSet<PLSQLPackageType>();
DatabaseTypeVisitor indirectVisitor = new BaseDatabaseTypeVisitor() {
@Override
public void beginVisit(PLSQLPackageType databaseType) {
indirectPackages.add(databaseType);
}
};
for (PLSQLPackageType pckage : directPackages) {
pckage.accept(indirectVisitor);
}
Set<PLSQLPackageType> packages = new HashSet<PLSQLPackageType>();
packages.addAll(directPackages);
packages.addAll(indirectPackages);
for (PLSQLPackageType pckage : packages) {
ShadowDDLGenerator ddlGenerator = new ShadowDDLGenerator(pckage);
dbwsBuilder.getTypeDDL().addAll(ddlGenerator.getAllCreateDDLs());
dbwsBuilder.getTypeDropDDL().addAll(ddlGenerator.getAllDropDDLs());
}
}
use of org.eclipse.persistence.tools.oracleddl.metadata.PLSQLType in project eclipselink by eclipse-ee4j.
the class XmlEntityMappingsGenerator method processPLSQLCollectionType.
/**
* Process the given PLSQLCollectionType and return a PLSQLTableMetadata instance.
*/
protected static ComplexTypeMetadata processPLSQLCollectionType(PLSQLCollectionType plsqlCollectionType) {
String typeName = plsqlCollectionType.getParentType().getPackageName() + DOT + plsqlCollectionType.getTypeName();
String compatiableName = plsqlCollectionType.getParentType().getPackageName() + UNDERSCORE + plsqlCollectionType.getTypeName();
PLSQLTableMetadata plsqlTable = new PLSQLTableMetadata();
plsqlTable.setName(typeName);
plsqlTable.setCompatibleType(compatiableName);
// handle Nested Table (i.e. non-Varray)
plsqlTable.setNestedTable(!plsqlCollectionType.isIndexed());
String dbType = plsqlCollectionType.getEnclosedType().getTypeName();
if (!(getJDBCTypeFromTypeName(dbType) == Types.OTHER)) {
// need special handling for nested PL/SQL scalar types
if (isArgPLSQLScalar(dbType)) {
plsqlTable.setNestedType(getOraclePLSQLTypeForName(dbType));
} else {
// OR Metadata doesn't handle VARCHAR2
if (dbType.equals(VARCHAR2_STR)) {
dbType = VARCHAR_STR;
}
plsqlTable.setNestedType(dbType + _TYPE_STR);
}
} else {
// may need to prepend package name
String pkg = null;
if (plsqlCollectionType.getEnclosedType() != null && plsqlCollectionType.getEnclosedType().isPLSQLType()) {
PLSQLType pType = (PLSQLType) plsqlCollectionType.getEnclosedType();
pkg = pType.getParentType().getPackageName();
}
plsqlTable.setNestedType(pkg == null ? dbType : pkg + DOT + dbType);
}
plsqlTable.setJavaType(typeName.toLowerCase() + COLLECTION_WRAPPER_SUFFIX);
return plsqlTable;
}
use of org.eclipse.persistence.tools.oracleddl.metadata.PLSQLType 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.PLSQLType in project eclipselink by eclipse-ee4j.
the class JPAMetadataGenerator method processPLSQLCollectionType.
/**
* Process the given PLSQLCollectionType and return a PLSQLTableMetadata instance.
*/
protected PLSQLTableMetadata processPLSQLCollectionType(PLSQLCollectionType plsqlCollectionType) {
String typeName = getQualifiedTypeName(plsqlCollectionType);
String compatiableName = getQualifiedCompatibleTypeName(plsqlCollectionType);
String targetClassName = compatiableName;
PLSQLTableMetadata plsqlTable = new PLSQLTableMetadata();
plsqlTable.setName(typeName);
plsqlTable.setCompatibleType(compatiableName);
plsqlTable.setJavaType(getGeneratedJavaClassName(typeName));
// handle Nested Table (i.e. non-Varray)
plsqlTable.setNestedTable(!plsqlCollectionType.isIndexed());
String dbType = plsqlCollectionType.getEnclosedType().getTypeName();
if (!(getJDBCTypeFromTypeName(dbType) == Types.OTHER)) {
// need special handling for nested PL/SQL scalar types
if (isArgPLSQLScalar(dbType)) {
plsqlTable.setNestedType(getOraclePLSQLTypeForName(dbType));
} else {
plsqlTable.setNestedType(processTypeName(dbType));
}
} else {
if (plsqlCollectionType.isComposite()) {
DatabaseType enclosedType = plsqlCollectionType.getEnclosedType();
// may need to prepend package name
if (enclosedType.isPLSQLType()) {
dbType = ((PLSQLType) enclosedType).getParentType().getPackageName() + DOT + dbType;
targetClassName = getGeneratedJavaClassName(dbType);
} else {
// advanced JDBC
targetClassName = getGeneratedJavaClassName(dbType, defaultPackage);
}
processCompositeType(enclosedType, dbType);
}
plsqlTable.setNestedType(dbType);
}
// avoid double-processing
getProcessedTypes().add(plsqlTable.getName());
// generate an EmbeddableAccessor for this type
generateEmbeddable(plsqlTable, targetClassName);
return plsqlTable;
}
use of org.eclipse.persistence.tools.oracleddl.metadata.PLSQLType 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;
}
Aggregations