Examples of PersistentClass


Examples of org.hibernate.mapping.PersistentClass

        RootClass rootclass = new RootClass();
        bindRootClass( element, rootclass, mappings, inheritedMetas );
        mappings.addClass( rootclass );
      }
      else if ( "subclass".equals( elementName ) ) {
        PersistentClass superModel = getSuperclass( mappings, element );
        handleSubclass( superModel, mappings, element, inheritedMetas );
      }
      else if ( "joined-subclass".equals( elementName ) ) {
        PersistentClass superModel = getSuperclass( mappings, element );
        handleJoinedSubclass( superModel, mappings, element, inheritedMetas );
      }
      else if ( "union-subclass".equals( elementName ) ) {
        PersistentClass superModel = getSuperclass( mappings, element );
        handleUnionSubclass( superModel, mappings, element, inheritedMetas );
      }
      else if ( "query".equals( elementName ) ) {
        bindNamedQuery( element, null, mappings );
      }
View Full Code Here

Examples of org.hibernate.mapping.PersistentClass

  }

  private static void bindJoin(Element node, Join join, Mappings mappings,
      java.util.Map inheritedMetas) throws MappingException {

    PersistentClass persistentClass = join.getPersistentClass();
    String path = persistentClass.getEntityName();

    // TABLENAME

    Attribute schemaNode = node.attribute( "schema" );
    String schema = schemaNode == null ?
        mappings.getSchemaName() : schemaNode.getValue();
    Attribute catalogNode = node.attribute( "catalog" );
    String catalog = catalogNode == null ?
        mappings.getCatalogName() : catalogNode.getValue();
    Table primaryTable = persistentClass.getTable();
    Table table = mappings.addTable(
        schema,
        catalog,
        getClassTableName( persistentClass, node, schema, catalog, primaryTable, mappings ),
        getSubselect( node ),
        false
      );
    join.setTable( table );
    bindComment(table, node);

    Attribute fetchNode = node.attribute( "fetch" );
    if ( fetchNode != null ) {
      join.setSequentialSelect( "select".equals( fetchNode.getValue() ) );
    }

    Attribute invNode = node.attribute( "inverse" );
    if ( invNode != null ) {
      join.setInverse( "true".equals( invNode.getValue() ) );
    }

    Attribute nullNode = node.attribute( "optional" );
    if ( nullNode != null ) {
      join.setOptional( "true".equals( nullNode.getValue() ) );
    }

    log.info(
        "Mapping class join: " + persistentClass.getEntityName() +
        " -> " + join.getTable().getName()
      );

    // KEY
    Element keyNode = node.element( "key" );
    SimpleValue key = new DependantValue( table, persistentClass.getIdentifier() );
    join.setKey( key );
    key.setCascadeDeleteEnabled( "cascade".equals( keyNode.attributeValue( "on-delete" ) ) );
    bindSimpleValue( keyNode, key, false, persistentClass.getEntityName(), mappings );

    // join.getKey().setType( new Type( lazz.getIdentifier() ) );
    join.createPrimaryKey();
    join.createForeignKey();

    // PROPERTIES
    Iterator iter = node.elementIterator();
    while ( iter.hasNext() ) {
      Element subnode = (Element) iter.next();
      String name = subnode.getName();
      String propertyName = subnode.attributeValue( "name" );

      Value value = null;
      if ( "many-to-one".equals( name ) ) {
        value = new ManyToOne( table );
        bindManyToOne( subnode, (ManyToOne) value, propertyName, true, mappings );
      }
      else if ( "any".equals( name ) ) {
        value = new Any( table );
        bindAny( subnode, (Any) value, true, mappings );
      }
      else if ( "property".equals( name ) ) {
        value = new SimpleValue( table );
        bindSimpleValue( subnode, (SimpleValue) value, true, propertyName, mappings );
      }
      else if ( "component".equals( name ) || "dynamic-component".equals( name ) ) {
        String subpath = StringHelper.qualify( path, propertyName );
        value = new Component( join );
        bindComponent(
            subnode,
            (Component) value,
            join.getPersistentClass().getClassName(),
            propertyName,
            subpath,
            true,
            false,
            mappings,
            inheritedMetas,
            false
          );
      }

      if ( value != null ) {
        Property prop = createProperty( value, propertyName, persistentClass
          .getEntityName(), subnode, mappings, inheritedMetas );
        prop.setOptional( join.isOptional() );
        join.addProperty( prop );
      }
View Full Code Here

Examples of org.hibernate.mapping.PersistentClass

    if ( baseIndex != null ) list.setBaseIndex( Integer.parseInt( baseIndex ) );
    list.setIndexNodeName( subnode.attributeValue("node") );

    if ( list.isOneToMany() && !list.getKey().isNullable() && !list.isInverse() ) {
      String entityName = ( (OneToMany) list.getElement() ).getReferencedEntityName();
      PersistentClass referenced = mappings.getClass( entityName );
      IndexBackref ib = new IndexBackref();
      ib.setName( '_' + list.getOwnerEntityName() + "." + node.attributeValue( "name" ) + "IndexBackref" );
      ib.setUpdateable( false );
      ib.setSelectable( false );
      ib.setCollectionRole( list.getRole() );
      ib.setEntityName( list.getOwner().getEntityName() );
      ib.setValue( list.getIndex() );
      // ( (Column) ( (SimpleValue) ic.getIndex() ).getColumnIterator().next()
      // ).setNullable(false);
      referenced.addProperty( ib );
    }
  }
View Full Code Here

Examples of org.hibernate.mapping.PersistentClass

      if ( ( (Selectable) colIter.next() ).isFormula() ) indexIsFormula = true;
    }

    if ( map.isOneToMany() && !map.getKey().isNullable() && !map.isInverse() && !indexIsFormula ) {
      String entityName = ( (OneToMany) map.getElement() ).getReferencedEntityName();
      PersistentClass referenced = mappings.getClass( entityName );
      IndexBackref ib = new IndexBackref();
      ib.setName( '_' + map.getOwnerEntityName() + "." + node.attributeValue( "name" ) + "IndexBackref" );
      ib.setUpdateable( false );
      ib.setSelectable( false );
      ib.setCollectionRole( map.getRole() );
      ib.setEntityName( map.getOwner().getEntityName() );
      ib.setValue( map.getIndex() );
      // ( (Column) ( (SimpleValue) ic.getIndex() ).getColumnIterator().next()
      // ).setNullable(false);
      referenced.addProperty( ib );
    }
  }
View Full Code Here

Examples of org.hibernate.mapping.PersistentClass

      throws MappingException {

    if ( collection.isOneToMany() ) {
      OneToMany oneToMany = (OneToMany) collection.getElement();
      String assocClass = oneToMany.getReferencedEntityName();
      PersistentClass persistentClass = (PersistentClass) persistentClasses.get( assocClass );
      if ( persistentClass == null ) {
        throw new MappingException( "Association references unmapped class: " + assocClass );
      }
      oneToMany.setAssociatedClass( persistentClass );
      collection.setCollectionTable( persistentClass.getTable() );

      log.info(
          "Mapping collection: " + collection.getRole() +
          " -> " + collection.getCollectionTable().getName()
        );
    }

    // CHECK
    Attribute chNode = node.attribute( "check" );
    if ( chNode != null ) {
      collection.getCollectionTable().addCheckConstraint( chNode.getValue() );
    }

    // contained elements:
    Iterator iter = node.elementIterator();
    while ( iter.hasNext() ) {
      Element subnode = (Element) iter.next();
      String name = subnode.getName();

      if ( "key".equals( name ) ) {
        KeyValue keyVal;
        String propRef = collection.getReferencedPropertyName();
        if ( propRef == null ) {
          keyVal = collection.getOwner().getIdentifier();
        }
        else {
          keyVal = (KeyValue) collection.getOwner().getRecursiveProperty( propRef ).getValue();
        }
        SimpleValue key = new DependantValue( collection.getCollectionTable(), keyVal );
        key.setCascadeDeleteEnabled( "cascade"
          .equals( subnode.attributeValue( "on-delete" ) ) );
        bindSimpleValue(
            subnode,
            key,
            collection.isOneToMany(),
            Collection.DEFAULT_KEY_COLUMN_NAME,
            mappings
          );
        collection.setKey( key );

        Attribute notNull = subnode.attribute( "not-null" );
        ( (DependantValue) key ).setNullable( notNull == null
          || notNull.getValue().equals( "false" ) );
        Attribute updateable = subnode.attribute( "update" );
        ( (DependantValue) key ).setUpdateable( updateable == null
          || updateable.getValue().equals( "true" ) );

      }
      else if ( "element".equals( name ) ) {
        SimpleValue elt = new SimpleValue( collection.getCollectionTable() );
        collection.setElement( elt );
        bindSimpleValue(
            subnode,
            elt,
            true,
            Collection.DEFAULT_ELEMENT_COLUMN_NAME,
            mappings
          );
      }
      else if ( "many-to-many".equals( name ) ) {
        ManyToOne element = new ManyToOne( collection.getCollectionTable() );
        collection.setElement( element );
        bindManyToOne(
            subnode,
            element,
            Collection.DEFAULT_ELEMENT_COLUMN_NAME,
            false,
            mappings
          );
        bindManyToManySubelements( collection, subnode, mappings );
      }
      else if ( "composite-element".equals( name ) ) {
        Component element = new Component( collection );
        collection.setElement( element );
        bindComposite(
            subnode,
            element,
            collection.getRole() + ".element",
            true,
            mappings,
            inheritedMetas
          );
      }
      else if ( "many-to-any".equals( name ) ) {
        Any element = new Any( collection.getCollectionTable() );
        collection.setElement( element );
        bindAny( subnode, element, true, mappings );
      }
      else if ( "cache".equals( name ) ) {
        collection.setCacheConcurrencyStrategy( subnode.attributeValue( "usage" ) );
        collection.setCacheRegionName( subnode.attributeValue( "region" ) );
      }

      String nodeName = subnode.attributeValue( "node" );
      if ( nodeName != null ) collection.setElementNodeName( nodeName );

    }

    if ( collection.isOneToMany()
      && !collection.isInverse()
      && !collection.getKey().isNullable() ) {
      // for non-inverse one-to-many, with a not-null fk, add a backref!
      String entityName = ( (OneToMany) collection.getElement() ).getReferencedEntityName();
      PersistentClass referenced = mappings.getClass( entityName );
      Backref prop = new Backref();
      prop.setName( '_' + collection.getOwnerEntityName() + "." + node.attributeValue( "name" ) + "Backref" );
      prop.setUpdateable( false );
      prop.setSelectable( false );
      prop.setCollectionRole( collection.getRole() );
      prop.setEntityName( collection.getOwner().getEntityName() );
      prop.setValue( collection.getKey() );
      referenced.addProperty( prop );
    }
  }
View Full Code Here

Examples of org.hibernate.mapping.PersistentClass

  }

  private static PersistentClass getSuperclass(Mappings mappings, Element subnode)
      throws MappingException {
    String extendsName = subnode.attributeValue( "extends" );
    PersistentClass superModel = mappings.getClass( extendsName );
    if ( superModel == null ) {
      String qualifiedExtendsName = getClassName( extendsName, mappings );
      superModel = mappings.getClass( qualifiedExtendsName );
    }
View Full Code Here

Examples of org.hibernate.mapping.PersistentClass

  Dom4jEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappedEntity) {
    super(entityMetamodel, mappedEntity);
    Iterator itr = mappedEntity.getSubclassClosureIterator();
    while( itr.hasNext() ) {
      final PersistentClass mapping = ( PersistentClass ) itr.next();
      subclassNodeNames.add( mapping.getNodeName() );
    }
  }
View Full Code Here

Examples of org.hibernate.mapping.PersistentClass

    //Generators:

    identifierGenerators = new HashMap();
    Iterator classes = cfg.getClassMappings();
    while ( classes.hasNext() ) {
      PersistentClass model = (PersistentClass) classes.next();
      if ( !model.isInherited() ) {
        IdentifierGenerator generator = model.getIdentifier().createIdentifierGenerator(
            settings.getDialect(),
                settings.getDefaultCatalogName(),
                settings.getDefaultSchemaName(),
                (RootClass) model
          );
        identifierGenerators.put( model.getEntityName(), generator );
      }
    }


    ///////////////////////////////////////////////////////////////////////
    // Prepare persisters and link them up with their cache
    // region/access-strategy

    final String cacheRegionPrefix = settings.getCacheRegionPrefix() == null ? "" : settings.getCacheRegionPrefix() + ".";

    entityPersisters = new HashMap();
    Map entityAccessStrategies = new HashMap();
    Map classMeta = new HashMap();
    classes = cfg.getClassMappings();
    while ( classes.hasNext() ) {
      final PersistentClass model = (PersistentClass) classes.next();
      model.prepareTemporaryTables( mapping, settings.getDialect() );
      final String cacheRegionName = cacheRegionPrefix + model.getRootClass().getCacheRegionName();
      // cache region is defined by the root-class in the hierarchy...
      EntityRegionAccessStrategy accessStrategy = ( EntityRegionAccessStrategy ) entityAccessStrategies.get( cacheRegionName );
      if ( accessStrategy == null && settings.isSecondLevelCacheEnabled() ) {
        final AccessType accessType = AccessType.parse( model.getCacheConcurrencyStrategy() );
        if ( accessType != null ) {
          log.trace( "Building cache for entity data [" + model.getEntityName() + "]" );
          EntityRegion entityRegion = settings.getRegionFactory().buildEntityRegion( cacheRegionName, properties, CacheDataDescriptionImpl.decode( model ) );
          accessStrategy = entityRegion.buildAccessStrategy( accessType );
          entityAccessStrategies.put( cacheRegionName, accessStrategy );
          allCacheRegions.put( cacheRegionName, entityRegion );
        }
      }
      EntityPersister cp = PersisterFactory.createClassPersister( model, accessStrategy, this, mapping );
      entityPersisters.put( model.getEntityName(), cp );
      classMeta.put( model.getEntityName(), cp.getClassMetadata() );
    }
    classMetadata = Collections.unmodifiableMap(classMeta);

    Map tmpEntityToCollectionRoleMap = new HashMap();
    collectionPersisters = new HashMap();
    Iterator collections = cfg.getCollectionMappings();
    while ( collections.hasNext() ) {
      Collection model = (Collection) collections.next();
      final String cacheRegionName = cacheRegionPrefix + model.getCacheRegionName();
      final AccessType accessType = AccessType.parse( model.getCacheConcurrencyStrategy() );
      CollectionRegionAccessStrategy accessStrategy = null;
      if ( accessType != null && settings.isSecondLevelCacheEnabled() ) {
        log.trace( "Building cache for collection data [" + model.getRole() + "]" );
        CollectionRegion collectionRegion = settings.getRegionFactory().buildCollectionRegion( cacheRegionName, properties, CacheDataDescriptionImpl.decode( model ) );
        accessStrategy = collectionRegion.buildAccessStrategy( accessType );
        entityAccessStrategies.put( cacheRegionName, accessStrategy );
        allCacheRegions.put( cacheRegionName, collectionRegion );
      }
      CollectionPersister persister = PersisterFactory.createCollectionPersister( cfg, model, accessStrategy, this) ;
      collectionPersisters.put( model.getRole(), persister.getCollectionMetadata() );
      Type indexType = persister.getIndexType();
      if ( indexType != null && indexType.isAssociationType() && !indexType.isAnyType() ) {
        String entityName = ( ( AssociationType ) indexType ).getAssociatedEntityName( this );
        Set roles = ( Set ) tmpEntityToCollectionRoleMap.get( entityName );
        if ( roles == null ) {
View Full Code Here

Examples of org.hibernate.mapping.PersistentClass

    if(entityName==null) {
      throw new MappingException( "<return alias='" + alias + "'> must specify either a class or entity-name");
    }
    LockMode lockMode = getLockMode( returnElem.attributeValue( "lock-mode" ) );

    PersistentClass pc = mappings.getClass( entityName );
    java.util.Map propertyResults = bindPropertyResults(alias, returnElem, pc, mappings );

    return new NativeSQLQueryRootReturn(
        alias,
        entityName,
View Full Code Here

Examples of org.hibernate.mapping.PersistentClass

          Component comp = (Component) value;
          parentPropIter = comp.getPropertyIterator();
        }
        else if ( value instanceof ToOne ) {
          ToOne toOne = (ToOne) value;
          PersistentClass referencedPc = mappings.getClass( toOne.getReferencedEntityName() );
          if ( toOne.getReferencedPropertyName() != null ) {
            try {
              parentPropIter = ( (Component) referencedPc.getRecursiveProperty( toOne.getReferencedPropertyName() ).getValue() ).getPropertyIterator();
            } catch (ClassCastException e) {
              throw new MappingException("dotted notation reference neither a component nor a many/one to one", e);
            }
          }
          else {
            try {
              if ( referencedPc.getIdentifierMapper() == null ) {
                parentPropIter = ( (Component) referencedPc.getIdentifierProperty().getValue() ).getPropertyIterator();
              }
              else {
                parentPropIter = referencedPc.getIdentifierMapper().getPropertyIterator();
              }
            }
            catch (ClassCastException e) {
              throw new MappingException("dotted notation reference neither a component nor a many/one to one", e);
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.