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);
}
}
}
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();
}
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");
}
}
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;
}
}
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());
}
}
Aggregations