Package org.hibernate.mapping

Examples of org.hibernate.mapping.PersistentClass


      return context.getSessionFactory()
          .getEntityPersister( ownerType.getTypeName() )
          .getEntityMetamodel();
    }
    else if ( persistenceType == Type.PersistenceType.MAPPED_SUPERCLASS) {
      PersistentClass persistentClass =
          context.getPersistentClassHostingProperties( (MappedSuperclassTypeImpl<?>) ownerType );
      return context.getSessionFactory()
        .getEntityPersister( persistentClass.getClassName() )
        .getEntityMetamodel();
    }
    else {
      throw new AssertionFailure( "Cannot get the metamodel for PersistenceType: " + persistenceType );
    }
View Full Code Here


  public void wrapUp() {
        LOG.trace("Wrapping up metadata context...");
    //we need to process types from superclasses to subclasses
    for (Object mapping : orderedMappings) {
      if ( PersistentClass.class.isAssignableFrom( mapping.getClass() ) ) {
        @SuppressWarnings( "unchecked" )
        final PersistentClass safeMapping = (PersistentClass) mapping;
                LOG.trace("Starting entity [" + safeMapping.getEntityName() + "]");
        try {
          final EntityTypeImpl<?> jpa2Mapping = entityTypesByPersistentClass.get( safeMapping );
          applyIdMetadata( safeMapping, jpa2Mapping );
          applyVersionAttribute( safeMapping, jpa2Mapping );
          Iterator<Property> properties = safeMapping.getDeclaredPropertyIterator();
          while ( properties.hasNext() ) {
            final Property property = properties.next();
            if ( property.getValue() == safeMapping.getIdentifierMapper() ) {
              // property represents special handling for id-class mappings but we have already
              // accounted for the embedded property mappings in #applyIdMetadata &&
              // #buildIdClassAttributes
              continue;
            }
            if ( safeMapping.isVersioned() && property == safeMapping.getVersion() ) {
              // skip the version property, it was already handled previously.
              continue;
            }
            final Attribute attribute = attributeFactory.buildAttribute( jpa2Mapping, property );
            if ( attribute != null ) {
              jpa2Mapping.getBuilder().addAttribute( attribute );
            }
          }
          jpa2Mapping.lock();
          populateStaticMetamodel( jpa2Mapping );
        }
        finally {
                    LOG.trace("Completed entity [" + safeMapping.getEntityName() + "]");
        }
      }
      else if ( MappedSuperclass.class.isAssignableFrom( mapping.getClass() ) ) {
        @SuppressWarnings( "unchecked" )
        final MappedSuperclass safeMapping = (MappedSuperclass) mapping;
                LOG.trace("Starting mapped superclass [" + safeMapping.getMappedClass().getName() + "]");
        try {
          final MappedSuperclassTypeImpl<?> jpa2Mapping = mappedSuperclassByMappedSuperclassMapping.get(
              safeMapping
          );
          applyIdMetadata( safeMapping, jpa2Mapping );
          applyVersionAttribute( safeMapping, jpa2Mapping );
          Iterator<Property> properties = safeMapping.getDeclaredPropertyIterator();
          while ( properties.hasNext() ) {
            final Property property = properties.next();
            if ( safeMapping.isVersioned() && property == safeMapping.getVersion() ) {
              // skip the version property, it was already handled previously.
              continue;
            }
            final Attribute attribute = attributeFactory.buildAttribute( jpa2Mapping, property );
            if ( attribute != null ) {
              jpa2Mapping.getBuilder().addAttribute( attribute );
            }
          }
          jpa2Mapping.lock();
          populateStaticMetamodel( jpa2Mapping );
        }
        finally {
                    LOG.trace("Completed mapped superclass [" + safeMapping.getMappedClass().getName() + "]");
        }
      }
      else {
        throw new AssertionFailure( "Unexpected mapping type: " + mapping.getClass() );
      }
View Full Code Here

  public void pushEntityWorkedOn(PersistentClass persistentClass) {
    stackOfPersistentClassesBeingProcessed.add(persistentClass);
  }

  public void popEntityWorkedOn(PersistentClass persistentClass) {
    final PersistentClass stackTop = stackOfPersistentClassesBeingProcessed.remove(
        stackOfPersistentClassesBeingProcessed.size() - 1
    );
    if (stackTop != persistentClass) {
      throw new AssertionFailure( "Inconsistent popping: "
        + persistentClass.getEntityName() + " instead of " + stackTop.getEntityName() );
    }
  }
View Full Code Here

          stackOfPersistentClassesBeingProcessed.size() - 1
      );
  }

  public PersistentClass getPersistentClassHostingProperties(MappedSuperclassTypeImpl<?> mappedSuperclassType) {
    final PersistentClass persistentClass = mappedSuperClassTypeToPersistentClass.get( mappedSuperclassType );
    if (persistentClass == null) {
      throw new AssertionFailure( "Could not find PersistentClass for MappedSuperclassType: "
          + mappedSuperclassType.getJavaType() );
    }
    return persistentClass;
View Full Code Here

    //add @MappedSuperclass in the metadata
    // classes from 0 to n-1 are @MappedSuperclass and should be linked
    org.hibernate.mapping.MappedSuperclass mappedSuperclass = null;
    final InheritanceState superEntityState =
        InheritanceState.getInheritanceStateOfSuperEntity( clazz, inheritanceStatePerClass );
    PersistentClass superEntity =
        superEntityState != null ?
            mappings.getClass( superEntityState.getClazz().getName() ) :
            null;
    final int lastMappedSuperclass = classesToProcessForMappedSuperclass.size() - 1;
    for ( int index = 0; index < lastMappedSuperclass; index++ ) {
View Full Code Here

      new SingletonIterator(model),
      model.getSubclassIterator()
    );

    while ( siter.hasNext() ) {
      PersistentClass clazz = (PersistentClass) siter.next();
      Table table = clazz.getTable();
      if ( !table.isAbstractUnionTable() ) {
        //TODO: move to .sql package!!
        buf.append("select ");
        Iterator citer = columns.iterator();
        while ( citer.hasNext() ) {
          Column col = (Column) citer.next();
          if ( !table.containsColumn(col) ) {
            int sqlType = col.getSqlTypeCode(mapping);
            buf.append( dialect.getSelectClauseNullString(sqlType) )
              .append(" as ");
          }
          buf.append( col.getName() );
          buf.append(", ");
        }
        buf.append( clazz.getSubclassId() )
          .append(" as clazz_");
        buf.append(" from ")
          .append( table.getQualifiedName(
              dialect,
              settings.getDefaultCatalogName(),
View Full Code Here

    Map<String, Set<FkSecondPass>> isADependencyOf = new HashMap<String, Set<FkSecondPass>>();
    List<FkSecondPass> endOfQueueFkSecondPasses = new ArrayList<FkSecondPass>( fkSecondPasses.size() );
    for ( FkSecondPass sp : fkSecondPasses ) {
      if ( sp.isInPrimaryKey() ) {
        String referenceEntityName = sp.getReferencedEntityName();
        PersistentClass classMapping = getClassMapping( referenceEntityName );
        String dependentTable = classMapping.getTable().getQuotedName();
        if ( !isADependencyOf.containsKey( dependentTable ) ) {
          isADependencyOf.put( dependentTable, new HashSet<FkSecondPass>() );
        }
        isADependencyOf.get( dependentTable ).add( sp );
      }
View Full Code Here

    itr = propertyReferences.iterator();
    while ( itr.hasNext() ) {
      Mappings.PropertyReference upr = (Mappings.PropertyReference) itr.next();

      PersistentClass clazz = getClassMapping( upr.referencedClass );
      if ( clazz == null ) {
        throw new MappingException(
            "property-ref to unmapped class: " +
            upr.referencedClass
          );
      }

      Property prop = clazz.getReferencedProperty( upr.propertyName );
      if ( upr.unique ) {
        ( (SimpleValue) prop.getValue() ).setAlternateUniqueKey( true );
      }
    }
View Full Code Here

            );
        }
        if ( log.isDebugEnabled() ) {
          log.debug( "resolving reference to class: " + referencedEntityName );
        }
        PersistentClass referencedClass = classes.get( referencedEntityName );
        if ( referencedClass == null ) {
          throw new MappingException(
              "An association from the table " +
              fk.getTable().getName() +
              " refers to an unmapped class: " +
              referencedEntityName
            );
        }
        if ( referencedClass.isJoinedSubclass() ) {
          secondPassCompileForeignKeys( referencedClass.getSuperclass().getTable(), done );
        }
        fk.setReferencedTable( referencedClass.getTable() );
        fk.alignColumns();
      }
    }
  }
View Full Code Here

      /**
       * Returns the identifier type of a mapped class
       */
      public Type getIdentifierType(String entityName) throws MappingException {
        PersistentClass pc = classes.get( entityName );
        if ( pc == null ) {
          throw new MappingException( "persistent class not known: " + entityName );
        }
        return pc.getIdentifier().getType();
      }

      public String getIdentifierPropertyName(String entityName) throws MappingException {
        final PersistentClass pc = classes.get( entityName );
        if ( pc == null ) {
          throw new MappingException( "persistent class not known: " + entityName );
        }
        if ( !pc.hasIdentifierProperty() ) {
          return null;
        }
        return pc.getIdentifierProperty().getName();
      }

      public Type getReferencedPropertyType(String entityName, String propertyName) throws MappingException {
        final PersistentClass pc = classes.get( entityName );
        if ( pc == null ) {
          throw new MappingException( "persistent class not known: " + entityName );
        }
        Property prop = pc.getReferencedProperty( propertyName );
        if ( prop == null ) {
          throw new MappingException(
              "property not known: " +
              entityName + '.' + propertyName
            );
View Full Code Here

TOP

Related Classes of org.hibernate.mapping.PersistentClass

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.