use of org.eclipse.persistence.tools.oracleddl.metadata.TableType 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.TableType 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.TableType in project eclipselink by eclipse-ee4j.
the class BaseDBWSBuilderHelper method buildDbArtifacts.
/**
* Gather table and procedure information based on TableOperation
* and ProcedureOperation. End result will be List<TableType>
* and List<ProcedureType>.
*/
public void buildDbArtifacts() {
List<TableOperationModel> tableOperations = new ArrayList<TableOperationModel>();
List<ProcedureOperationModel> procedureOperations = new ArrayList<ProcedureOperationModel>();
// its possible a builder might have pre-built tables
if (dbTables.size() == 0) {
// do Table operations first
for (OperationModel operation : dbwsBuilder.operations) {
if (operation.isTableOperation()) {
TableOperationModel tom = (TableOperationModel) operation;
tableOperations.add(tom);
if (tom.additionalOperations != null && tom.additionalOperations.size() > 0) {
for (OperationModel nestedOperation : tom.additionalOperations) {
if (nestedOperation.isProcedureOperation()) {
procedureOperations.add((ProcedureOperationModel) nestedOperation);
}
}
}
}
}
if (tableOperations.size() > 0) {
List<String> catalogPatterns = new ArrayList<String>();
List<String> schemaPatterns = new ArrayList<String>();
List<String> tableNamePatterns = new ArrayList<String>();
for (TableOperationModel tableOperation : tableOperations) {
catalogPatterns.add(tableOperation.getCatalogPattern());
schemaPatterns.add(tableOperation.getSchemaPattern());
tableNamePatterns.add(tableOperation.getTablePattern());
}
List<TableType> tables = loadTables(catalogPatterns, schemaPatterns, tableNamePatterns);
// if we didn't find any tables log a WARNING
if (tables == null || tables.isEmpty()) {
logNotFoundWarnings(NO_TABLE_MSG, schemaPatterns, catalogPatterns, tableNamePatterns);
} else {
// now assign tables to operations
for (TableType tableType : tables) {
for (TableOperationModel tableOperation : tableOperations) {
// figure out catalog(optional)/schema/tableName matching
boolean tableNameMatch = sqlMatch(tableOperation.getTablePattern(), tableType.getTableName());
boolean schemaNameMatch = sqlMatch(tableOperation.getSchemaPattern(), tableType.getSchema());
if (tableNameMatch && schemaNameMatch) {
String originalCatalogPattern = tableOperation.getCatalogPattern();
if (tableType.isDbTableType() && originalCatalogPattern != null) {
boolean catalogNameMatch = sqlMatch(originalCatalogPattern, ((DbTable) tableType).getCatalog());
if (catalogNameMatch) {
tableOperation.getDbTables().add(tableType);
}
} else {
tableOperation.getDbTables().add(tableType);
}
}
}
}
dbTables.addAll(tables);
}
}
}
// it's possible a builder might have pre-built procedures
if (dbStoredProcedures.size() == 0) {
for (OperationModel operation : dbwsBuilder.operations) {
if (operation.isProcedureOperation()) {
procedureOperations.add((ProcedureOperationModel) operation);
}
}
if (procedureOperations.size() > 0) {
List<String> catalogPatterns = new ArrayList<String>();
List<String> schemaPatterns = new ArrayList<String>();
List<String> procedureNamePatterns = new ArrayList<String>();
for (ProcedureOperationModel procedureOperation : procedureOperations) {
catalogPatterns.add(procedureOperation.getCatalogPattern());
schemaPatterns.add(procedureOperation.getSchemaPattern());
procedureNamePatterns.add(procedureOperation.getProcedurePattern());
}
List<ProcedureType> procedures = loadProcedures(catalogPatterns, schemaPatterns, procedureNamePatterns);
// if we didn't find any procs/funcs log a WARNING
if (procedures == null || procedures.isEmpty()) {
logNotFoundWarnings(NO_PROC_MSG, schemaPatterns, catalogPatterns, procedureNamePatterns);
} else {
// now assign procedures to operations
for (ProcedureType procedureType : procedures) {
for (ProcedureOperationModel procedureOperation : procedureOperations) {
boolean procedureNameMatch = sqlMatch(procedureOperation.getProcedurePattern(), procedureType.getProcedureName());
boolean schemaNameMatch = true;
boolean catalogNameMatch = true;
if (procedureNameMatch) {
String originalSchemaPattern = procedureOperation.getSchemaPattern();
if (originalSchemaPattern != null) {
schemaNameMatch = sqlMatch(originalSchemaPattern, procedureType.getSchema());
}
String originalCatalogPattern = procedureOperation.getCatalogPattern();
if (originalCatalogPattern != null) {
catalogNameMatch = sqlMatch(originalCatalogPattern, procedureType.getCatalogName());
}
}
if (procedureNameMatch && schemaNameMatch && catalogNameMatch) {
procedureOperation.getDbStoredProcedures().add(procedureType);
}
}
}
dbStoredProcedures.addAll(procedures);
}
}
}
}
use of org.eclipse.persistence.tools.oracleddl.metadata.TableType in project eclipselink by eclipse-ee4j.
the class TypeRowTypeTestSuite method setUp.
@SuppressWarnings({ "unchecked", "rawtypes" })
@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_EMPTYPE_TABLE, ddlDebug);
runDdl(conn, CREATE_EMPREC_TYPE, ddlDebug);
runDdl(conn, CREATE_EMP_RECORD_PACKAGE, ddlDebug);
runDdl(conn, CREATE_ROWTYPE_TEST_PACKAGE, ddlDebug);
}
String schema = System.getProperty(DATABASE_USERNAME_KEY, DEFAULT_DATABASE_USERNAME);
List<String> procedurePatterns = new ArrayList<String>();
procedurePatterns.add("get_emp_record");
procedurePatterns.add("testProc");
procedurePatterns.add("testFunc");
// use DatabaseTypeBuilder to generate a lists of TableTypes and PackageTypes
dbTypeBuilder = new DatabaseTypeBuilder();
try {
// process the table
List<TableType> dbTables = dbTypeBuilder.buildTables(conn, schema, "EMPTYPEX");
// process the "EMP_RECORD_PACKAGE" package
List<ProcedureType> empRecPkgProcedures = new ArrayList<ProcedureType>();
List<PLSQLPackageType> packages = dbTypeBuilder.buildPackages(conn, schema, "EMP_RECORD_PACKAGE");
for (PLSQLPackageType pkgType : packages) {
// now get the desired procedures/functions from the processed package
for (ProcedureType procType : pkgType.getProcedures()) {
if (procedurePatterns.contains(procType.getProcedureName())) {
empRecPkgProcedures.add(procType);
}
}
}
// process the "RTYPE_PKG" package
List<ProcedureType> rtypePkgProcedures = new ArrayList<ProcedureType>();
packages = dbTypeBuilder.buildPackages(conn, schema, "RTYPE_PKG");
for (PLSQLPackageType pkgType : packages) {
// now get the desired procedures/functions from the processed package
for (ProcedureType procType : pkgType.getProcedures()) {
if (procedurePatterns.contains(procType.getProcedureName())) {
rtypePkgProcedures.add(procType);
}
}
}
// combine tables and procedures to pass to the metadata generator
dbTypes = new ArrayList();
dbTypes.addAll(dbTables);
dbTypes.addAll(empRecPkgProcedures);
dbTypes.addAll(rtypePkgProcedures);
} catch (ParseException e) {
e.printStackTrace();
fail("An unexpected exception occurred: " + e.getMessage());
}
}
use of org.eclipse.persistence.tools.oracleddl.metadata.TableType 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;
}
Aggregations