Package org.hibernate.mapping

Examples of org.hibernate.mapping.Collection


    Value value = property.getValue();
    int span;
    Iterator columnIterator;
    Iterator referencedColumnsIterator = null;
    if (value != null && value instanceof Collection) {
      Collection collection = (Collection) value;
      span = collection.getKey().getColumnSpan();
      columnIterator = collection.getKey().getColumnIterator();
    }
    else {
      span = property.getColumnSpan();
      columnIterator = property.getColumnIterator();
    }
View Full Code Here


  public String generateCollectionAnnotation(Property property, Configuration cfg) {
    StringBuffer annotation = new StringBuffer();
    Value value = property.getValue();
    if ( value != null && value instanceof Collection) {
      Collection collection = (Collection) value;
      if ( collection.isOneToMany() ) {
        String mappedBy = null;
        AnnotationBuilder ab = AnnotationBuilder.createAnnotation( importType( "javax.persistence.OneToMany") );
        ab.addAttribute( "cascade", getCascadeTypes( property ) );
        ab.addAttribute( "fetch", getFetchType (property) );
        if ( collection.isInverse() ) {
          mappedBy = getOneToManyMappedBy( cfg, collection );
          ab.addQuotedAttribute( "mappedBy", mappedBy );
        }
        annotation.append( ab.getResult() );

        if (mappedBy == null) annotation.append("\n").append( generateJoinColumnsAnnotation(property, cfg) );
      }
      else {
        //TODO do the @OneToMany @JoinTable
        //TODO composite element
        String mappedBy = null;
        AnnotationBuilder ab = AnnotationBuilder.createAnnotation( importType( "javax.persistence.ManyToMany") );
        ab.addAttribute( "cascade", getCascadeTypes( property ) );
        ab.addAttribute( "fetch", getFetchType (property) );

        if ( collection.isInverse() ) {
          mappedBy = getManyToManyMappedBy( cfg, collection );
          ab.addQuotedAttribute( "mappedBy", mappedBy );
        }
        annotation.append(ab.getResult());
        if (mappedBy == null) {
          annotation.append("\n    @");
          annotation.append( importType( "javax.persistence.JoinTable") ).append( "(name=\"" );
          Table table = collection.getCollectionTable();

          annotation.append( table.getName() );
          annotation.append( "\"" );
          if ( StringHelper.isNotEmpty( table.getSchema() ) ) {
            annotation.append(", schema=\"").append( table.getSchema() ).append("\"");
          }
          if ( StringHelper.isNotEmpty( table.getCatalog() ) ) {
            annotation.append(", catalog=\"").append( table.getCatalog() ).append("\"");
          }
          String uniqueConstraint = generateAnnTableUniqueConstraint(table);
          if ( uniqueConstraint.length() > 0 ) {
            annotation.append(", uniqueConstraints=").append(uniqueConstraint);
          }
          annotation.append( ", joinColumns = { ");
          buildArrayOfJoinColumnAnnotation(
              collection.getKey().getColumnIterator(),
              null,
              annotation,
              property.isInsertable(),
              property.isUpdateable()
          );
          annotation.append( " }");
          annotation.append( ", inverseJoinColumns = { ");
          buildArrayOfJoinColumnAnnotation(
              collection.getElement().getColumnIterator(),
              null,
              annotation,
              property.isInsertable(),
              property.isUpdateable()
          );
View Full Code Here

    mappedBy = "unresolved";
    while ( ! isOtherSide && properties.hasNext() ) {
      Property collectionProperty = (Property) properties.next();
      Value collectionValue = collectionProperty.getValue();
      if ( collectionValue != null && collectionValue instanceof Collection ) {
        Collection realCollectionValue = (Collection) collectionValue;
        if ( ! realCollectionValue.isOneToMany() ) {
          if ( joinColumns.size() == realCollectionValue.getElement().getColumnSpan() ) {
            isOtherSide = true;
            Iterator it = realCollectionValue.getElement().getColumnIterator();
            while ( it.hasNext() ) {
              Object column = it.next();
              if (! joinColumns.contains( column ) ) {
                isOtherSide = false;
                break;
View Full Code Here

      }
    }

    iter = getConfiguration().getCollectionMappings();
    while ( iter.hasNext() ) {
      Collection collection = (Collection) iter.next();

      if ( collection.isIdentified() ) {

        IdentifierGenerator ig = ( (IdentifierCollection) collection ).getIdentifier()
            .createIdentifierGenerator(
                getConfiguration().getIdentifierGeneratorFactory(),
                dialect,
View Full Code Here

  }
  public void visitProperty(Configuration configuration, PersistentClass clazz, Property property, IssueCollector collector) {
    Value value = property.getValue();
   
    if(value instanceof Collection) {
      Collection col = (Collection) value;
      if(col.getCacheConcurrencyStrategy()!=null) { // caching is enabled
        if (!col.getElement().isSimpleValue()) {
          String entityName = (String) col.getElement().accept( new EntityNameFromValueVisitor() );

          if(entityName!=null) {
            PersistentClass classMapping = configuration.getClassMapping( entityName );
            if(classMapping.getCacheConcurrencyStrategy()==null) {
              collector.reportIssue( new Issue("CACHE_COLLECTION_NONCACHABLE_TARGET", Issue.HIGH_PRIORITY, "Entity '" + classMapping.getEntityName() +"' is referenced from the cache-enabled collection '" + col.getRole() + "' without the entity being cachable"));
            }
          }
        }
      }
    } 
View Full Code Here

      return MetaAttributeHelper.getMetaAsString( p.getMetaAttribute( "default-value" ) );
    }
    if(c2j.getJavaTypeName(p, false)==null) {
      throw new IllegalArgumentException();
    } else if (p.getValue() instanceof Collection) {
      Collection col = (Collection) p.getValue();
     
      DefaultInitializor initialization = (DefaultInitializor) col.accept(new DefaultValueVisitor(true) {
      
        public Object accept(Bag o) {
          return new DefaultInitializor("java.util.ArrayList", true);
        }
       
        public Object accept(org.hibernate.mapping.List o) {
          return new DefaultInitializor("java.util.ArrayList", true);
        }
       
        public Object accept(org.hibernate.mapping.Map o) {
          if(o.isSorted()) {
            return new DefaultInitializor("java.util.TreeMap", false);
          } else {
            return new DefaultInitializor("java.util.HashMap", true);
          }
        }
       
        public Object accept(IdentifierBag o) {
          return new DefaultInitializor("java.util.ArrayList", true);
        }
       
        public Object accept(Set o) {
          if(o.isSorted()) {
            return new DefaultInitializor("java.util.TreeSet", false);
          } else {
            return new DefaultInitializor("java.util.HashSet", true);
          }
        }
       
       
        public Object accept(PrimitiveArray o) {
          return null; // TODO: default init for arrays ?
        }
       
        public Object accept(Array o) {
          return null;// TODO: default init for arrays ?
        }
       
      });
            
      if(initialization!=null) {
        String comparator = null;
        String decl = null;

        if(col.isSorted()) {
          comparator = col.getComparatorClassName();
        }

        if(useGenerics) {
          decl = c2j.getGenericCollectionDeclaration((Collection) p.getValue(), true, importContext);
        }
View Full Code Here

        .qualify( path, propertyName );

      CollectionType collectType = CollectionType.collectionTypeFromString( name );
      Value value = null;
      if ( collectType != null ) {
        Collection collection = collectType.create(
            subnode,
            subpath,
            component.getOwner(),
            mappings, inheritedMetas
          );
View Full Code Here

      String propertyName = subnode.attributeValue( "name" );

      CollectionType collectType = CollectionType.collectionTypeFromString( name );
      Value value = null;
      if ( collectType != null ) {
        Collection collection = collectType.create(
            subnode,
            StringHelper.qualify( entityName, propertyName ),
            persistentClass,
            mappings, inheritedMetas
          );
View Full Code Here

      if ( propertyRef != null ) {
        mappings.addUniquePropertyReference( toOne.getReferencedEntityName(), propertyRef );
      }
    }
    else if ( value instanceof Collection ) {
      Collection coll = (Collection) value;
      String propertyRef = coll.getReferencedPropertyName();
      // not necessarily a *unique* property reference
      if ( propertyRef != null ) {
        mappings.addPropertyReference( coll.getOwnerEntityName(), propertyRef );
      }
    }

    value.createForeignKey();
    Property prop = new Property();
View Full Code Here

      }
    }

    iter = collections.values().iterator();
    while ( iter.hasNext() ) {
      Collection collection = ( Collection ) iter.next();
      if ( collection.isIdentified() ) {
        IdentifierGenerator ig = ( ( IdentifierCollection ) collection ).getIdentifier().createIdentifierGenerator(
            getIdentifierGeneratorFactory(),
            dialect,
            defaultCatalog,
            defaultSchema,
View Full Code Here

TOP

Related Classes of org.hibernate.mapping.Collection

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.