Package se.unlogic.standardutils.dao.annotations

Examples of se.unlogic.standardutils.dao.annotations.ManyToOne


        } else if (field.isAnnotationPresent(ManyToOne.class)) {

          this.checkAutoGeneration(daoManaged);

          ManyToOne manyToOne = field.getAnnotation(ManyToOne.class);

          List<Field> remoteClassFields = ReflectionUtils.getFields(field.getType());

          Field matchingRemoteField = null;

          if (remoteClassFields != null) {

            for (Field remoteField : remoteClassFields) {

              if (remoteField.isAnnotationPresent(DAOManaged.class) && remoteField.isAnnotationPresent(OneToMany.class)
                  && remoteField.getType() == List.class && ReflectionUtils.isGenericlyTyped(remoteField)
                  && ((Class<?>) ReflectionUtils.getGenericType(remoteField) == this.beanClass)) {

                matchingRemoteField = remoteField;

                break;
              }
            }
          }

          if (matchingRemoteField == null) {

            throw new RuntimeException("No corresponding @OneToMany annotated field found in  " + field.getType()
                + " matching @ManyToOne relation of field " + field.getName() + " in  " + beanClass + "!");
          }

          Field remoteKeyField = null;

          if (!StringUtils.isEmpty(manyToOne.remoteKeyField())) {

            remoteKeyField = ReflectionUtils.getField(field.getType(), manyToOne.remoteKeyField());

            //TODO Check if the remote key field is @DAOPopluate annotated
            if (remoteKeyField == null) {

              throw new RuntimeException("Unable to find @Key annotated field " + manyToOne.remoteKeyField() + " in " + field.getType() + " specified for @ManyToOne annotated field "
                  + field.getName() + " in " + beanClass);
            }

          } else {

            for (Field remoteField : remoteClassFields) {

              if (remoteField.isAnnotationPresent(DAOManaged.class) && remoteField.isAnnotationPresent(Key.class)) {

                if (remoteKeyField != null) {

                  throw new RuntimeException("Found multiple @Key annotated fields in " + field.getType() + ", therefore the remoteKeyField property needs to be specified for the @ManyToOne annotated field "
                      + field.getName() + " in " + beanClass);
                }

                remoteKeyField = remoteField;
              }
            }

            if (remoteKeyField == null) {

              throw new RuntimeException("Unable to find @Key annotated field in " + field.getType() + " while parsing @ManyToOne annotated field "
                  + field.getName() + " in " + beanClass);
            }
          }

          DefaultManyToOneRelation<T, ?, ?> relation = null;

          if (field.isAnnotationPresent(Key.class)) {

            relation = DefaultManyToOneRelation.getGenericInstance(beanClass, field.getType(), remoteKeyField.getType(), field, remoteKeyField, daoManaged, daoFactory);

            manyToOneRelationKeys.put(field, relation);

          } else {

            relation = DefaultManyToOneRelation.getGenericInstance(beanClass, field.getType(), remoteKeyField.getType(), field, remoteKeyField, daoManaged, daoFactory);

            this.manyToOneRelations.put(field, relation);
          }

          this.columnMap.put(field, relation);

          if (orderBy != null) {
            this.columnOrderMap.put(orderBy, relation);
          }

          if (manyToOne.autoAdd()) {
            this.autoAddRelations.add(field);
          }

          if (manyToOne.autoUpdate()) {
            this.autoUpdateRelations.add(field);
          }

          if (manyToOne.autoGet()) {
            this.autoGetRelations.add(field);
          }

        } else if (field.isAnnotationPresent(ManyToMany.class)) {
View Full Code Here


        } else if (field.isAnnotationPresent(ManyToOne.class)) {

          this.checkAutoGeneration(daoManaged);

          ManyToOne manyToOne = field.getAnnotation(ManyToOne.class);

          List<Field> remoteClassFields = ReflectionUtils.getFields(field.getType());

          Field matchingRemoteField = null;

          if (remoteClassFields != null) {

            for (Field remoteField : remoteClassFields) {

              if (remoteField.isAnnotationPresent(DAOManaged.class) && remoteField.isAnnotationPresent(OneToMany.class)
                  && remoteField.getType() == List.class && ReflectionUtils.isGenericlyTyped(remoteField)
                  && ((Class<?>) ReflectionUtils.getGenericType(remoteField) == this.beanClass)) {

                matchingRemoteField = remoteField;

                break;
              }
            }
          }

          if (matchingRemoteField == null) {

            throw new RuntimeException("No corresponding @OneToMany annotated field found in  " + field.getType()
                + " matching @ManyToOne relation of field " + field.getName() + " in  " + beanClass + "!");
          }

          Field remoteKeyField = null;

          if (!StringUtils.isEmpty(manyToOne.remoteKeyField())) {

            remoteKeyField = ReflectionUtils.getField(field.getType(), manyToOne.remoteKeyField());

            //TODO Check if the remote key field is @DAOPopluate annotated
            if (remoteKeyField == null) {

              throw new RuntimeException("Unable to find @Key annotated field " + manyToOne.remoteKeyField() + " in " + field.getType() + " specified for @ManyToOne annotated field "
                  + field.getName() + " in " + beanClass);
            }

          } else {

            for (Field remoteField : remoteClassFields) {

              if (remoteField.isAnnotationPresent(DAOManaged.class) && remoteField.isAnnotationPresent(Key.class)) {

                if (remoteKeyField != null) {

                  throw new RuntimeException("Found multiple @Key annotated fields in " + field.getType() + ", therefore the remoteKeyField property needs to be specified for the @ManyToOne annotated field "
                      + field.getName() + " in " + beanClass);
                }

                remoteKeyField = remoteField;
              }
            }

            if (remoteKeyField == null) {

              throw new RuntimeException("Unable to find @Key annotated field in " + field.getType() + " while parsing @ManyToOne annotated field "
                  + field.getName() + " in " + beanClass);
            }
          }

          DefaultManyToOneRelation<T, ?, ?> relation = null;

          if (field.isAnnotationPresent(Key.class)) {

            relation = DefaultManyToOneRelation.getGenericInstance(beanClass, field.getType(), remoteKeyField.getType(), field, remoteKeyField, daoManaged, daoFactory);

            manyToOneRelationKeys.put(field, relation);

          } else {

            relation = DefaultManyToOneRelation.getGenericInstance(beanClass, field.getType(), remoteKeyField.getType(), field, remoteKeyField, daoManaged, daoFactory);

            this.manyToOneRelations.put(field, relation);
          }

          this.columnMap.put(field, relation);

          if (orderBy != null) {
            this.columnOrderMap.put(orderBy, relation);
          }

          if (manyToOne.autoAdd()) {
            this.autoAddRelations.add(field);
          }

          if (manyToOne.autoUpdate()) {
            this.autoUpdateRelations.add(field);
          }

          if (manyToOne.autoGet()) {
            this.autoGetRelations.add(field);
          }

        } else if (field.isAnnotationPresent(ManyToMany.class)) {
View Full Code Here

TOP

Related Classes of se.unlogic.standardutils.dao.annotations.ManyToOne

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.