Search in sources :

Example 1 with ValueInjector

use of org.apache.cayenne.exp.ValueInjector in project cayenne by apache.

the class BaseContext method injectInitialValue.

/**
 * If ObjEntity qualifier is set, asks it to inject initial value to an
 * object. Also performs all Persistent initialization operations
 */
protected void injectInitialValue(Object obj) {
    // must follow this exact order of property initialization per CAY-653,
    // i.e. have
    // the id and the context in place BEFORE setPersistence is called
    Persistent object = (Persistent) obj;
    object.setObjectContext(this);
    object.setPersistenceState(PersistenceState.NEW);
    GraphManager graphManager = getGraphManager();
    synchronized (graphManager) {
        graphManager.registerNode(object.getObjectId(), object);
        graphManager.nodeCreated(object.getObjectId());
    }
    ObjEntity entity;
    try {
        entity = getEntityResolver().getObjEntity(object.getClass());
    } catch (CayenneRuntimeException ex) {
        // ObjEntity cannot be fetched, ignored
        entity = null;
    }
    if (entity != null) {
        if (entity.getDeclaredQualifier() instanceof ValueInjector) {
            ((ValueInjector) entity.getDeclaredQualifier()).injectValue(object);
        }
    }
    // invoke callbacks
    getEntityResolver().getCallbackRegistry().performCallbacks(LifecycleEvent.POST_ADD, object);
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) GraphManager(org.apache.cayenne.graph.GraphManager) ValueInjector(org.apache.cayenne.exp.ValueInjector)

Aggregations

ValueInjector (org.apache.cayenne.exp.ValueInjector)1 GraphManager (org.apache.cayenne.graph.GraphManager)1 ObjEntity (org.apache.cayenne.map.ObjEntity)1