Package com.et.ar.orm

Examples of com.et.ar.orm.ColumnField


                orm.idGeneratorType = id.generate();
                orm.idType = f.getType();
            }
            Column column = f.getAnnotation(Column.class);
            if (column != null){
                ColumnField field = new ColumnField();
                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);
            }
            HasOne hasOne = f.getAnnotation(HasOne.class);
            if (hasOne != null){
                HasOneField field = new HasOneField();
                field.setName(f.getName());
                field.setAnnotation(hasOne);
                field.setTargetType(f.getType());
                if (hasOne.foreignKey().equals("")){
                    field.setForeignKey(orm.table+"_id");
                }
                else{
                    field.setForeignKey(hasOne.foreignKey());
                }
               
                hasOneFields.add(field);
            }
            BelongsTo belongsTo = f.getAnnotation(BelongsTo.class);
            if (belongsTo != null){
                BelongsToField field = new BelongsToField();
                field.setName(f.getName());
                field.setAnnotation(belongsTo);
                field.setTargetType(f.getType());
                if (belongsTo.foreignKey().equals("")){
                    OrmInfo targetOrm = OrmInfo.getOrmInfo(f.getType());
                    field.setForeignKey(targetOrm.table+"_id");
                }
                else{
                    field.setForeignKey(belongsTo.foreignKey());
                }
                belongsToFields.add(field);
            }
        }
       
View Full Code Here


                }
            }
           
            Object[] args = new Object[orm.columnFields.length];
            for(int i=0; i<orm.columnFields.length; i++){
                ColumnField field = orm.columnFields[i];
                sql1 += field.getName() + ",";
                sql2 += "?,";
                args[i] = OrmInfo.getFieldValue(c, field.getName(), obj);
            }
            String sql = sql1.substring(0,sql1.length()-1)+") " + sql2.substring(0,sql2.length()-1)+")";
           
            int updated = execute(sql, args);
            //获得自增长值
            if (orm.idGeneratorType != GeneratorType.SEQUENCE){
                if (adapter != null){
                    Object id = executeScalar(adapter.getIdentitySelectString(), null);
                    id = ConvertUtil.castFromObject(id.toString(), orm.idType);
                    OrmInfo.setFieldValue(c, orm.id, obj, id);
                }
                else{
                    String selectMaxSql = "select max(" + orm.id + ") from " + orm.table;
                    Object maxId = executeScalar(selectMaxSql, null);
                    maxId = ConvertUtil.castFromObject(maxId, orm.idType);
                    OrmInfo.setFieldValue(c, orm.id, obj, maxId);
                }
            }
            OrmInfo.setFieldValue(ActiveRecordBase.class, "isnewrecord", obj, false);
            return updated;
        }
        else{
            String sql1 = "insert into " + orm.table + "(";
            String sql2 = "values(";
            List<Object> tmpArgs = new ArrayList<Object>();
            if (orm.id != null){
                sql1 += orm.id + ",";
                sql2 += "?,";
                Object value = OrmInfo.getFieldValue(c, orm.id, obj);
                tmpArgs.add(value);
            }
            for(ColumnField field: orm.columnFields){
                sql1 += field.getName() + ",";
                sql2 += "?,";
                Object value = OrmInfo.getFieldValue(c, field.getName(), obj);
                tmpArgs.add(value);
            }
            String sql = sql1.substring(0,sql1.length()-1)+") " + sql2.substring(0,sql2.length()-1)+")";
            Object[] args = tmpArgs.toArray();
           
View Full Code Here

        OrmInfo orm = OrmInfo.getOrmInfo(clasz);
       
        Object[] args = new Object[orm.columnFields.length+1];
        String sql = "update " + orm.table + " set ";
        for (int i=0; i<orm.columnFields.length; i++){
            ColumnField field = orm.columnFields[i];
            sql += field.getName() + "=?,";
            args[i] = OrmInfo.getFieldValue(clasz, field.getName(), obj);
        }
        sql = sql.substring(0, sql.length()-1) + " where " + orm.id + "=?";
        args[orm.columnFields.length] = OrmInfo.getFieldValue(clasz, orm.id, obj);
       
        int updated = execute(sql, args);
View Full Code Here

TOP

Related Classes of com.et.ar.orm.ColumnField

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.