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/Dynamic/Design RuntimeDefinition"

(New page: == Dynamic Persistence Design: Create/Modify/Remove Dynamic Types == Dynamic persistence also allows for the creation of the dynamic types during the runtime execution of an application. ...)
 
Line 3: Line 3:
 
Dynamic persistence also allows for the creation of the dynamic types during the runtime execution of an application. This is generally in response to an administrator user defining a new type with its properties and associations and the requesting the type to be added and optionally its schema to be created on the database. This is accomplished in this design using the [http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/incubator/dynamic/branches/1.1.0/org.eclipse.persistence.core.dynamic/src/org/eclipse/persistence/dynamic/EntityTypeBuilder.java EntityTypeBuilder] which functions as a factory for building or modifying a dynamic type.
 
Dynamic persistence also allows for the creation of the dynamic types during the runtime execution of an application. This is generally in response to an administrator user defining a new type with its properties and associations and the requesting the type to be added and optionally its schema to be created on the database. This is accomplished in this design using the [http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/incubator/dynamic/branches/1.1.0/org.eclipse.persistence.core.dynamic/src/org/eclipse/persistence/dynamic/EntityTypeBuilder.java EntityTypeBuilder] which functions as a factory for building or modifying a dynamic type.
  
=== EntityTypeBuilder API ==
+
=== EntityTypeBuilder API ===
  
 
The API on the EntityTypeBuilder allows a type to be wrapped and extended. The wrapped type can then be added to a session.
 
The API on the EntityTypeBuilder allows a type to be wrapped and extended. The wrapped type can then be added to a session.

Revision as of 14:31, 10 September 2009

Dynamic Persistence Design: Create/Modify/Remove Dynamic Types

Dynamic persistence also allows for the creation of the dynamic types during the runtime execution of an application. This is generally in response to an administrator user defining a new type with its properties and associations and the requesting the type to be added and optionally its schema to be created on the database. This is accomplished in this design using the EntityTypeBuilder which functions as a factory for building or modifying a dynamic type.

EntityTypeBuilder API

The API on the EntityTypeBuilder allows a type to be wrapped and extended. The wrapped type can then be added to a session.

Creating new Types

Here is a simple example using the native ORM API:

public void entityTypeFromDescriptor() throws Exception {
    EntityTypeImpl entityType = buildMyEntityType();
 
    assertEquals(MyEntity.class, entityType.getJavaClass());
 
    DatabaseSession session = new Project(buildDatabaseLogin()).createDatabaseSession();
    session.getSessionLog().setLevel(SessionLog.FINE);
    session.login();
 
    session.addDescriptor(entityType.getDescriptor());
    new SchemaManager(session).replaceDefaultTables();
 
    DynamicEntity entity = entityType.newInstance();
    entity.set("id", 1);
    entity.set("name", "Name");
 
    session.insertObject(entity);
 
    session.logout();
 
}
 
private EntityTypeImpl buildMyEntityType() {
    EntityTypeBuilder factory = new EntityTypeBuilder(MyEntity.class, null, "MY_ENTITY");
    factory.setPrimaryKeyFields("ID");
    factory.addDirectMapping("id", int.class, "ID");
    factory.addDirectMapping("name", String.class, "NAME");
 
    return (EntityTypeImpl) factory.getType();
}

A more comprehensive example is available here

Modifying Existing Types

Removing Existing Types

Back to the top