Search in sources :

Example 1 with SerializedObjectPolicy

use of org.eclipse.persistence.descriptors.SerializedObjectPolicy in project eclipselink by eclipse-ee4j.

the class AbstractSerializedObjectPolicy method initializeField.

@Override
public void initializeField(AbstractSession session) {
    if (this.field == null) {
        session.getIntegrityChecker().handleError(DescriptorException.serializedObjectPolicyFieldNotSet(this.descriptor));
        return;
    }
    if (this.descriptor.isChildDescriptor()) {
        SerializedObjectPolicy parentPolicy = this.descriptor.getInheritancePolicy().getParentDescriptor().getSerializedObjectPolicy();
        if (parentPolicy != null && parentPolicy.getField() == this.field) {
            return;
        }
    }
    this.field = this.descriptor.buildField(this.field);
    this.descriptor.getFields().add(this.field);
}
Also used : SerializedObjectPolicy(org.eclipse.persistence.descriptors.SerializedObjectPolicy)

Example 2 with SerializedObjectPolicy

use of org.eclipse.persistence.descriptors.SerializedObjectPolicy in project eclipselink by eclipse-ee4j.

the class Customizer method customize.

@Override
public void customize(Session session) throws Exception {
    String sessionName = session.getName();
    Integer numberOfCalls = (Integer) sessionCalls.get(sessionName);
    int num = 0;
    if (numberOfCalls != null) {
        num = numberOfCalls;
    }
    sessionCalls.put(sessionName, num + 1);
    // **temp
    session.getEventManager().addListener(new AcquireReleaseListener());
    session.getEventManager().addListener(new SessionEventAdapter() {

        @Override
        public void postLogin(SessionEvent event) {
            if (event.getSession().getPlatform().isPostgreSQL()) {
                event.getSession().setQueryTimeoutDefault(0);
            }
        }
    });
    if (Boolean.parseBoolean(System.getProperty("sop"))) {
        boolean isRecoverable = Boolean.parseBoolean(System.getProperty("sop.recoverable"));
        Class<?> sopClass = Class.forName("oracle.toplink.exalogic.sop.SerializedObjectPolicy");
        Method setIsRecoverableMethod = null;
        if (isRecoverable) {
            setIsRecoverableMethod = sopClass.getDeclaredMethod("setIsRecoverable", boolean.class);
        }
        Class<?>[] sopEntities = { Employee.class, Address.class, Project.class };
        for (Class<?> sopEntity : sopEntities) {
            ClassDescriptor descriptor = session.getDescriptor(sopEntity);
            Object sop = sopClass.getConstructor().newInstance();
            if (isRecoverable) {
                setIsRecoverableMethod.invoke(sop, true);
            }
            ((SerializedObjectPolicy) sop).setField(new DatabaseField("SOP"));
            descriptor.setSerializedObjectPolicy((SerializedObjectPolicy) sop);
            if (descriptor.usesOptimisticLocking() && (descriptor.getOptimisticLockingPolicy() instanceof VersionLockingPolicy)) {
                ((VersionLockingPolicy) descriptor.getOptimisticLockingPolicy()).setIsCascaded(true);
            }
        }
    }
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) VersionLockingPolicy(org.eclipse.persistence.descriptors.VersionLockingPolicy) Method(java.lang.reflect.Method) SessionEvent(org.eclipse.persistence.sessions.SessionEvent) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) SerializedObjectPolicy(org.eclipse.persistence.descriptors.SerializedObjectPolicy) SessionEventAdapter(org.eclipse.persistence.sessions.SessionEventAdapter)

Aggregations

SerializedObjectPolicy (org.eclipse.persistence.descriptors.SerializedObjectPolicy)2 Method (java.lang.reflect.Method)1 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)1 VersionLockingPolicy (org.eclipse.persistence.descriptors.VersionLockingPolicy)1 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)1 SessionEvent (org.eclipse.persistence.sessions.SessionEvent)1 SessionEventAdapter (org.eclipse.persistence.sessions.SessionEventAdapter)1