Package org.hibernate.envers.entities.mapper.id

Examples of org.hibernate.envers.entities.mapper.id.IdMapper


            // In case of a fake many-to-one bidirectional relation, we have to generate a mapper which maps
            // the mapped-by property name to the id of the related entity (which is the owner of the collection).
            String auditMappedBy = propertyAuditingData.getAuditMappedBy();

            // Creating a prefixed relation mapper.
            IdMapper relMapper = referencingIdMapping.getIdMapper().prefixMappedProperties(
                    MappingTools.createToOneRelationPrefix(auditMappedBy));

            fakeBidirectionalRelationMapper = new ToOneIdMapper(
                    relMapper,
                    // The mapper will only be used to map from entity to map, so no need to provide other details
View Full Code Here


                propertyAuditingData, true);

        String lastPropertyPrefix = MappingTools.createToOneRelationPrefix(propertyAuditingData.getName());

        // Generating the id mapper for the relation
        IdMapper relMapper = idMapping.getIdMapper().prefixMappedProperties(lastPropertyPrefix);

        // Storing information about this relation
        mainGenerator.getEntitiesConfigurations().get(entityName).addToOneRelation(
                propertyAuditingData.getName(), referencedEntityName, relMapper, insertable);
View Full Code Here

        String lastPropertyPrefix = MappingTools.createToOneRelationPrefix(owningReferencePropertyName);
        String referencedEntityName = propertyValue.getReferencedEntityName();

        // Generating the id mapper for the relation
        IdMapper ownedIdMapper = ownedIdMapping.getIdMapper().prefixMappedProperties(lastPropertyPrefix);

        // Storing information about this relation
        mainGenerator.getEntitiesConfigurations().get(entityName).addToOneNotOwningRelation(
                propertyAuditingData.getName(), owningReferencePropertyName,
                referencedEntityName, ownedIdMapper);
View Full Code Here

            // In case of a fake many-to-one bidirectional relation, we have to generate a mapper which maps
            // the mapped-by property name to the id of the related entity (which is the owner of the collection).
            String auditMappedBy = propertyAuditingData.getAuditMappedBy();

            // Creating a prefixed relation mapper.
            IdMapper relMapper = referencingIdMapping.getIdMapper().prefixMappedProperties(
                    MappingTools.createToOneRelationPrefix(auditMappedBy));

            fakeBidirectionalRelationMapper = new ToOneIdMapper(
                    relMapper,
                    // The mapper will only be used to map from entity to map, so no need to provide other details
View Full Code Here

        if (type != null) {
            entityName = type;
        }

        // First mapping the primary key
        IdMapper idMapper = verCfg.getEntCfg().get(entityName).getIdMapper();
        Map originalId = (Map) versionsEntity.get(verCfg.getAuditEntCfg().getOriginalIdPropName());

        // Fixes HHH-4751 issue (@IdClass with @ManyToOne relation mapping inside)
        // Note that identifiers are always audited
        // Replace identifier proxies if do not point to audit tables
        replaceNonAuditIdProxies(originalId, revision);

        Object primaryKey = idMapper.mapToIdFromMap(originalId);

        // Checking if the entity is in cache
        if (versionsReader.getFirstLevelCache().contains(entityName, revision, primaryKey)) {
            return versionsReader.getFirstLevelCache().get(entityName, revision, primaryKey);
        }

        // If it is not in the cache, creating a new entity instance
        Object ret;
        try {
          EntityConfiguration entCfg = verCfg.getEntCfg().get(entityName);
          if(entCfg == null) {
            // a relation marked as RelationTargetAuditMode.NOT_AUDITED
            entCfg = verCfg.getEntCfg().getNotVersionEntityConfiguration(entityName);
          }

            Class<?> cls = ReflectHelper.classForName(entCfg.getEntityClassName());
            ret = ReflectHelper.getDefaultConstructor(cls).newInstance();
        } catch (Exception e) {
            throw new AuditException(e);
        }

        // Putting the newly created entity instance into the first level cache, in case a one-to-one bidirectional
        // relation is present (which is eagerly loaded).
        versionsReader.getFirstLevelCache().put(entityName, revision, primaryKey, ret);

        verCfg.getEntCfg().get(entityName).getPropertyMapper().mapToEntityFromMap(verCfg, ret, versionsEntity, primaryKey,
                versionsReader, revision);
        idMapper.mapToEntityFromMap(ret, originalId);

        // Put entity on entityName cache after mapping it from the map representation
        versionsReader.getFirstLevelCache().putOnEntityNameCache(primaryKey, revision, ret, entityName);
       
        return ret;
View Full Code Here

            // We've got to initialize the object from the proxy to later read its state.
            value = Tools.getTargetFromProxy(session.getFactory(), hibernateProxy);
    } else {
          toEntityName =  session.guessEntityName(value);

            IdMapper idMapper = enversConfiguration.getEntCfg().get(toEntityName).getIdMapper();
            id = (Serializable) idMapper.mapToIdFromEntity(value);
    }

    Set<String> toPropertyNames = enversConfiguration.getEntCfg()
        .getToPropertyNames(fromEntityName, relDesc.getFromPropertyName(), toEntityName);
    String toPropertyName = toPropertyNames.iterator().next();
View Full Code Here

        IdMappingData idMapping = configuration.getIdMappingData();

        String lastPropertyPrefix = propertyAuditingData.getName() + "_";

        // Generating the id mapper for the relation
        IdMapper relMapper = idMapping.getIdMapper().prefixMappedProperties(lastPropertyPrefix);

        // Storing information about this relation
        mainGenerator.getEntitiesConfigurations().get(entityName).addToOneRelation(
                propertyAuditingData.getName(), referencedEntityName, relMapper);
View Full Code Here

        String lastPropertyPrefix = owningReferencePropertyName + "_";
        String referencedEntityName = propertyValue.getReferencedEntityName();

        // Generating the id mapper for the relation
        IdMapper ownedIdMapper = ownedIdMapping.getIdMapper().prefixMappedProperties(lastPropertyPrefix);

        // Storing information about this relation
        mainGenerator.getEntitiesConfigurations().get(entityName).addToOneNotOwningRelation(
                propertyAuditingData.getName(), owningReferencePropertyName,
                referencedEntityName, ownedIdMapper);
View Full Code Here

              // We've got to initialize the object from the proxy to later read its state.  
              newValue = Tools.getTargetFromProxy(session.getFactory(), hibernateProxy);
                      } else {
                        toEntityName =  session.guessEntityName(newValue);

              IdMapper idMapper = verCfg.getEntCfg().get(toEntityName).getIdMapper();
                           id = (Serializable) idMapper.mapToIdFromEntity(newValue);
                      }

                        verSync.addWorkUnit(new CollectionChangeWorkUnit(session, toEntityName, verCfg, id, newValue));
                    }

                    if (oldValue != null) {
                      String toEntityName;
            Serializable id;

                      if(oldValue instanceof HibernateProxy) {
                          HibernateProxy hibernateProxy = (HibernateProxy) oldValue;
                          toEntityName = session.bestGuessEntityName(oldValue);
                          id = hibernateProxy.getHibernateLazyInitializer().getIdentifier();
              // We've got to initialize the object as we'll read it's state anyway.
              oldValue = Tools.getTargetFromProxy(session.getFactory(), hibernateProxy);
                      } else {
                        toEntityName =  session.guessEntityName(oldValue);

              IdMapper idMapper = verCfg.getEntCfg().get(toEntityName).getIdMapper();
              id = (Serializable) idMapper.mapToIdFromEntity(oldValue);
                      }
           
                        verSync.addWorkUnit(new CollectionChangeWorkUnit(session, toEntityName, verCfg, id, oldValue));
                    }
                }
View Full Code Here

                workUnit.getReferencingPropertyName());

        // relDesc can be null if this is a collection of simple values (not a relation).
        if (relDesc != null && relDesc.isBidirectional()) {
            String relatedEntityName = relDesc.getToEntityName();
            IdMapper relatedIdMapper = verCfg.getEntCfg().get(relatedEntityName).getIdMapper();
           
            for (PersistentCollectionChangeData changeData : workUnit.getCollectionChanges()) {
                Object relatedObj = changeData.getChangedElement();
                Serializable relatedId = (Serializable) relatedIdMapper.mapToIdFromEntity(relatedObj);

                verSync.addWorkUnit(new CollectionChangeWorkUnit(event.getSession(), relatedEntityName, verCfg,
            relatedId, relatedObj));
            }
        }
View Full Code Here

TOP

Related Classes of org.hibernate.envers.entities.mapper.id.IdMapper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.