Package se.unlogic.standardutils.annotations

Examples of se.unlogic.standardutils.annotations.UnsupportedFieldTypeException


      if(annotation != null && (!field.isAnnotationPresent(OneToOne.class) && !field.isAnnotationPresent(OneToMany.class) && !field.isAnnotationPresent(ManyToOne.class) && !field.isAnnotationPresent(ManyToMany.class) )){

        if(Modifier.isFinal(field.getModifiers())){

          throw new UnsupportedFieldTypeException("The annotated field " + field.getName() + " in class " + beanClass + " is final!", field, annotation.getClass(), beanClass);

        }

        Method resultSetColumnNameMethod = ResultSetMethods.getColumnNameMethod(field.getType());

        BeanStringPopulator<?> typePopulator = null;

        if(resultSetColumnNameMethod == null){

          if(populators != null){
            typePopulator = this.getPopulator(populators, field, annotation);
          }
         
          if(typePopulator == null){
           
            typePopulator = BeanStringPopulatorRegistery.getBeanStringPopulator(field.getType());
          }
         
          if(typePopulator == null){
           
            if(field.getType().isEnum()){

              typePopulator = EnumPopulator.getInstanceFromField(field);

            }else if(List.class.isAssignableFrom(field.getType()) && ReflectionUtils.getGenericlyTypeCount(field) == 1 && ((Class<?>)ReflectionUtils.getGenericType(field)).isEnum()){

              typePopulator = EnumPopulator.getInstanceFromListField(field);
           
          }

          if(typePopulator == null){
            throw new UnsupportedFieldTypeException("The annotated field " + field.getName() + " in class " + beanClass + " is of unsupported type " + field.getType(), field, annotation.annotationType() , beanClass);
          }
        }

        ReflectionUtils.fixFieldAccess(field);
View Full Code Here


      if(typePopulator != null){
       
        remoteKeyPopulator = new TypeBasedResultSetPopulator<RemoteKeyType>(typePopulator, columnName);
      }else{

        throw new UnsupportedFieldTypeException("Unable to find resultset method or type populator for field " + remoteKeyField.getName() + " in " + remoteClass + " when creating many to one relation for field " + field.getName() + " in " + beanClass, field, ManyToOne.class, beanClass);
      }
    }
  }
View Full Code Here

          this.checkOrderByAnnotation(field, orderBy);

          if (field.getType() != List.class) {

            throw new UnsupportedFieldTypeException("The annotated field " + field.getName() + " in  " + beanClass + " is of unsupported type "
                + field.getType() + ". Fields annotated as @OneToMany have to be a genericly typed " + List.class, field, OneToMany.class,
                beanClass);
          }

          if (ReflectionUtils.getGenericlyTypeCount(field) != 1) {

            throw new UnsupportedFieldTypeException("The annotated field " + field.getName() + " in  " + beanClass
                + " is genericly typed. Fields annotated as @OneToMany have to be a genericly typed " + List.class, field, OneToMany.class,
                beanClass);
          }

          // This is a bit ugly but still necessary until someone else
          // comes up with something smarter...
          Class<?> remoteClass = (Class<?>) ReflectionUtils.getGenericType(field);

          SimplifiedRelation simplifiedRelation = field.getAnnotation(SimplifiedRelation.class);

          if (simplifiedRelation != null) {

            this.oneToManyRelations.put(field, SimplifiedOneToManyRelation.getGenericInstance(beanClass, remoteClass, field, this, typePopulators, queryParameterPopulators));

          } else {

            // Use this class pks, no extra field
            this.oneToManyRelations.put(field, DefaultOneToManyRelation.getGenericInstance(beanClass, remoteClass, field, daoFactory, daoManaged));
          }

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

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

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

        } 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)) {

          this.checkAutoGeneration(daoManaged);

          this.checkOrderByAnnotation(field, orderBy);

          if (field.getType() != List.class) {

            throw new UnsupportedFieldTypeException("The annotated field " + field.getName() + " in  " + beanClass + " is of unsupported type "
                + field.getType() + ". Fields annotated as @ManyToMany have to be a genericly typed " + List.class, field, ManyToMany.class,
                beanClass);
          }

          if (ReflectionUtils.getGenericlyTypeCount(field) != 1) {

            throw new UnsupportedFieldTypeException("The annotated field " + field.getName() + " in  " + beanClass
                + " is genericly typed. Fields annotated as @ManyToMany have to be a genericly typed " + List.class, field, ManyToMany.class,
                beanClass);
          }

          // This is a bit ugly but still necessary until someone else
View Full Code Here

      if(typePopulator != null){
       
        remoteKeyPopulator = new TypeBasedResultSetPopulator<RemoteKeyType>(typePopulator, columnName);
      }else{

        throw new UnsupportedFieldTypeException("Unable to find resultset method or type populator for field " + remoteKeyField.getName() + " in " + remoteClass + " when creating many to one relation for field " + field.getName() + " in " + beanClass, field, ManyToOne.class, beanClass);
      }
    }
  }
View Full Code Here

          this.checkOrderByAnnotation(field, orderBy);

          if (field.getType() != List.class) {

            throw new UnsupportedFieldTypeException("The annotated field " + field.getName() + " in  " + beanClass + " is of unsupported type "
                + field.getType() + ". Fields annotated as @OneToMany have to be a genericly typed " + List.class, field, OneToMany.class,
                beanClass);
          }

          if (ReflectionUtils.getGenericlyTypeCount(field) != 1) {

            throw new UnsupportedFieldTypeException("The annotated field " + field.getName() + " in  " + beanClass
                + " is genericly typed. Fields annotated as @OneToMany have to be a genericly typed " + List.class, field, OneToMany.class,
                beanClass);
          }

          // This is a bit ugly but still necessary until someone else
          // comes up with something smarter...
          Class<?> remoteClass = (Class<?>) ReflectionUtils.getGenericType(field);

          SimplifiedRelation simplifiedRelation = field.getAnnotation(SimplifiedRelation.class);

          if (simplifiedRelation != null) {

            this.oneToManyRelations.put(field, SimplifiedOneToManyRelation.getGenericInstance(beanClass, remoteClass, field, this, typePopulators, queryParameterPopulators));

          } else {

            // Use this class pks, no extra field
            this.oneToManyRelations.put(field, DefaultOneToManyRelation.getGenericInstance(beanClass, remoteClass, field, daoFactory, daoManaged));
          }

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

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

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

        } 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)) {

          this.checkAutoGeneration(daoManaged);

          this.checkOrderByAnnotation(field, orderBy);

          if (field.getType() != List.class) {

            throw new UnsupportedFieldTypeException("The annotated field " + field.getName() + " in  " + beanClass + " is of unsupported type "
                + field.getType() + ". Fields annotated as @ManyToMany have to be a genericly typed " + List.class, field, ManyToMany.class,
                beanClass);
          }

          if (ReflectionUtils.getGenericlyTypeCount(field) != 1) {

            throw new UnsupportedFieldTypeException("The annotated field " + field.getName() + " in  " + beanClass
                + " is genericly typed. Fields annotated as @ManyToMany have to be a genericly typed " + List.class, field, ManyToMany.class,
                beanClass);
          }

          // This is a bit ugly but still necessary until someone else
View Full Code Here

      if(annotation != null && (!field.isAnnotationPresent(OneToOne.class) && !field.isAnnotationPresent(OneToMany.class) && !field.isAnnotationPresent(ManyToOne.class) && !field.isAnnotationPresent(ManyToMany.class) )){

        if(Modifier.isFinal(field.getModifiers())){

          throw new UnsupportedFieldTypeException("The annotated field " + field.getName() + " in class " + beanClass + " is final!", field, annotation.getClass(), beanClass);

        }

        Method resultSetColumnNameMethod = ResultSetMethods.getColumnNameMethod(field.getType());

        BeanStringPopulator<?> typePopulator = null;

        if(resultSetColumnNameMethod == null){

          if(populators != null){
            typePopulator = this.getPopulator(populators, field, annotation);
          }
         
          if(typePopulator == null){
           
            typePopulator = BeanStringPopulatorRegistery.getBeanStringPopulator(field.getType());
          }
         
          if(typePopulator == null){
           
            if(field.getType().isEnum()){

              typePopulator = EnumPopulator.getInstanceFromField(field);

            }else if(List.class.isAssignableFrom(field.getType()) && ReflectionUtils.getGenericlyTypeCount(field) == 1 && ((Class<?>)ReflectionUtils.getGenericType(field)).isEnum()){

              typePopulator = EnumPopulator.getInstanceFromListField(field);
           
          }

          if(typePopulator == null){
            throw new UnsupportedFieldTypeException("The annotated field " + field.getName() + " in class " + beanClass + " is of unsupported type " + field.getType(), field, annotation.annotationType() , beanClass);
          }
        }

        ReflectionUtils.fixFieldAccess(field);
View Full Code Here

TOP

Related Classes of se.unlogic.standardutils.annotations.UnsupportedFieldTypeException

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.