Package org.hibernate.envers.internal.entities

Examples of org.hibernate.envers.internal.entities.IdMappingData


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

    if ( !isAudited ) {
      final String entityName = pc.getEntityName();
      final 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;
      }

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

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

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

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

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

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

    final InheritanceType inheritanceType = InheritanceType.get( pc );

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


      CompositeMapperBuilder mapper,
      String entityName,
      boolean insertable) {
    final String referencedEntityName = ((ToOne) value).getReferencedEntityName();

    final IdMappingData idMapping = mainGenerator.getReferencedIdMappingData(
        entityName,
        referencedEntityName,
        propertyAuditingData,
        true
    );

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

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

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

    // If the property isn't insertable, checking if this is not a "fake" bidirectional many-to-one relationship,
    // that is, when the one side owns the relation (and is a collection), and the many side is non insertable.
    // When that's the case and the user specified to store this relation without a middle table (using
    // @AuditMappedBy), we have to make the property insertable for the purposes of Envers. In case of changes to
    // the entity that didn't involve the relation, it's value will then be stored properly. In case of changes
    // to the entity that did involve the relation, it's the responsibility of the collection side to store the
    // proper data.
    boolean nonInsertableFake;
    if ( !insertable && propertyAuditingData.isForceInsertable() ) {
      nonInsertableFake = true;
      insertable = true;
    }
    else {
      nonInsertableFake = false;
    }

    // Adding an element to the mapping corresponding to the references entity id's
    final Element properties = (Element) idMapping.getXmlRelationMapping().clone();
    properties.addAttribute( "name", propertyAuditingData.getName() );

    MetadataTools.prefixNamesInPropertyElement(
        properties,
        lastPropertyPrefix,
View Full Code Here

    final EntityConfiguration configuration = mainGenerator.getEntitiesConfigurations().get( entityName );
    if ( configuration == null ) {
      throw new MappingException( "An audited relation to a non-audited entity " + entityName + "!" );
    }

    final IdMappingData ownedIdMapping = configuration.getIdMappingData();

    if ( ownedIdMapping == null ) {
      throw new MappingException( "An audited relation to a non-audited entity " + entityName + "!" );
    }

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

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

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

      CompositeMapperBuilder mapper,
      String entityName,
      boolean insertable) {
    final String referencedEntityName = ((ToOne) value).getReferencedEntityName();

    final IdMappingData idMapping = mainGenerator.getReferencedIdMappingData(
        entityName,
        referencedEntityName,
        propertyAuditingData,
        true
    );

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

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

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

      CompositeMapperBuilder mapper,
      String entityName,
      boolean insertable) {
    final String referencedEntityName = ((ToOne) value).getReferencedEntityName();

    final IdMappingData idMapping = mainGenerator.getReferencedIdMappingData(
        entityName,
        referencedEntityName,
        propertyAuditingData,
        true
    );

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

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

    // Storing information about this relation
    mainGenerator.getEntitiesConfigurations().get( entityName ).addToOneRelation(
        propertyAuditingData.getName(), referencedEntityName, relMapper,
        insertable, MappingTools.ignoreNotFound( value )
    );

    // If the property isn't insertable, checking if this is not a "fake" bidirectional many-to-one relationship,
    // that is, when the one side owns the relation (and is a collection), and the many side is non insertable.
    // When that's the case and the user specified to store this relation without a middle table (using
    // @AuditMappedBy), we have to make the property insertable for the purposes of Envers. In case of changes to
    // the entity that didn't involve the relation, it's value will then be stored properly. In case of changes
    // to the entity that did involve the relation, it's the responsibility of the collection side to store the
    // proper data.
    boolean nonInsertableFake;
    if ( !insertable && propertyAuditingData.isForceInsertable() ) {
      nonInsertableFake = true;
      insertable = true;
    }
    else {
      nonInsertableFake = false;
    }

    // Adding an element to the mapping corresponding to the references entity id's
    final Element properties = (Element) idMapping.getXmlRelationMapping().clone();
    properties.addAttribute( "name", propertyAuditingData.getName() );

    MetadataTools.prefixNamesInPropertyElement(
        properties,
        lastPropertyPrefix,
View Full Code Here

    final EntityConfiguration configuration = mainGenerator.getEntitiesConfigurations().get( entityName );
    if ( configuration == null ) {
      throw new MappingException( "An audited relation to a non-audited entity " + entityName + "!" );
    }

    final IdMappingData ownedIdMapping = configuration.getIdMappingData();

    if ( ownedIdMapping == null ) {
      throw new MappingException( "An audited relation to a non-audited entity " + entityName + "!" );
    }

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

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

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

      CompositeMapperBuilder mapper,
      String entityName,
      boolean insertable) {
    final String referencedEntityName = ((ToOne) value).getReferencedEntityName();

    final IdMappingData idMapping = mainGenerator.getReferencedIdMappingData(
        entityName,
        referencedEntityName,
        propertyAuditingData,
        true
    );

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

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

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

        propertyName
    );

    final String mappedBy = getMappedBy( propertyValue );

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

    // Generating the id mappers data for the referencing side of the relation.
    final 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).
    final MiddleIdData referencedIdData = createMiddleIdData(
        referencedIdMapping,
        null, referencedEntityName
    );

    // Generating the element mapping.
    final 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.
    final RelationQueryGenerator queryGenerator = new OneAuditEntityQueryGenerator(
        mainGenerator.getGlobalCfg(),
        mainGenerator.getVerEntCfg(),
        mainGenerator.getAuditStrategy(),
        referencingIdData,
        referencedEntityName,
        referencedIdData,
        isEmbeddableElementType()
    );

    // Creating common mapper data.
    final 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).
      final String auditMappedBy = propertyAuditingData.getAuditMappedBy();

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

      fakeBidirectionalRelationMapper = new ToOneIdMapper(
          relMapper,
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).
    final 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

            "mapkey",
            null
        );
      }
      else {
        final IdMappingData referencedIdMapping = mainGenerator.getEntitiesConfigurations()
            .get( referencedEntityName ).getIdMappingData();
        final 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 {
View Full Code Here

TOP

Related Classes of org.hibernate.envers.internal.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.