Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EclipseLink/Development/DBWS/MetadataGenerationFromDDLMetaModel"

(PL/SQL Stored Functions/Procedures)
Line 2: Line 2:
 
The EclipseLink DBWS design time component (a.k.a. DBWSBuilder) generates OR and OX projects for use by the runtime component - these project instances are built using DDLParser generated meta-model objects.  Since EclipseLink 2.5, DBWS generates and writes out JAXB and JPA metadata ([http://wiki.eclipse.org/EclipseLink/Development/DBWS/MetadataSupport DBWS Metadata Support]) based on the OR/OX projects.  When considering JAXB/JPA metadata generation consolidation among various components, it would make sense to have the ability to generate metadata directly from the DDLParser generated metamodel, then bootstrap DBWS builder, JPA-RS, etc. from this metadata.  This would allow the DDLParser and metadata generation piece proposed here to be standalone components, available to whomever requires this generated metadata.
 
The EclipseLink DBWS design time component (a.k.a. DBWSBuilder) generates OR and OX projects for use by the runtime component - these project instances are built using DDLParser generated meta-model objects.  Since EclipseLink 2.5, DBWS generates and writes out JAXB and JPA metadata ([http://wiki.eclipse.org/EclipseLink/Development/DBWS/MetadataSupport DBWS Metadata Support]) based on the OR/OX projects.  When considering JAXB/JPA metadata generation consolidation among various components, it would make sense to have the ability to generate metadata directly from the DDLParser generated metamodel, then bootstrap DBWS builder, JPA-RS, etc. from this metadata.  This would allow the DDLParser and metadata generation piece proposed here to be standalone components, available to whomever requires this generated metadata.
  
== JPA Metadata Generation ==
+
== Basic DDLParser Usage ==
The [http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api EclipseLink JPA meta-model] will be utilized to generate the JPA metadata.  The proposed <code>JPAMetadataGenerator</code> class will be responsible for building an instance of <code>org.eclipse.persistence.internal.jpa.metadata.xml.XMLEntityMappings</code>.  The entity mapping writer class (<code>org.eclipse.persistence.internal.jpa.metadata.xml.XMLEntityMappingsWriter</code>) will then be used to marshal the generated metadata.
+
 
+
=== Basic DDLParser Usage ===
+
 
The <code>DatabaseTypeBuilder</code> class (part of the DDLParser package) is responsible for generating the required statement to be used to retrieve the DDL from the database, then parsing the returned DDL into the meta-model objects.  The type builder can build TableTypes, ProcedureTypes, and PLSQLPackageTypes based on user provided schema(s) and table/procedure/package name(s), and a database connection.  The build methods can take a single schema & table/procedure/package name, or lists of each when multiple artifacts are to be parsed.
 
The <code>DatabaseTypeBuilder</code> class (part of the DDLParser package) is responsible for generating the required statement to be used to retrieve the DDL from the database, then parsing the returned DDL into the meta-model objects.  The type builder can build TableTypes, ProcedureTypes, and PLSQLPackageTypes based on user provided schema(s) and table/procedure/package name(s), and a database connection.  The build methods can take a single schema & table/procedure/package name, or lists of each when multiple artifacts are to be parsed.
  
==== Table ====
+
=== Table ===
 
<source lang="java">
 
<source lang="java">
 
// use DatabaseTypeBuilder to generate a list of TableTypes
 
// use DatabaseTypeBuilder to generate a list of TableTypes
Line 20: Line 17:
 
</source>
 
</source>
  
==== Top-level StoredProcedure ====
+
=== Top-level StoredProcedure ===
 
<source lang="java">
 
<source lang="java">
 
// use DatabaseTypeBuilder to generate a list of ProcedureTypes
 
// use DatabaseTypeBuilder to generate a list of ProcedureTypes
Line 32: Line 29:
 
</source>
 
</source>
  
==== Top-level StoredFunction ====
+
=== Top-level StoredFunction ===
 
<source lang="java">
 
<source lang="java">
 
// use DatabaseTypeBuilder to generate a list of FunctionTypes
 
// use DatabaseTypeBuilder to generate a list of FunctionTypes
Line 44: Line 41:
 
</source>
 
</source>
  
==== PL/SQL Stored Functions/Procedures ====
+
=== PL/SQL Stored Functions/Procedures ===
 
Retrieving meta-model instances for PL/SQL procedures and functions involves retrieving the PL/SQL package meta-model, then getting the procedure and/or function objects from it.
 
Retrieving meta-model instances for PL/SQL procedures and functions involves retrieving the PL/SQL package meta-model, then getting the procedure and/or function objects from it.
  
Line 76: Line 73:
 
}
 
}
 
</source>
 
</source>
 +
 +
== JPA Metadata Generation ==
 +
The [http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api EclipseLink JPA meta-model] will be utilized to generate the JPA metadata.  The proposed <code>JPAMetadataGenerator</code> class will be responsible for building an instance of <code>org.eclipse.persistence.internal.jpa.metadata.xml.XMLEntityMappings</code>.  The entity mapping writer class (<code>org.eclipse.persistence.internal.jpa.metadata.xml.XMLEntityMappingsWriter</code>) will then be used to marshal the generated metadata.
  
 
== JAXB Metadata Generation ==
 
== JAXB Metadata Generation ==

Revision as of 10:52, 17 July 2013

Generating JAXB and JPA Metadata From DDL Parser Meta-model

The EclipseLink DBWS design time component (a.k.a. DBWSBuilder) generates OR and OX projects for use by the runtime component - these project instances are built using DDLParser generated meta-model objects. Since EclipseLink 2.5, DBWS generates and writes out JAXB and JPA metadata (DBWS Metadata Support) based on the OR/OX projects. When considering JAXB/JPA metadata generation consolidation among various components, it would make sense to have the ability to generate metadata directly from the DDLParser generated metamodel, then bootstrap DBWS builder, JPA-RS, etc. from this metadata. This would allow the DDLParser and metadata generation piece proposed here to be standalone components, available to whomever requires this generated metadata.

Basic DDLParser Usage

The DatabaseTypeBuilder class (part of the DDLParser package) is responsible for generating the required statement to be used to retrieve the DDL from the database, then parsing the returned DDL into the meta-model objects. The type builder can build TableTypes, ProcedureTypes, and PLSQLPackageTypes based on user provided schema(s) and table/procedure/package name(s), and a database connection. The build methods can take a single schema & table/procedure/package name, or lists of each when multiple artifacts are to be parsed.

Table

// use DatabaseTypeBuilder to generate a list of TableTypes
DatabaseTypeBuilder dbTypeBuilder = new DatabaseTypeBuilder();
try {
    List<TableType> dbTables = dbTypeBuilder.buildTables(conn, "SCOTT", "EMPLOYEE_TABLE");
    ...
} catch (ParseException e) {
    // handle exception
}

Top-level StoredProcedure

// use DatabaseTypeBuilder to generate a list of ProcedureTypes
DatabaseTypeBuilder dbTypeBuilder = new DatabaseTypeBuilder();
try {
    List<ProcedureType> dbProcedures = dbTypeBuilder.buildProcedures(conn, "TOPLEVEL", "GetAllEmployees");
    ...
} catch (ParseException e) {
    // handle exception
}

Top-level StoredFunction

// use DatabaseTypeBuilder to generate a list of FunctionTypes
DatabaseTypeBuilder dbTypeBuilder = new DatabaseTypeBuilder();
try {
    List<FunctionType> dbFunctions = dbTypeBuilder.buildFunctions(conn, "TOPLEVEL", "GetEmployeeById");
    ...
} catch (ParseException e) {
    // handle exception
}

PL/SQL Stored Functions/Procedures

Retrieving meta-model instances for PL/SQL procedures and functions involves retrieving the PL/SQL package meta-model, then getting the procedure and/or function objects from it.

// add desired PL/SQL stored function/procedure names
List<String> procedurePatterns = new ArrayList<String>();
// PL/SQL stored procedures
procedurePatterns.add("COPYTABLE");
procedurePatterns.add("COPYPHONECOLLECTION");  
// PL/SQL stored functions
procedurePatterns.add("CREATETABLE");
procedurePatterns.add("GETALLTABLES");  
 
// use DatabaseTypeBuilder to generate a list of PLSQLPackageTypes
DatabaseTypeBuilder dbTypeBuilder = new DatabaseTypeBuilder();
try {
    List<ProcedureType> dbProcedures = new ArrayList<ProcedureType>();
    // process the package
    List<PLSQLPackageType> packages = dbTypeBuilder.buildPackages(conn, "SCOTT", "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) {
    // handle exception
}

JPA Metadata Generation

The EclipseLink JPA meta-model will be utilized to generate the JPA metadata. The proposed JPAMetadataGenerator class will be responsible for building an instance of org.eclipse.persistence.internal.jpa.metadata.xml.XMLEntityMappings. The entity mapping writer class (org.eclipse.persistence.internal.jpa.metadata.xml.XMLEntityMappingsWriter) will then be used to marshal the generated metadata.

JAXB Metadata Generation

  • TBD

Open Issues

  1. What should the default package name for generated Entities (or anything not in a PL/SQL package) be? Ideally the user would be permitted to set this on the generator.
  2. Query names - what would be the default name for a query generated from a stored procedure, etc.? Perhaps the user could provide a Map of query names > procedure names.
  3. For non-Oracle databases, JDBCHelper returns meta-model objects that extend the DDLParser meta-model - should this functionality be taken into consideration here as well?
  4. Automatic CRUD operation generation for tables; by default, DBWS generates CRUD query operations for a given database table - is this something we should include by default? Perhaps it could be configurable.

Back to the top