Skip to content

The Entity Manager

ccapndave edited this page Feb 23, 2011 · 4 revisions

The EntityManager is the central access point for ORM functionality provided by Flextrine. It is used to manage the persistence of your object and to query for objects from the database. This class is a singleton which means that there is only ever one instance of the EntityManager in existence. To get a reference to this instance use the following code:

var em:EntityManager = EntityManager.getInstance();

Configuring the Entity Manager

To configure the EntityManager to point to your Flextrine server-side application set the configuration using the following code. Since EntityManager is a singleton you only need to do this once in your Flex application.

var configuration:Configuration = new Configuration();
configuration.gateway = "http://localhost/flextrine/gateway.php";
em.setConfiguration(configuration);

Other configuration options

There are a number of global configuration options that can be passed to the EntityManager.

Using a different Flextrine application

You can specify that Flextrine should communicate with a server-side application other than the one defined as a default in php/config/config.yml by adding an app GET parameter to the gateway url.

configuration.gateway = "http://localhost/flextrine/gateway.php?app=application_name";

Setting the default fetch mode

You can specify a default fetch mode in the configuration:

// Eager fetching
configuration.fetchMode = FetchMode.EAGER;

// Lazy fetching
configuration.fetchMode = FetchMode.LAZY;

Enabling and disabling on-demand loading of collections and entities

You can specify whether lazily loaded collections and/or entities load themselves when accessed. See On-demand loading for more details.

configuration.loadEntitiesOnDemand = false;
configuration.loadCollectionsOnDemand= false;

Enabling and disabling em.rollback()

In order to save memory you can disable the rollback feature in the global configuration. This means that EntityManager::rollback() will not be available.

configuration.enableRollback= false;

Setting the entityTimeToLive

The global entityTimeToLive value is used to control garbage collection. See Garbage collection for more details.

// Disable garbage collection in repositories
configuration.entityTimeToLive = -1;

// Set the garbage collection delay to 5 seconds (default)
configuration.entityTimeToLive = 5000;

// Set the garbage collection delay to 1 minute
configuration.entityTimeToLive = 60000;