Package org.hibernate.envers.entities

Examples of org.hibernate.envers.entities.IdMappingData


        String schema = getSchema(auditingData.getAuditTable().schema(), pc.getTable());
        String catalog = getCatalog(auditingData.getAuditTable().catalog(), pc.getTable());

    if (!isAudited) {
      String entityName = pc.getEntityName();
      IdMappingData idMapper = idMetadataGenerator.addId(pc);

            if (idMapper == null) {
                // Unsupported id mapping, e.g. key-many-to-one. If the entity is used in auditing, an exception
                // will be thrown later on.
                log.debug("Unable to create auditing id mapping for entity " + entityName +
                        ", because of an unsupported Hibernate id mapping (e.g. key-many-to-one).");
                return;
            }

      ExtendedPropertyMapper propertyMapper = null;
      String parentEntityName = null;
      EntityConfiguration entityCfg = new EntityConfiguration(entityName, idMapper, propertyMapper,
          parentEntityName);
      notAuditedEntitiesConfigurations.put(entityName, entityCfg);
      return;
    }

        String entityName = pc.getEntityName();
        log.debug("Generating first-pass auditing mapping for entity " + entityName + ".");

        String auditEntityName = verEntCfg.getAuditEntityName(entityName);
        String auditTableName = verEntCfg.getAuditTableName(entityName, pc.getTable().getName());

        // Registering the audit entity name, now that it is known
        auditEntityNameRegister.register(auditEntityName);

        AuditTableData auditTableData = new AuditTableData(auditEntityName, auditTableName, schema, catalog);

        // Generating a mapping for the id
        IdMappingData idMapper = idMetadataGenerator.addId(pc);

        InheritanceType inheritanceType = InheritanceType.get(pc);

        // These properties will be read from the mapping data
        final Element class_mapping;
View Full Code Here


        String schema = getSchema(auditingData.getAuditTable().schema(), pc.getTable());
        String catalog = getCatalog(auditingData.getAuditTable().catalog(), pc.getTable());

    if (!isAudited) {
      String entityName = pc.getEntityName();
      IdMappingData idMapper = idMetadataGenerator.addId(pc, false);

            if (idMapper == null) {
                // Unsupported id mapping, e.g. key-many-to-one. If the entity is used in auditing, an exception
                // will be thrown later on.
                log.debug("Unable to create auditing id mapping for entity " + entityName +
                        ", because of an unsupported Hibernate id mapping (e.g. key-many-to-one).");
                return;
            }

      ExtendedPropertyMapper propertyMapper = null;
      String parentEntityName = null;
      EntityConfiguration entityCfg = new EntityConfiguration(entityName, idMapper, propertyMapper,
          parentEntityName);
      notAuditedEntitiesConfigurations.put(entityName, entityCfg);
      return;
    }

        String entityName = pc.getEntityName();
        log.debug("Generating first-pass auditing mapping for entity " + entityName + ".");

        String auditEntityName = verEntCfg.getAuditEntityName(entityName);
        String auditTableName = verEntCfg.getAuditTableName(entityName, pc.getTable().getName());

        // Registering the audit entity name, now that it is known
        auditEntityNameRegister.register(auditEntityName);

        AuditTableData auditTableData = new AuditTableData(auditEntityName, auditTableName, schema, catalog);

        // Generating a mapping for the id
        IdMappingData idMapper = idMetadataGenerator.addId(pc, true);

        InheritanceType inheritanceType = InheritanceType.getForChild(pc);

        // These properties will be read from the mapping data
        final Element class_mapping;
View Full Code Here

        log.debug("Adding audit mapping for property " + referencingEntityName + "." + propertyName +
                ": one-to-many collection, using a join column on the referenced entity.");

        String mappedBy = getMappedBy(propertyValue);

        IdMappingData referencedIdMapping = mainGenerator.getReferencedIdMappingData(referencingEntityName,
                    referencedEntityName, propertyAuditingData, false);
        IdMappingData referencingIdMapping = referencingEntityConfiguration.getIdMappingData();

        // Generating the id mappers data for the referencing side of the relation.
        MiddleIdData referencingIdData = createMiddleIdData(referencingIdMapping,
                mappedBy + "_", referencingEntityName);

        // And for the referenced side. The prefixed mapper won't be used (as this collection isn't persisted
        // in a join table, so the prefix value is arbitrary).
        MiddleIdData referencedIdData = createMiddleIdData(referencedIdMapping,
                null, referencedEntityName);

        // Generating the element mapping.
        MiddleComponentData elementComponentData = new MiddleComponentData(
                new MiddleRelatedComponentMapper(referencedIdData), 0);

        // Generating the index mapping, if an index exists. It can only exists in case a javax.persistence.MapKey
        // annotation is present on the entity. So the middleEntityXml will be not be used. The queryGeneratorBuilder
        // will only be checked for nullnes.
        MiddleComponentData indexComponentData = addIndex(null, null);

        // Generating the query generator - it should read directly from the related entity.
        RelationQueryGenerator queryGenerator = new OneAuditEntityQueryGenerator(mainGenerator.getGlobalCfg(),
                mainGenerator.getVerEntCfg(), referencingIdData, referencedEntityName,
                referencedIdMapping.getIdMapper());

        // Creating common mapper data.
        CommonCollectionMapperData commonCollectionMapperData = new CommonCollectionMapperData(
                mainGenerator.getVerEntCfg(), referencedEntityName,
                propertyAuditingData.getPropertyData(),
                referencingIdData, queryGenerator);

        PropertyMapper fakeBidirectionalRelationMapper;
        PropertyMapper fakeBidirectionalRelationIndexMapper;
        if (fakeOneToManyBidirectional) {
            // 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

        // ******
        // Generating the mapping for the referencing entity (it must be an entity).
        // ******
        // Getting the id-mapping data of the referencing entity (the entity that "owns" this collection).
        IdMappingData referencingIdMapping = referencingEntityConfiguration.getIdMappingData();

        // Only valid for an inverse relation; null otherwise.
        String mappedBy;

        // The referencing prefix is always for a related entity. So it has always the "_" at the end added.
View Full Code Here

            if (mapKey == null) {
                // This entity doesn't specify a javax.persistence.MapKey. Mapping it to the middle entity.
                return addValueToMiddleTable(indexedValue.getIndex(), middleEntityXml,
                        queryGeneratorBuilder, "mapkey", null);
            } else {
                IdMappingData referencedIdMapping = mainGenerator.getEntitiesConfigurations()
                        .get(referencedEntityName).getIdMappingData();
                int currentIndex = queryGeneratorBuilder == null ? 0 : queryGeneratorBuilder.getCurrentIndex();
                if ("".equals(mapKey)) {
                    // The key of the map is the id of the entity.
                    return new MiddleComponentData(new MiddleMapKeyIdComponentMapper(mainGenerator.getVerEntCfg(),
                            referencedIdMapping.getIdMapper()), currentIndex);
                } else {
                    // The key of the map is a property of the entity.
                    return new MiddleComponentData(new MiddleMapKeyPropertyComponentMapper(mapKey,
                            propertyAuditingData.getAccessType()), currentIndex);
                }
View Full Code Here

        if (type instanceof ManyToOneType) {
            String prefixRelated = prefix + "_";

            String referencedEntityName = MappingTools.getReferencedEntityName(value);

            IdMappingData referencedIdMapping = mainGenerator.getReferencedIdMappingData(referencingEntityName,
                    referencedEntityName, propertyAuditingData, true);

            // Adding related-entity (in this case: the referenced entities id) id mapping to the xml only if the
            // relation isn't inverse (so when <code>xmlMapping</code> is not null).
            if (xmlMapping != null) {
View Full Code Here

        orig_id_mapping.addAttribute("name", mainGenerator.getVerEntCfg().getOriginalIdPropName());

        // Adding a relation to the revision entity (effectively: the "revision number" property)
        mainGenerator.addRevisionInfoRelation(orig_id_mapping);

        return new IdMappingData(mapper, orig_id_mapping, rel_id_mapping);
    }
View Full Code Here

        String schema = getSchema(auditingData.getAuditTable().schema(), pc.getTable());
        String catalog = getCatalog(auditingData.getAuditTable().catalog(), pc.getTable());

    if (!isAudited) {
      String entityName = pc.getEntityName();
      IdMappingData idMapper = idMetadataGenerator.addId(pc, false);

            if (idMapper == null) {
                // Unsupported id mapping, e.g. key-many-to-one. If the entity is used in auditing, an exception
                // will be thrown later on.
                LOG.debugf("Unable to create auditing id mapping for entity %s, because of an unsupported Hibernate id mapping (e.g. key-many-to-one)",
                           entityName);
                return;
            }

      ExtendedPropertyMapper propertyMapper = null;
      String parentEntityName = null;
      EntityConfiguration entityCfg = new EntityConfiguration(entityName, pc.getClassName(), idMapper, propertyMapper,
          parentEntityName);
      notAuditedEntitiesConfigurations.put(entityName, entityCfg);
      return;
    }

        String entityName = pc.getEntityName();
        LOG.debugf("Generating first-pass auditing mapping for entity %s", entityName);

        String auditEntityName = verEntCfg.getAuditEntityName(entityName);
        String auditTableName = verEntCfg.getAuditTableName(entityName, pc.getTable().getName());

        // Registering the audit entity name, now that it is known
        auditEntityNameRegister.register(auditEntityName);

        AuditTableData auditTableData = new AuditTableData(auditEntityName, auditTableName, schema, catalog);

        // Generating a mapping for the id
        IdMappingData idMapper = idMetadataGenerator.addId(pc, true);

        InheritanceType inheritanceType = InheritanceType.get(pc);

        // These properties will be read from the mapping data
        final Element class_mapping;
View Full Code Here

                   referencingEntityName,
                   propertyName);

        String mappedBy = getMappedBy(propertyValue);

        IdMappingData referencedIdMapping = mainGenerator.getReferencedIdMappingData(referencingEntityName,
                    referencedEntityName, propertyAuditingData, false);
        IdMappingData referencingIdMapping = referencingEntityConfiguration.getIdMappingData();

        // Generating the id mappers data for the referencing side of the relation.
        MiddleIdData referencingIdData = createMiddleIdData(referencingIdMapping,
                mappedBy + "_", referencingEntityName);

        // And for the referenced side. The prefixed mapper won't be used (as this collection isn't persisted
        // in a join table, so the prefix value is arbitrary).
        MiddleIdData referencedIdData = createMiddleIdData(referencedIdMapping,
                null, referencedEntityName);

        // Generating the element mapping.
        MiddleComponentData elementComponentData = new MiddleComponentData(
                new MiddleRelatedComponentMapper(referencedIdData), 0);

        // Generating the index mapping, if an index exists. It can only exists in case a javax.persistence.MapKey
        // annotation is present on the entity. So the middleEntityXml will be not be used. The queryGeneratorBuilder
        // will only be checked for nullnes.
        MiddleComponentData indexComponentData = addIndex(null, null);

        // Generating the query generator - it should read directly from the related entity.
        RelationQueryGenerator queryGenerator = new OneAuditEntityQueryGenerator(mainGenerator.getGlobalCfg(),
                mainGenerator.getVerEntCfg(), mainGenerator.getAuditStrategy(),
                referencingIdData, referencedEntityName, referencedIdData);

        // Creating common mapper data.
        CommonCollectionMapperData commonCollectionMapperData = new CommonCollectionMapperData(
                mainGenerator.getVerEntCfg(), referencedEntityName,
                propertyAuditingData.getPropertyData(),
                referencingIdData, queryGenerator);

        PropertyMapper fakeBidirectionalRelationMapper;
        PropertyMapper fakeBidirectionalRelationIndexMapper;
        if (fakeOneToManyBidirectional) {
            // 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

        // ******
        // Generating the mapping for the referencing entity (it must be an entity).
        // ******
        // Getting the id-mapping data of the referencing entity (the entity that "owns" this collection).
        IdMappingData referencingIdMapping = referencingEntityConfiguration.getIdMappingData();

        // Only valid for an inverse relation; null otherwise.
        String mappedBy;

        // The referencing prefix is always for a related entity. So it has always the "_" at the end added.
View Full Code Here

TOP

Related Classes of org.hibernate.envers.entities.IdMappingData

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.