Skip to main content

Notice: This Wiki is now read only and edits are no longer 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"

(Removing Existing Types)
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
<css>
 +
  .source-java5 {border-style: solid;}
 +
</css>
 
== Dynamic Persistence Design: Create/Modify/Remove Dynamic Types ==
 
== Dynamic Persistence Design: Create/Modify/Remove Dynamic Types ==
  
Line 11: Line 14:
 
Here is a simple example using the native ORM API:
 
Here is a simple example using the native ORM API:
  
<source lang="java">
+
<source lang="java5">
 
public void entityTypeFromDescriptor() throws Exception {
 
public void entityTypeFromDescriptor() throws Exception {
 
     EntityTypeImpl entityType = buildMyEntityType();
 
     EntityTypeImpl entityType = buildMyEntityType();
Line 47: Line 50:
  
 
=== Modifying Existing Types ===
 
=== Modifying Existing Types ===
 
+
TBD
  
 
=== Removing Existing Types ===
 
=== Removing Existing Types ===
 +
Is this just 'de-activating' the descriptor?
 +
What happens to 'live' objects?

Latest revision as of 13:27, 24 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

TBD

Removing Existing Types

Is this just 'de-activating' the descriptor? What happens to 'live' objects?

Back to the top