use of java.io.Serializable in project silk by jbee.
the class TestMockingBinds method wildcardBindsDoFallBackToMostGeneralIfRequired.
@Test
public void wildcardBindsDoFallBackToMostGeneralIfRequired() {
Injector injector = Bootstrap.injector(TestMockingBindsModule.class);
Serializable mock = injector.resolve(dependency(Serializable.class));
assertTrue(isProxyClass(mock.getClass()));
assertEquals(Object.class.getCanonicalName(), mock.toString());
}
use of java.io.Serializable in project hibernate-orm by hibernate.
the class EntityInstantiator method replaceNonAuditIdProxies.
@SuppressWarnings({ "unchecked" })
private void replaceNonAuditIdProxies(Map versionsEntity, Number revision) {
final Map originalId = (Map) versionsEntity.get(enversService.getAuditEntitiesConfiguration().getOriginalIdPropName());
for (Object key : originalId.keySet()) {
final Object value = originalId.get(key);
if (value instanceof HibernateProxy) {
final HibernateProxy hibernateProxy = (HibernateProxy) value;
final LazyInitializer initializer = hibernateProxy.getHibernateLazyInitializer();
final String entityName = initializer.getEntityName();
final Serializable entityId = initializer.getIdentifier();
if (enversService.getEntitiesConfigurations().isVersioned(entityName)) {
final String entityClassName = enversService.getEntitiesConfigurations().get(entityName).getEntityClassName();
final Class entityClass = ReflectionTools.loadClass(entityClassName, enversService.getClassLoaderService());
final ToOneDelegateSessionImplementor delegate = new ToOneDelegateSessionImplementor(versionsReader, entityClass, entityId, revision, RevisionType.DEL.equals(versionsEntity.get(enversService.getAuditEntitiesConfiguration().getRevisionTypePropName())), enversService);
originalId.put(key, versionsReader.getSessionImplementor().getFactory().getMetamodel().entityPersister(entityName).createProxy(entityId, delegate));
}
}
}
}
use of java.io.Serializable in project hibernate-orm by hibernate.
the class AbstractOneToOneMapper method nullSafeMapToEntityFromMap.
@Override
public void nullSafeMapToEntityFromMap(EnversService enversService, Object obj, Map data, Object primaryKey, AuditReaderImplementor versionsReader, Number revision) {
final EntityInfo referencedEntity = getEntityInfo(enversService, referencedEntityName);
Object value;
try {
value = queryForReferencedEntity(versionsReader, referencedEntity, (Serializable) primaryKey, revision);
} catch (NoResultException e) {
value = null;
} catch (NonUniqueResultException e) {
throw new AuditException("Many versions results for one-to-one relationship " + entityName + "." + getPropertyData().getBeanName() + ".", e);
}
setPropertyValue(obj, value);
}
use of java.io.Serializable in project hibernate-orm by hibernate.
the class EntityChangeNotifier method entityChanged.
/**
* Notifies {@link RevisionInfoGenerator} about changes made in the current revision. Provides information
* about modified entity class, entity name and its id, as well as {@link org.hibernate.envers.RevisionType}
* and revision log entity.
*
* @param session Active session.
* @param currentRevisionData Revision log entity.
* @param vwu Performed work unit.
*/
public void entityChanged(Session session, Object currentRevisionData, AuditWorkUnit vwu) {
Serializable entityId = vwu.getEntityId();
if (entityId instanceof PersistentCollectionChangeWorkUnit.PersistentCollectionChangeWorkUnitId) {
// Notify about a change in collection owner entity.
entityId = ((PersistentCollectionChangeWorkUnit.PersistentCollectionChangeWorkUnitId) entityId).getOwnerId();
}
final Class entityClass = EntityTools.getEntityClass(sessionImplementor, vwu.getEntityName());
revisionInfoGenerator.entityChanged(entityClass, vwu.getEntityName(), entityId, vwu.getRevisionType(), currentRevisionData);
}
use of java.io.Serializable in project hibernate-orm by hibernate.
the class BaseEnversCollectionEventListener method generateBidirectionalCollectionChangeWorkUnits.
private void generateBidirectionalCollectionChangeWorkUnits(AuditProcess auditProcess, AbstractCollectionEvent event, PersistentCollectionChangeWorkUnit workUnit, RelationDescription rd) {
// Checking if this is enabled in configuration ...
if (!getEnversService().getGlobalConfiguration().isGenerateRevisionsForCollections()) {
return;
}
// relDesc can be null if this is a collection of simple values (not a relation).
if (rd != null && rd.isBidirectional()) {
final String relatedEntityName = rd.getToEntityName();
final IdMapper relatedIdMapper = getEnversService().getEntitiesConfigurations().get(relatedEntityName).getIdMapper();
final Set<String> toPropertyNames = getEnversService().getEntitiesConfigurations().getToPropertyNames(event.getAffectedOwnerEntityName(), rd.getFromPropertyName(), relatedEntityName);
final String toPropertyName = toPropertyNames.iterator().next();
for (PersistentCollectionChangeData changeData : workUnit.getCollectionChanges()) {
final Object relatedObj = changeData.getChangedElement();
final Serializable relatedId = (Serializable) relatedIdMapper.mapToIdFromEntity(relatedObj);
auditProcess.addWorkUnit(new CollectionChangeWorkUnit(event.getSession(), event.getSession().bestGuessEntityName(relatedObj), toPropertyName, getEnversService(), relatedId, relatedObj));
}
}
}
Aggregations