use of org.eclipse.persistence.tools.oracleddl.metadata.PLSQLPackageType 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.PLSQLPackageType in project eclipselink by eclipse-ee4j.
the class OracleHelper method loadProcedures.
/**
* Generates a {@code List<ProcedureType>} based on a given set of patterns.
*/
@Override
protected List<ProcedureType> loadProcedures(List<String> catalogPatterns, List<String> schemaPatterns, List<String> procedureNamePatterns) {
List<ProcedureType> allProcsAndFuncs = new ArrayList<ProcedureType>();
List<String> topLevelSchemaPatterns = new ArrayList<String>();
List<String> topLevelProcedureNamePatterns = new ArrayList<String>();
Map<String, Set<String>> packagePatterns = new HashMap<String, Set<String>>();
for (int i = 0, len = catalogPatterns.size(); i < len; i++) {
String catalogPattern = catalogPatterns.get(i);
String schemaPattern = schemaPatterns.get(i);
if (schemaPattern == null) {
schemaPattern = dbwsBuilder.getUsername().toUpperCase();
}
if (catalogPattern == null || catalogPattern.length() == 0 || TOPLEVEL.equals(catalogPattern)) {
topLevelSchemaPatterns.add(schemaPattern);
topLevelProcedureNamePatterns.add(procedureNamePatterns.get(i));
} else {
Set<String> packageNames = packagePatterns.get(schemaPattern);
if (packageNames == null) {
packageNames = new HashSet<String>();
packagePatterns.put(schemaPattern, packageNames);
}
packageNames.add(catalogPattern);
}
}
if (topLevelProcedureNamePatterns.size() > 0) {
try {
List<ProcedureType> topLevelProcedures = dtBuilder.buildProcedures(dbwsBuilder.getConnection(), topLevelSchemaPatterns, topLevelProcedureNamePatterns);
if (topLevelProcedures != null && topLevelProcedures.size() > 0) {
allProcsAndFuncs.addAll(topLevelProcedures);
}
} catch (ParseException e) {
dbwsBuilder.logMessage(Level.WARNING, e.getMessage());
}
try {
List<FunctionType> topLevelFunctions = dtBuilder.buildFunctions(dbwsBuilder.getConnection(), topLevelSchemaPatterns, topLevelProcedureNamePatterns);
if (topLevelFunctions != null && topLevelFunctions.size() > 0) {
allProcsAndFuncs.addAll(topLevelFunctions);
}
} catch (ParseException e) {
dbwsBuilder.logMessage(Level.WARNING, e.getMessage());
}
}
if (packagePatterns.size() > 0) {
try {
// unravel map
List<String> schemaPats = new ArrayList<String>();
List<String> packagePats = new ArrayList<String>();
for (Map.Entry<String, Set<String>> entry : packagePatterns.entrySet()) {
String schema = entry.getKey();
for (String packageName : entry.getValue()) {
schemaPats.add(schema);
packagePats.add(packageName);
}
}
List<PLSQLPackageType> packages = dtBuilder.buildPackages(dbwsBuilder.getConnection(), schemaPats, packagePats);
if (packages == null || packages.isEmpty()) {
logPackageNotFoundWarnings(NO_PKG_MSG, schemaPats, packagePats);
} else {
for (PLSQLPackageType pakage : packages) {
// check DDL generation
ShadowDDLGenerator ddlGenerator = new ShadowDDLGenerator(pakage);
dbwsBuilder.getTypeDDL().addAll(ddlGenerator.getAllCreateDDLs());
dbwsBuilder.getTypeDropDDL().addAll(ddlGenerator.getAllDropDDLs());
// check for overloading
Map<String, List<ProcedureType>> overloadMap = new HashMap<String, List<ProcedureType>>();
List<ProcedureType> procedures = pakage.getProcedures();
for (ProcedureType procedure : procedures) {
String procedureName = procedure.getProcedureName();
List<ProcedureType> multipleProcedures = overloadMap.get(procedureName);
if (multipleProcedures == null) {
multipleProcedures = new ArrayList<ProcedureType>();
overloadMap.put(procedureName, multipleProcedures);
}
multipleProcedures.add(procedure);
}
for (List<ProcedureType> procs : overloadMap.values()) {
if (procs.size() > 1) {
for (int i = 0, len = procs.size(); i < len; i++) {
procs.get(i).setOverload(i);
}
}
}
// Check against procedureNamePatterns
String tmp = buildNamePatternsList(procedureNamePatterns);
for (ProcedureType procedure : procedures) {
if (sqlMatch(tmp, procedure.getProcedureName())) {
allProcsAndFuncs.add(procedure);
}
}
}
}
} catch (ParseException e) {
dbwsBuilder.logMessage(Level.WARNING, e.getMessage());
}
}
return allProcsAndFuncs.isEmpty() ? null : allProcsAndFuncs;
}
use of org.eclipse.persistence.tools.oracleddl.metadata.PLSQLPackageType 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.PLSQLPackageType 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.PLSQLPackageType in project eclipselink by eclipse-ee4j.
the class PLSQLRecordTypeTestSuite method setUp.
@SuppressWarnings({ "rawtypes", "unchecked" })
@BeforeClass
public static void setUp() throws ClassNotFoundException, SQLException {
AllTests.setUp();
String ddlCreateProp = System.getProperty(DATABASE_DDL_CREATE_KEY, DEFAULT_DATABASE_DDL_CREATE);
if ("true".equalsIgnoreCase(ddlCreateProp)) {
ddlCreate = true;
}
String ddlDropProp = System.getProperty(DATABASE_DDL_DROP_KEY, DEFAULT_DATABASE_DDL_DROP);
if ("true".equalsIgnoreCase(ddlDropProp)) {
ddlDrop = true;
}
String ddlDebugProp = System.getProperty(DATABASE_DDL_DEBUG_KEY, DEFAULT_DATABASE_DDL_DEBUG);
if ("true".equalsIgnoreCase(ddlDebugProp)) {
ddlDebug = true;
}
if (ddlCreate) {
runDdl(conn, CREATE_A_PHONE_TYPE, ddlDebug);
runDdl(conn, CREATE_A_PHONE_TYPE_TABLE, ddlDebug);
runDdl(conn, CREATE_A_PHONE_TYPE_VARRAY, ddlDebug);
runDdl(conn, CREATE_A_CONTACT_TYPE, ddlDebug);
runDdl(conn, CREATE_PACKAGE2_PACKAGE, ddlDebug);
runDdl(conn, CREATE_PACKAGE2_EMPREC_TYPE, ddlDebug);
}
String schema = System.getProperty(DATABASE_USERNAME_KEY, DEFAULT_DATABASE_USERNAME);
List<String> procedurePatterns = new ArrayList<String>();
procedurePatterns.add("COPYRECORD");
procedurePatterns.add("COPYRECORD_FUNC");
procedurePatterns.add("COPYCOMPLEXRECORD");
procedurePatterns.add("COPYCOMPLEXRECORD_FUNC");
procedurePatterns.add("COPYMORECOMPLEXRECORD_FUNC");
procedurePatterns.add("COPYSUPERCOMPLEXRECORD");
// use DatabaseTypeBuilder to generate a list of PackageTypes
dbTypeBuilder = new DatabaseTypeBuilder();
dbProcedures = new ArrayList();
try {
// process the package
List<PLSQLPackageType> packages = dbTypeBuilder.buildPackages(conn, schema, "PACKAGE2");
for (PLSQLPackageType pkgType : packages) {
// now get the desired procedures/functions from the processed package
for (ProcedureType procType : pkgType.getProcedures()) {
if (procedurePatterns.contains(procType.getProcedureName())) {
dbProcedures.add(procType);
}
}
}
} catch (ParseException e) {
e.printStackTrace();
}
}
Aggregations