Search in sources :

Example 1 with UnitOfWorkChangeSet

use of org.eclipse.persistence.internal.sessions.UnitOfWorkChangeSet in project cuba by cuba-platform.

the class EntityCacheConnection method invalidateQueryCache.

protected void invalidateQueryCache(Object command) {
    if (command instanceof MergeChangeSetCommand) {
        MergeChangeSetCommand changeSetCommand = (MergeChangeSetCommand) command;
        UnitOfWorkChangeSet changeSet = changeSetCommand.getChangeSet(null);
        if (changeSet != null && changeSet.getAllChangeSets() != null) {
            Set<String> typeNames = new HashSet<>();
            changeSet.getAllChangeSets().values().stream().filter(obj -> obj.getClassName() != null).forEach(obj -> {
                MetaClass metaClass = metadata.getClass(ReflectionHelper.getClass(obj.getClassName()));
                if (metaClass != null) {
                    metaClass = metadata.getExtendedEntities().getOriginalOrThisMetaClass(metaClass);
                    typeNames.add(metaClass.getName());
                }
            });
            queryCacheManager.invalidate(typeNames, false);
        }
    }
}
Also used : RemoteCommandManager(org.eclipse.persistence.sessions.coordination.RemoteCommandManager) ClusterListenerAdapter(com.haulmont.cuba.core.app.ClusterListenerAdapter) MergeChangeSetCommand(org.eclipse.persistence.sessions.coordination.MergeChangeSetCommand) ReflectionHelper(com.haulmont.bali.util.ReflectionHelper) Set(java.util.Set) AppBeans(com.haulmont.cuba.core.global.AppBeans) MetaClass(com.haulmont.chile.core.model.MetaClass) Metadata(com.haulmont.cuba.core.global.Metadata) Serializable(java.io.Serializable) HashSet(java.util.HashSet) ClusterManagerAPI(com.haulmont.cuba.core.app.ClusterManagerAPI) UnitOfWorkChangeSet(org.eclipse.persistence.internal.sessions.UnitOfWorkChangeSet) Helper(org.eclipse.persistence.internal.helper.Helper) BroadcastRemoteConnection(org.eclipse.persistence.internal.sessions.coordination.broadcast.BroadcastRemoteConnection) MergeChangeSetCommand(org.eclipse.persistence.sessions.coordination.MergeChangeSetCommand) MetaClass(com.haulmont.chile.core.model.MetaClass) UnitOfWorkChangeSet(org.eclipse.persistence.internal.sessions.UnitOfWorkChangeSet) HashSet(java.util.HashSet)

Example 2 with UnitOfWorkChangeSet

use of org.eclipse.persistence.internal.sessions.UnitOfWorkChangeSet in project eclipselink by eclipse-ee4j.

the class ExceptionSerializationTestCase method setup.

@Override
public void setup() {
    conversionException = ConversionException.couldNotBeConverted(new Object(), String.class);
    Exception exception = new Exception();
    Vector errors = new Vector();
    errors.addElement(errors);
    UnitOfWorkChangeSet changeSet = new UnitOfWorkChangeSet();
}
Also used : UnitOfWorkChangeSet(org.eclipse.persistence.internal.sessions.UnitOfWorkChangeSet) Vector(java.util.Vector) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) ConversionException(org.eclipse.persistence.exceptions.ConversionException)

Example 3 with UnitOfWorkChangeSet

use of org.eclipse.persistence.internal.sessions.UnitOfWorkChangeSet in project eclipselink by eclipse-ee4j.

the class VariableOneToOneInsertTest method test.

@Override
public void test() {
    UnitOfWork uow = getSession().acquireUnitOfWork();
    this.company = new Company();
    Company c = (Company) uow.registerObject(this.company);
    c.setName("Company One");
    c.setId(54);
    Email email = new Email();
    email.setAddress("@Blather.ca");
    email.setHolder(c);
    email.setId(45);
    c.setContact(email);
    c.email = email;
    // this is a little magic to ensure we write Company first, it will not enduce
    // any side effects.
    UnitOfWorkChangeSet uowcs = (UnitOfWorkChangeSet) uow.getCurrentChanges();
    uowcs.getObjectChanges().remove(Email.class);
    try {
        ((org.eclipse.persistence.internal.sessions.UnitOfWorkImpl) uow).commitRootUnitOfWorkWithPreBuiltChangeSet(uowcs);
    } catch (DatabaseException ex) {
        throw new TestErrorException("Duplicate Insert with Variable One To One Private Owned see bug 4378539");
    }
}
Also used : UnitOfWorkChangeSet(org.eclipse.persistence.internal.sessions.UnitOfWorkChangeSet) DatabaseException(org.eclipse.persistence.exceptions.DatabaseException)

Example 4 with UnitOfWorkChangeSet

use of org.eclipse.persistence.internal.sessions.UnitOfWorkChangeSet in project eclipselink by eclipse-ee4j.

the class ObjectBuilder method getBaseChangeRecordForField.

/**
 * Return the base ChangeRecord for the given DatabaseField.
 * The object and all its relevant aggregates must exist.
 * The returned ChangeRecord is
 * either DirectToFieldChangeRecord or TransformationMappingChangeRecord,
 * or null.
 */
public ChangeRecord getBaseChangeRecordForField(ObjectChangeSet objectChangeSet, Object object, DatabaseField databaseField, AbstractSession session) {
    DatabaseMapping mapping = getMappingForField(databaseField);
    // Drill down through the mappings until we get the direct mapping to the databaseField.
    while (mapping.isAggregateObjectMapping()) {
        String attributeName = mapping.getAttributeName();
        Object aggregate = mapping.getAttributeValueFromObject(object);
        ClassDescriptor referenceDescriptor = mapping.getReferenceDescriptor();
        AggregateChangeRecord aggregateChangeRecord = (AggregateChangeRecord) objectChangeSet.getChangesForAttributeNamed(attributeName);
        if (aggregateChangeRecord == null) {
            aggregateChangeRecord = new AggregateChangeRecord(objectChangeSet);
            aggregateChangeRecord.setAttribute(attributeName);
            aggregateChangeRecord.setMapping(mapping);
            objectChangeSet.addChange(aggregateChangeRecord);
        }
        ObjectChangeSet aggregateChangeSet = (ObjectChangeSet) aggregateChangeRecord.getChangedObject();
        if (aggregateChangeSet == null) {
            aggregateChangeSet = referenceDescriptor.getObjectBuilder().createObjectChangeSet(aggregate, (UnitOfWorkChangeSet) objectChangeSet.getUOWChangeSet(), session);
            aggregateChangeRecord.setChangedObject(aggregateChangeSet);
        }
        mapping = referenceDescriptor.getObjectBuilder().getMappingForField(databaseField);
        objectChangeSet = aggregateChangeSet;
        object = aggregate;
    }
    String attributeName = mapping.getAttributeName();
    if (mapping.isAbstractDirectMapping()) {
        DirectToFieldChangeRecord changeRecord = (DirectToFieldChangeRecord) objectChangeSet.getChangesForAttributeNamed(attributeName);
        if (changeRecord == null) {
            changeRecord = new DirectToFieldChangeRecord(objectChangeSet);
            changeRecord.setAttribute(attributeName);
            changeRecord.setMapping(mapping);
            objectChangeSet.addChange(changeRecord);
        }
        return changeRecord;
    } else if (mapping.isTransformationMapping()) {
        TransformationMappingChangeRecord changeRecord = (TransformationMappingChangeRecord) objectChangeSet.getChangesForAttributeNamed(attributeName);
        if (changeRecord == null) {
            changeRecord = new TransformationMappingChangeRecord(objectChangeSet);
            changeRecord.setAttribute(attributeName);
            changeRecord.setMapping(mapping);
            objectChangeSet.addChange(changeRecord);
        }
        return changeRecord;
    } else {
        session.log(SessionLog.FINEST, SessionLog.QUERY, "field_for_unsupported_mapping_returned", databaseField, getDescriptor());
        return null;
    }
}
Also used : TransformationMappingChangeRecord(org.eclipse.persistence.internal.sessions.TransformationMappingChangeRecord) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) UnitOfWorkChangeSet(org.eclipse.persistence.internal.sessions.UnitOfWorkChangeSet) AggregateObjectChangeSet(org.eclipse.persistence.internal.sessions.AggregateObjectChangeSet) ObjectChangeSet(org.eclipse.persistence.internal.sessions.ObjectChangeSet) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) InvalidObject(org.eclipse.persistence.internal.helper.InvalidObject) AggregateChangeRecord(org.eclipse.persistence.internal.sessions.AggregateChangeRecord) DirectToFieldChangeRecord(org.eclipse.persistence.internal.sessions.DirectToFieldChangeRecord)

Example 5 with UnitOfWorkChangeSet

use of org.eclipse.persistence.internal.sessions.UnitOfWorkChangeSet in project eclipselink by eclipse-ee4j.

the class AttributeChangeListener method internalPropertyChange.

/**
 * INTERNAL:
 * This method marks the object as changed.  This method is only
 * called by EclipseLink
 */
@Override
public void internalPropertyChange(PropertyChangeEvent evt) {
    if (evt.getNewValue() == evt.getOldValue()) {
        return;
    }
    DatabaseMapping mapping = descriptor.getObjectBuilder().getMappingForAttributeName(evt.getPropertyName());
    // Bug#4127952 Throw an exception indicating there is no mapping for the property name.
    if (mapping == null) {
        throw ValidationException.wrongPropertyNameInChangeEvent(owner.getClass(), evt.getPropertyName());
    }
    if (mapping instanceof AbstractDirectMapping || mapping instanceof AbstractTransformationMapping) {
        // If both newValue and oldValue are null, or newValue is not null and newValue equals oldValue, don't build ChangeRecord
        if (((evt.getNewValue() == null) && (evt.getOldValue() == null)) || ((evt.getNewValue() != null) && (evt.getNewValue()).equals(evt.getOldValue()))) {
            return;
        }
    }
    super.internalPropertyChange(evt);
    if (uow.getUnitOfWorkChangeSet() == null) {
        uow.setUnitOfWorkChangeSet(new UnitOfWorkChangeSet(uow));
    }
    if (objectChangeSet == null) {
        // only null if new or if in a new UOW
        // add to tracker list to prevent GC of clone if using weak references
        // put it in here so that it only occurs on the 1st change for a particular UOW
        uow.addToChangeTrackedHardList(owner);
        objectChangeSet = getDescriptor().getObjectBuilder().createObjectChangeSet(owner, (UnitOfWorkChangeSet) uow.getUnitOfWorkChangeSet(), false, uow);
    }
    if (evt.getClass().equals(ClassConstants.PropertyChangeEvent_Class)) {
        mapping.updateChangeRecord(evt.getSource(), evt.getNewValue(), evt.getOldValue(), objectChangeSet, getUnitOfWork());
    } else if (evt.getClass().equals(ClassConstants.CollectionChangeEvent_Class) || (evt.getClass().equals(ClassConstants.MapChangeEvent_Class))) {
        mapping.updateCollectionChangeRecord((CollectionChangeEvent) evt, objectChangeSet, getUnitOfWork());
    } else {
        throw ValidationException.wrongChangeEvent(evt.getClass());
    }
}
Also used : UnitOfWorkChangeSet(org.eclipse.persistence.internal.sessions.UnitOfWorkChangeSet) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping)

Aggregations

UnitOfWorkChangeSet (org.eclipse.persistence.internal.sessions.UnitOfWorkChangeSet)29 ObjectChangeSet (org.eclipse.persistence.internal.sessions.ObjectChangeSet)19 WriteObjectQuery (org.eclipse.persistence.queries.WriteObjectQuery)7 UnitOfWorkImpl (org.eclipse.persistence.internal.sessions.UnitOfWorkImpl)6 EntityManager (jakarta.persistence.EntityManager)4 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)4 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)4 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)4 HashMap (java.util.HashMap)3 ContainerPolicy (org.eclipse.persistence.internal.queries.ContainerPolicy)3 AbstractRecord (org.eclipse.persistence.internal.sessions.AbstractRecord)3 CollectionChangeRecord (org.eclipse.persistence.internal.sessions.CollectionChangeRecord)3 InsertObjectQuery (org.eclipse.persistence.queries.InsertObjectQuery)3 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Set (java.util.Set)2 TreeMap (java.util.TreeMap)2 Vector (java.util.Vector)2 DatabaseException (org.eclipse.persistence.exceptions.DatabaseException)2 QueryException (org.eclipse.persistence.exceptions.QueryException)2