use of org.eclipse.persistence.tools.oracleddl.metadata.DatabaseType in project eclipselink by eclipse-ee4j.
the class JDBCHelper method buildProcedureOperation.
@Override
public void buildProcedureOperation(ProcedureOperationModel procedureOperationModel) {
String name = procedureOperationModel.getName();
boolean isMySQL = dbwsBuilder.getDatabasePlatform().getClass().getName().contains("MySQL");
for (ProcedureType storedProcedure : procedureOperationModel.getDbStoredProcedures()) {
StringBuilder sb = new StringBuilder();
if (name == null || name.length() == 0) {
if (storedProcedure.getOverload() > 0) {
sb.append(storedProcedure.getOverload());
sb.append('_');
}
if (storedProcedure.getCatalogName() != null && storedProcedure.getCatalogName().length() > 0) {
sb.append(storedProcedure.getCatalogName());
sb.append('_');
}
if (storedProcedure.getSchema() != null && storedProcedure.getSchema().length() > 0) {
sb.append(storedProcedure.getSchema());
sb.append('_');
}
sb.append(storedProcedure.getProcedureName());
} else {
sb.append(name);
}
QueryOperation qo = new QueryOperation();
qo.setName(sb.toString());
QueryHandler qh;
if (storedProcedure.isFunctionType()) {
qh = new StoredFunctionQueryHandler();
} else {
qh = new StoredProcedureQueryHandler();
}
sb = new StringBuilder();
if (!isMySQL) {
if (storedProcedure.getCatalogName() != null && storedProcedure.getCatalogName().length() > 0) {
sb.append(storedProcedure.getCatalogName());
sb.append('.');
}
}
if (storedProcedure.getSchema() != null && storedProcedure.getSchema().length() > 0) {
sb.append(storedProcedure.getSchema());
sb.append('.');
}
sb.append(storedProcedure.getProcedureName());
((StoredProcedureQueryHandler) qh).setName(sb.toString());
dbwsBuilder.logMessage(FINEST, "Building QueryOperation for " + sb.toString());
// before assigning queryHandler, check for named query in OR project
List<DatabaseQuery> queries = dbwsBuilder.getOrProject().getQueries();
if (queries.size() > 0) {
for (DatabaseQuery q : queries) {
if (q.getName().equals(qo.getName())) {
qh = new NamedQueryHandler();
((NamedQueryHandler) qh).setName(qo.getName());
}
}
}
qo.setQueryHandler(qh);
String returnType = procedureOperationModel.getReturnType();
boolean isCollection = procedureOperationModel.isCollection();
boolean isSimpleXMLFormat = procedureOperationModel.isSimpleXMLFormat();
Result result = null;
if (storedProcedure.isFunctionType()) {
FunctionType storedFunction = (FunctionType) storedProcedure;
DatabaseType rarg = storedFunction.getReturnArgument();
if (rarg.getTypeName().contains("CURSOR")) {
result = new CollectionResult();
result.setType(SXF_QNAME_CURSOR);
} else {
result = new Result();
int rargJdbcType = Util.getJDBCTypeFromTypeName(rarg.getTypeName());
switch(rargJdbcType) {
case STRUCT:
case ARRAY:
case OTHER:
if (returnType != null) {
result.setType(buildCustomQName(returnType, dbwsBuilder));
} else {
result.setType(ANY_QNAME);
}
break;
default:
result.setType(getXMLTypeFromJDBCType(rargJdbcType));
break;
}
}
} else {
// if user overrides returnType, assume they're right
if (returnType != null) {
result = new Result();
result.setType(buildCustomQName(returnType, dbwsBuilder));
} else {
if (isCollection) {
result = new CollectionResult();
if (isSimpleXMLFormat) {
result.setType(SXF_QNAME_CURSOR);
}
} else {
result = new Result();
result.setType(SXF_QNAME);
}
}
}
if (procedureOperationModel.getBinaryAttachment()) {
Attachment attachment = new Attachment();
attachment.setMimeType("application/octet-stream");
result.setAttachment(attachment);
}
for (ArgumentType arg : storedProcedure.getArguments()) {
String argName = arg.getArgumentName();
if (argName != null) {
ProcedureArgument pa = null;
Parameter parm = null;
ArgumentTypeDirection direction = arg.getDirection();
QName xmlType = null;
switch(Util.getJDBCTypeFromTypeName(arg.getTypeName())) {
case STRUCT:
case ARRAY:
case OTHER:
String typeString = nct.generateSchemaAlias(arg.getTypeName());
xmlType = buildCustomQName(typeString, dbwsBuilder);
break;
default:
xmlType = getXMLTypeFromJDBCType(Util.getJDBCTypeFromTypeName(arg.getTypeName()));
break;
}
if (direction == IN) {
parm = new Parameter();
parm.setName(argName);
parm.setType(xmlType);
pa = new ProcedureArgument();
pa.setName(argName);
pa.setParameterName(argName);
if (qh instanceof StoredProcedureQueryHandler) {
((StoredProcedureQueryHandler) qh).getInArguments().add(pa);
}
} else {
// the first OUT/INOUT arg determines singleResult vs. collectionResult
pa = new ProcedureOutputArgument();
ProcedureOutputArgument pao = (ProcedureOutputArgument) pa;
pao.setName(argName);
pao.setParameterName(argName);
if (arg.getTypeName().contains("CURSOR") && returnType == null) {
// if user overrides returnType, assume they're right
pao.setResultType(SXF_QNAME_CURSOR);
if (result == null) {
result = new CollectionResult();
result.setType(SXF_QNAME_CURSOR);
}
} else {
// Hmm, multiple OUT's gonna be a problem - later!
if (returnType != null && !isSimpleXMLFormat) {
xmlType = qNameFromString("{" + dbwsBuilder.getTargetNamespace() + "}" + returnType, dbwsBuilder.getSchema());
}
pao.setResultType(xmlType);
if (result == null) {
if (isCollection) {
result = new CollectionResult();
} else {
result = new Result();
}
result.setType(xmlType);
}
}
if (direction == INOUT) {
parm = new Parameter();
parm.setName(argName);
parm.setType(xmlType);
result.setType(xmlType);
// use of INOUT precludes SimpleXMLFormat
isSimpleXMLFormat = false;
if (qh instanceof StoredProcedureQueryHandler) {
((StoredProcedureQueryHandler) qh).getInOutArguments().add(pao);
}
} else {
if (qh instanceof StoredProcedureQueryHandler) {
((StoredProcedureQueryHandler) qh).getOutArguments().add(pao);
}
}
}
if (parm != null) {
qo.getParameters().add(parm);
}
}
}
handleSimpleXMLFormat(isSimpleXMLFormat, result, procedureOperationModel);
qo.setResult(result);
dbwsBuilder.getXrServiceModel().getOperations().put(qo.getName(), qo);
}
finishProcedureOperation();
}
use of org.eclipse.persistence.tools.oracleddl.metadata.DatabaseType 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.DatabaseType 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.DatabaseType 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.DatabaseType 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