-
Notifications
You must be signed in to change notification settings - Fork 3
The Entity Manager
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();
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);
There are a number of global configuration options that can be passed to the EntityManager.
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";
You can specify a default fetch mode in the configuration:
// Eager fetching
configuration.fetchMode = FetchMode.EAGER;
// Lazy fetching
configuration.fetchMode = FetchMode.LAZY;
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;
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;
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;