Package javax.persistence

Examples of javax.persistence.JoinColumn


          this.checkFetch(collection, manyToOne, beanDescriptor, propertyDescriptor, fetchType);

          if (!propertyDescriptor.isAnnotationPresent(JoinColumn.class)) {
            collection.add("Missing @JoinColumn on " + beanDescriptor.getType().getCanonicalName() + "." + propertyDescriptor.getName());
          } else {
            JoinColumn joinColumn = propertyDescriptor.getAnnotation(JoinColumn.class);
            if (manyToOne.optional() != joinColumn.nullable()) {
              collection.add("Conflict in @ManyToOne(optional) and @JoinColumn(nullable) on " + beanDescriptor.getType().getCanonicalName() + "." + propertyDescriptor.getName());
            }
          }
        }
        if (propertyDescriptor.isAnnotationPresent(OneToMany.class)) {
          OneToMany oneToMany = propertyDescriptor.getAnnotation(OneToMany.class);
          CascadeType[] cascades = oneToMany.cascade();
          FetchType fetchType = oneToMany.fetch();
          String mappedBy = oneToMany.mappedBy();

          this.checkCascade(collection, oneToMany, beanDescriptor, propertyDescriptor, cascades);
          this.checkFetch(collection, oneToMany, beanDescriptor, propertyDescriptor, fetchType);
          this.checkMappedBy(collection, oneToMany, beanDescriptor, propertyDescriptor, mappedBy);
        }
        if (propertyDescriptor.isAnnotationPresent(OneToOne.class)) {
          OneToOne oneToOne = propertyDescriptor.getAnnotation(OneToOne.class);
          CascadeType[] cascades = oneToOne.cascade();
          FetchType fetchType = oneToOne.fetch();
          String mappedBy = oneToOne.mappedBy();

          this.checkCascade(collection, oneToOne, beanDescriptor, propertyDescriptor, cascades);
          this.checkFetch(collection, oneToOne, beanDescriptor, propertyDescriptor, fetchType);

          if (ConditionUtils.isEmpty(mappedBy)) {
            if (!propertyDescriptor.isAnnotationPresent(JoinColumn.class)) {
              collection.add("Missing @OneToOne(mappedBy) or @JoinColumn on " + beanDescriptor.getType().getCanonicalName() + "." + propertyDescriptor.getName());
            } else {
              JoinColumn joinColumn = propertyDescriptor.getAnnotation(JoinColumn.class);
              if (oneToOne.optional() != joinColumn.nullable()) {
                collection.add("Conflict in @OneToOne(optional) and @JoinColumn(nullable) on " + beanDescriptor.getType().getCanonicalName() + "." + propertyDescriptor.getName());
              }
            }
          }
        }
View Full Code Here


                  if (manyToOne == null)
                    manyToOne = tarObjFieldGetter.getAnnotation(ManyToOne.class);
                  if (manyToOne == null)
                    continue;
                 
                  JoinColumn joinCol = tarObjField.getAnnotation(JoinColumn.class);
                  if (joinCol == null)
                    joinCol = tarObjFieldGetter.getAnnotation(JoinColumn.class);
                 
                  if (joinCol != null){
                    String referencedColumn = joinCol.referencedColumnName();
                    if (referencedColumn == null || referencedColumn.trim().length() == 0)
                      referencedColumn = idColumn;
                   
                    referencedField = ORMConfigBeanUtil.getField(ownClass, referencedColumn);
                    Method referencedFieldGetter = ru.getGetter(referencedField);
                    if (referencedFieldGetter != null)
                      referencedFieldVal = referencedFieldGetter.invoke(t);
                  }
                 
                  // finished
                  mappedBy = tarObjField.getName();
                 
                  DAOFactory.getDeleteDAO(dsName).deleteByFieldIsValue(tarClass, new String[]{tarObjField.getName()}, new String[]{String.valueOf(referencedFieldVal)});
                  break;
                }
              }
            }

          } else {
            for (int i = 0; i < tarList.size(); i++) {
              Object tarObj = tarList.get(i);
              if (tarObj == null)
                continue;
             
              Object tarObjIdVal = ORMConfigBeanUtil.getIdVal(tarObj);
              if (tarObjIdVal == null)
                continue;
             
              ReflectUtil tarRu = new ReflectUtil(tarObj);

              if (mappedBy != null && mappedBy.trim().length() > 0) {
                Method ownFieldSetter = tarRu.getSetter(mappedBy);
                if (ownFieldSetter == null)
                  continue;

                // finished
                DAOFactory.getDeleteDAO(dsName).deleteById(tarObj);
              } else {
                JoinTable joinTable = null;
                if (f.isAnnotationPresent(JoinTable.class)) {
                  joinTable = f.getAnnotation(JoinTable.class);
                } else if (tarGetter.isAnnotationPresent(JoinTable.class)) {
                  joinTable = tarGetter.getAnnotation(JoinTable.class);
                } else {
                  // find ownclass in tarObj fields
                  for (Field tarObjField : tarRu.getFields()) {
                    if (!tarObjField.getType().getName().equals(ownClass.getName()))
                      continue;
                   
                    Method tarObjFieldGetter = tarRu.getGetter(tarObjField.getName());
                    if (tarObjFieldGetter == null)
                      continue;
                   
                    ManyToOne manyToOne = tarObjField.getAnnotation(ManyToOne.class);
                    if (manyToOne == null)
                      manyToOne = tarObjFieldGetter.getAnnotation(ManyToOne.class);
                    if (manyToOne == null)
                      continue;
                   
                    JoinColumn joinCol = tarObjField.getAnnotation(JoinColumn.class);
                    if (joinCol == null)
                      joinCol = tarObjFieldGetter.getAnnotation(JoinColumn.class);
                   
                    if (joinCol != null){
                      String referencedColumn = joinCol.referencedColumnName();
                      if (referencedColumn == null || referencedColumn.trim().length() == 0)
                        referencedColumn = idColumn;
                     
                      referencedField = ORMConfigBeanUtil.getField(ownClass, referencedColumn);
                      Method referencedFieldGetter = ru.getGetter(referencedField);
View Full Code Here

              if (manyToOne == null)
                manyToOne = tarObjFieldGetter.getAnnotation(ManyToOne.class);
              if (manyToOne == null)
                continue;
             
              JoinColumn joinCol = tarObjField.getAnnotation(JoinColumn.class);
              if (joinCol == null)
                joinCol = tarObjFieldGetter.getAnnotation(JoinColumn.class);
             
              if (joinCol != null){
                String referencedColumn = joinCol.referencedColumnName();
                if (referencedColumn == null || referencedColumn.trim().length() == 0)
                  referencedColumn = idColumn;
               
                String referencedField = ORMConfigBeanUtil.getField(ownClass, referencedColumn);
                Method referencedFieldGetter = ru.getGetter(referencedField);
View Full Code Here

        OneToOne oneAnn = getter.getAnnotation(OneToOne.class);
        if (oneAnn == null)
          oneAnn = f.getAnnotation(OneToOne.class);

        if (oneAnn != null) {
          JoinColumn joinColumn = getter
              .getAnnotation(JoinColumn.class);
          if (joinColumn == null)
            joinColumn = f.getAnnotation(JoinColumn.class);

          if (joinColumn == null) {
            p.setColumn(f.getName() + "_id");
          } else {
            if (joinColumn.name().trim().length() == 0) {
              String refCol = joinColumn.referencedColumnName();
              if (refCol == null || refCol.trim().length() == 0)
                p.setColumn(f.getName() + "_id");
              else
                p.setColumn(f.getName() + "_" + refCol);
            } else
              p.setColumn(joinColumn.name());
          }
          String relProperty = oneAnn.mappedBy();
          if (relProperty == null || relProperty.trim().length() == 0)
            relProperty = ORMConfigBeanUtil.getIdField(f.getType());

          p.setRelProperty(relProperty);
          p.setRelClass(f.getType());
          p.setType(PropType.ONE_ONE);
          p.setSize("20");
        }

        ManyToOne manyOneAnn = getter.getAnnotation(ManyToOne.class);
        if (manyOneAnn == null)
          manyOneAnn = f.getAnnotation(ManyToOne.class);

        if (manyOneAnn != null) {
          ReflectUtil _ru;
          try {
            _ru = new ReflectUtil(f.getType());

            for (Field _f : _ru.getFields()) {
              if (!ClassUtil.isListClass(_f))
                continue;

              String _name = _f.getName();
              Method _getter = ru.getGetter(_name);
              if (getter == null)
                continue;

              OneToMany oneManyAnn = _getter
                  .getAnnotation(OneToMany.class);
              if (oneManyAnn == null)
                oneManyAnn = f.getAnnotation(OneToMany.class);

              if (oneManyAnn == null)
                continue;

              Class<?> _targetClass = ClassUtil
                  .getGenericType(_f);
              if (!clazz.getName().equals(_targetClass.getName()))
                continue;

              String relProperty = oneManyAnn.mappedBy();
              if (relProperty == null
                  || relProperty.trim().length() == 0)
                relProperty = ORMConfigBeanUtil.getIdField(_f
                    .getType());

              p.setRelProperty(relProperty);

              break;
            }
          } catch (Exception e) {
          }

          p.setRelClass(f.getType());
          p.setType(PropType.MANY_ONE);
          p.setSize("20");
          JoinColumn col = getter.getAnnotation(JoinColumn.class);
          if (col == null)
            col = f.getAnnotation(JoinColumn.class);

          if (col == null) {
            p.setColumn(f.getName() + "_id");
          } else {
            if (col.name().trim().length() == 0) {
              String refCol = col.referencedColumnName();
              if (refCol == null || refCol.trim().length() == 0)
                p.setColumn(f.getName() + "_id");
              else
                p.setColumn(f.getName() + "_" + refCol);
            } else
              p.setColumn(col.name());
          }
        }
      }

      result.add(p);
View Full Code Here

       
        if (moAn == null)
          continue;
      }
      String referencedColumn = null;
      JoinColumn joinCol = f.getAnnotation(JoinColumn.class);
      if (joinCol == null)
        joinCol = tarGetter.getAnnotation(JoinColumn.class);
     
      if (joinCol == null)
        fk = f.getName()+"_id";
      else
        fk = joinCol.name();
        referencedColumn = joinCol.referencedColumnName();
      }
     
      Class<?> tarClass = f.getType();
     
      if (referencedColumn == null || referencedColumn.trim().length() == 0)
View Full Code Here

          .getDeclaredProperties( AccessType.FIELD.getType() ) ) {
        if ( prop.isAnnotationPresent( Id.class ) && prop.isAnnotationPresent( Column.class ) ) {
          columnName = prop.getAnnotation( Column.class ).name();
        }

        final JoinColumn joinColumn = property.getAnnotation( JoinColumn.class );
        if ( property.isAnnotationPresent( ManyToOne.class ) && joinColumn != null
            && ! BinderHelper.isEmptyAnnotationValue( joinColumn.name() )
            && joinColumn.name().equals( columnName )
            && !property.isAnnotationPresent( MapsId.class ) ) {
           hasSpecjManyToOne = true;
          for ( Ejb3JoinColumn column : columns ) {
            column.setInsertable( false );
            column.setUpdatable( false );
View Full Code Here

      };
    }
    else {
      joinColumns = new Ejb3JoinColumn[annJoins.length];
      JoinColumn annJoin;
      int length = annJoins.length;
      for ( int index = 0; index < length ; index++ ) {
        annJoin = annJoins[index];
        Ejb3JoinColumn currentJoinColumn = new Ejb3JoinColumn();
        currentJoinColumn.setImplicit( true );
View Full Code Here

      };
    }
    else {
      joinColumns = new Ejb3JoinColumn[annJoins.length];
      JoinColumn annJoin;
      int length = annJoins.length;
      for ( int index = 0; index < length ; index++ ) {
        annJoin = annJoins[index];
        Ejb3JoinColumn currentJoinColumn = new Ejb3JoinColumn();
        currentJoinColumn.setImplicit( true );
View Full Code Here

          .getDeclaredProperties( AccessType.FIELD.getType() ) ) {
        if ( prop.isAnnotationPresent( Id.class ) && prop.isAnnotationPresent( Column.class ) ) {
          columnName = prop.getAnnotation( Column.class ).name();
        }

        final JoinColumn joinColumn = property.getAnnotation( JoinColumn.class );
        if ( property.isAnnotationPresent( ManyToOne.class ) && joinColumn != null
            && ! BinderHelper.isEmptyAnnotationValue( joinColumn.name() )
            && joinColumn.name().equals( columnName )
            && !property.isAnnotationPresent( MapsId.class ) ) {
           hasSpecjManyToOne = true;
          for ( Ejb3JoinColumn column : columns ) {
            column.setInsertable( false );
            column.setUpdatable( false );
View Full Code Here

          .getDeclaredProperties( AccessType.FIELD.getType() ) ) {
        if ( prop.isAnnotationPresent( Id.class ) && prop.isAnnotationPresent( Column.class ) ) {
          columnName = prop.getAnnotation( Column.class ).name();
        }

        final JoinColumn joinColumn = property.getAnnotation( JoinColumn.class );
        if ( property.isAnnotationPresent( ManyToOne.class ) && joinColumn != null
            && ! BinderHelper.isEmptyAnnotationValue( joinColumn.name() )
            && joinColumn.name().equals( columnName )
            && !property.isAnnotationPresent( MapsId.class ) ) {
           hasSpecjManyToOne = true;
          for ( Ejb3JoinColumn column : columns ) {
            column.setInsertable( false );
            column.setUpdatable( false );
View Full Code Here

TOP

Related Classes of javax.persistence.JoinColumn

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.