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

EclipseLink/Development/Dynamic/Design RuntimeDefinition

< EclipseLink‎ | Development‎ | Dynamic
Revision as of 13:26, 24 September 2009 by Michael.norman.oracle.com (Talk | contribs) (Modifying Existing Types)

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

TBD

Removing Existing Types

Back to the top