Package org.hibernate.mapping

Examples of org.hibernate.mapping.PersistentClass


    public PersistentClass getClass(String entityName) {
      return classes.get( entityName );
    }

    public PersistentClass locatePersistentClassByEntityName(String entityName) {
      PersistentClass persistentClass = classes.get( entityName );
      if ( persistentClass == null ) {
        String actualEntityName = imports.get( entityName );
        if ( StringHelper.isNotEmpty( actualEntityName ) ) {
          persistentClass = classes.get( actualEntityName );
        }
View Full Code Here


            if (getCacheConcurrencyStrategy() != null) {

                Iterator iter = cfg.getClassMappings();
                while (iter.hasNext()) {
                    PersistentClass clazz = (PersistentClass) iter.next();
                    Iterator props = clazz.getPropertyClosureIterator();
                    boolean hasLob = false;
                    while (props.hasNext()) {
                        Property prop = (Property) props.next();
                        if (prop.getValue().isSimpleValue()) {
                            String type = ((SimpleValue) prop.getValue()).getTypeName();
                            if ("blob".equals(type) || "clob".equals(type))
                                hasLob = true;
                            if (Blob.class.getName().equals(type)
                                    || Clob.class.getName().equals(type))
                                hasLob = true;
                        }
                    }
                    if (!hasLob && !clazz.isInherited() && overrideCacheStrategy()) {
                        cfg.setCacheConcurrencyStrategy(clazz.getEntityName(),
                                getCacheConcurrencyStrategy());
                    }
                }

                iter = cfg.getCollectionMappings();
View Full Code Here

    {
        org.hibernate.cfg.Configuration config = sessionSource.getConfiguration();
        Iterator<PersistentClass> mappings = config.getClassMappings();
        while (mappings.hasNext())
        {
            final PersistentClass persistentClass = mappings.next();
            final Class entityClass = persistentClass.getMappedClass();

            ValueEncoderFactory factory = new ValueEncoderFactory()
            {
                public ValueEncoder create(Class type)
                {
View Full Code Here

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

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

            public Type getReferencedPropertyType(String persistentClass, String propertyName) throws MappingException
            {
        final PersistentClass pc = cfg.getClassMapping( persistentClass );
        if (pc==null) throw new MappingException("persistent class not known: " + persistentClass);
        Property prop = pc.getProperty(propertyName);
        if (prop==nullthrow new MappingException("property not known: " + persistentClass + '.' + propertyName);
        return prop.getType();
      }

      public IdentifierGeneratorFactory getIdentifierGeneratorFactory() {
View Full Code Here

        }
       
    if(getConfiguration()!=null) {
        Iterator classMappings = getConfiguration().getClassMappings();
        while (classMappings.hasNext() ) {
            PersistentClass element = (PersistentClass) classMappings.next();
            if(element instanceof RootClass) {
                dump(pw, ejb3, element);
            }
        }
    }
View Full Code Here

      pw.println("<mapping resource=\"" + getMappingFileResource(element) + "\"/>");
    }
     
    Iterator directSubclasses = element.getDirectSubclasses();
    while (directSubclasses.hasNext() ) {
      PersistentClass subclass = (PersistentClass) directSubclasses.next();
      dump(pw, useClass, subclass);   
    }
   
  }
View Full Code Here

      rc.setTable(table);
      try {
        mappings.addClass(rc);
      } catch(DuplicateMappingException dme) {
        // TODO: detect this and generate a "permutation" of it ?
        PersistentClass class1 = mappings.getClass(dme.getName());
        Table table2 = class1.getTable();
        throw new JDBCBinderException("Duplicate class name '" + rc.getEntityName() + "' generated for '" + table + "'. Same name where generated for '" + table2 + "'");
      }
      mappings.addImport( rc.getEntityName(), rc.getEntityName() );

      Set processed = new HashSet();
View Full Code Here

            Mappings mappings,
            java.util.Map inheritedMetas) throws MappingException {

        if(collection.isOneToMany() ) {
            OneToMany oneToMany = (OneToMany) collection.getElement();
            PersistentClass persistentClass = mappings.getClass(oneToMany.getReferencedEntityName() );

            if (persistentClass==null) throw new MappingException(
                    "Association " + collection.getRole() + " references unmapped class: " + oneToMany.getReferencedEntityName()
                );
View Full Code Here

        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

  }

  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

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.