Package com.et.ar.annotations

Examples of com.et.ar.annotations.HasMany


                }
            }

            for(HasManyField field: orm.hasManyFields){
                String fieldName = field.getName();
                HasMany annotation = field.getAnnotation();
                Object idValue = OrmInfo.getFieldValue(clasz, orm.id, this);
                List<?> values = (List<?>)OrmInfo.getFieldValue(clasz, fieldName, this);
                if (values != null){
                    Class<?> childClass = field.getTargetType();
                    for(Object obj: values){
                        OrmInfo.setFieldValue(childClass, annotation.foreignKey(), obj, idValue);
                        ActiveRecordBase ar = (ActiveRecordBase)obj;
                        if (ar.save() == false){
                            this.getErrors().addAll(ar.getErrors());
                            rollback(clasz);
                            return false;
                        }
                    }
                }
            }
            for(HasOneField field: orm.hasOneFields){
                String fieldName = field.getName();
                HasOne annotation = field.getAnnotation();
                Object idValue = OrmInfo.getFieldValue(clasz, orm.id, this);
                Object obj = OrmInfo.getFieldValue(clasz, fieldName, this);
                if (obj != null){
                    Class<?> childClass = field.getTargetType();
                    OrmInfo.setFieldValue(childClass, annotation.foreignKey(), obj, idValue);
                    ActiveRecordBase ar = (ActiveRecordBase)obj;
                    if (ar.save() == false){
                        this.getErrors().addAll(ar.getErrors());
                        rollback(clasz);
                        return false;
View Full Code Here


                field.setName(f.getName());
                field.setType(f.getType());
                columnFields.add(field);
            }
           
            HasMany hasMany = f.getAnnotation(HasMany.class);
            if (hasMany != null){
                HasManyField field = new HasManyField();
                field.setName(f.getName());
                field.setAnnotation(hasMany);
                ParameterizedType ptype = (ParameterizedType)f.getGenericType();
                Class<?> childClass = (Class<?>)ptype.getActualTypeArguments()[0];
                if (hasMany.foreignKey().equals("")){
                    field.setForeignKey(orm.table+"_id");
                }
                else{
                    field.setForeignKey(hasMany.foreignKey());
                }
                field.setTargetType(childClass);
               
                hasManyFields.add(field);
            }
View Full Code Here

TOP

Related Classes of com.et.ar.annotations.HasMany

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.