⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 queryimpl.java

📁 这个是perst-269.zip下面的SOURCECODE,和大家分享了。
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    Class getType() { 
        return Object.class;
    }

    String getFieldName() { 
        if (base != null) { 
            if (base.tag != opCurrent) { 
                String baseName = base.getFieldName();
                return (baseName != null) ? baseName + "." + fieldName : null;
            } else { 
                return fieldName;
            }
        } else { 
            return containsFieldName != null ? containsFieldName + "." + fieldName : fieldName;
        }
    }

    LoadAnyNode(Node base, String name, String containsFieldName) { 
        super(tpAny, opLoadAny);
        fieldName = name;
        this.containsFieldName = containsFieldName;
        this.base = base;
    }

    public String toString() { 
        return "LoadAnyNode: fieldName='" + fieldName + "', containsFieldName='" 
            + containsFieldName + "', base=(" + base + "), f=" + f + ", m=" + m;
    }
    

    Object evaluateObj(FilterIterator t) { 
        Object obj;
        Class  cls;
        Field f = this.f;
        Method m  = this.m;                    
        try { 
            if (base == null) { 
                if (t.containsElem != null) { 
                    obj = t.containsElem;
                    cls = obj.getClass();
                    if (f != null && f.getDeclaringClass().equals(cls)) { 
                        return t.query.resolve(f.get(obj));
                    }
                    if (m != null && m.getDeclaringClass().equals(cls)) { 
                        return t.query.resolve(m.invoke(obj, null));
                    }
                    if ((f = ClassDescriptor.locateField(cls, fieldName)) != null) { 
                        this.f = f;
                        return t.query.resolve(f.get(obj));
                    }
                    if ((m = QueryImpl.lookupMethod(cls, fieldName, QueryImpl.defaultProfile)) != null) {
                        this.m = m;
                        return t.query.resolve(m.invoke(obj, null));
                    }
                }
                obj = t.currObj;
            } else { 
                obj = base.evaluateObj(t);
                if (obj == null) { 
                    throw new JSQLNullPointerException(null, fieldName);
                }
            }
            cls = obj.getClass();
            if (f != null && f.getDeclaringClass().equals(cls)) { 
                return t.query.resolve(f.get(obj));
            }
            if (m != null && m.getDeclaringClass().equals(cls)) { 
                return t.query.resolve(m.invoke(obj, null));
            }
            if ((f = ClassDescriptor.locateField(cls, fieldName)) != null) { 
                this.f = f;
                return t.query.resolve(f.get(obj));
            }
            if ((m = QueryImpl.lookupMethod(cls, fieldName, QueryImpl.defaultProfile)) != null) {
                this.m = m;
                return t.query.resolve(m.invoke(obj, null));
            }
        } catch(IllegalAccessException x) { 
            x.printStackTrace();
            throw new IllegalAccessError();
        } catch (InvocationTargetException x) {
            x.printStackTrace();
            throw new IllegalAccessError();            
        }

        throw new JSQLNoSuchFieldException(cls, fieldName);
    }
}
    
class ResolveNode extends Node { 
    Resolver resolver;
    Class    resolvedClass;
    Node     expr;

    public boolean equals(Object o) { 
        return o instanceof ResolveNode 
            && ((ResolveNode)o).expr.equals(expr) 
            && ((ResolveNode)o).resolver.equals(resolver)
            && ((ResolveNode)o).resolvedClass.equals(resolvedClass);
    }

    Class getType() { 
        return resolvedClass;
    }

    Object evaluateObj(FilterIterator t) { 
        return resolver.resolve(expr.evaluateObj(t));
    }
    
    String getFieldName() { 
        if (expr != null) { 
            return expr.getFieldName(); 
        } else { 
            return null; 
        } 
    }

    ResolveNode(Node expr, Resolver resolver, Class resolvedClass) { 
        super(tpObj, opResolve);
        this.expr = expr;
        this.resolver = resolver;
        this.resolvedClass = resolvedClass;
    }
}

class LoadNode extends Node {
    Field field;
    Node  base;

    public boolean equals(Object o) { 
        return o instanceof LoadNode 
            && super.equals(o)
            && ((LoadNode)o).field.equals(field) 
            && equalObjects(((LoadNode)o).base, base);
    }

    Class getType() { 
        return field.getType();
    }

    String getFieldName() { 
        if (base != null && base.tag != opCurrent) { 
            String baseName = base.getFieldName();
            return (baseName != null) ? baseName + "." + field.getName() : null;
        } else { 
            return field.getName();
        }
    }

    final Object getBase(FilterIterator t) { 
        if (base == null) {
            return t.currObj;
        }        
        Object obj = base.evaluateObj(t);
        if (obj == null) {
            throw new JSQLNullPointerException(base.getType(), field.getName());
        }
        return obj;
    }

    long evaluateInt(FilterIterator t) {
        try { 
            return field.getLong(getBase(t));
        } catch (IllegalAccessException x) { 
            throw new IllegalAccessError();
        }
    }
    
    double evaluateReal(FilterIterator t) { 
        try { 
            return field.getDouble(getBase(t));
        } catch (IllegalAccessException x) { 
            throw new IllegalAccessError();
        }
    }
    
    boolean evaluateBool(FilterIterator t) { 
        try { 
            return field.getBoolean(getBase(t));
        } catch (IllegalAccessException x) { 
            throw new IllegalAccessError();
        }
    }
        
    String evaluateStr(FilterIterator t) { 
        try {
            return (String)field.get(getBase(t));
        } catch (IllegalAccessException x) { 
            throw new IllegalAccessError();
        }
    }
        
    Object evaluateObj(FilterIterator t) { 
        try {
            return field.get(getBase(t));
        } catch (IllegalAccessException x) { 
            throw new IllegalAccessError();
        }
    }
    
    LoadNode(Node base, Field f) { 
        super(getFieldType(f.getType()), opLoad);
        field = f;
        this.base = base;
    }
}


class AggregateFunctionNode extends Node { 
    public boolean equals(Object o) { 
        return o instanceof AggregateFunctionNode
            && super.equals(o)
            && equalObjects(((AggregateFunctionNode)o).argument, argument)
            && ((AggregateFunctionNode)o).index == index;
    }

    long    evaluateInt(FilterIterator t) {
        return t.intAggragateFuncValue[index];
    }

    double  evaluateReal(FilterIterator t) {
        return t.realAggragateFuncValue[index];
    }

    AggregateFunctionNode(int type, int tag, Node arg) {
        super(type, tag);
        argument = arg;
    }

    int     index;
    Node    argument;
}

class InvokeElementNode extends InvokeNode { 
    String containsArrayName;

    InvokeElementNode(Method mth, Node arguments[], String arrayName) { 
        super(null, mth, arguments);
        containsArrayName = arrayName;
    }

    public boolean equals(Object o) { 
        return o instanceof InvokeElementNode && super.equals(o);
    }

    Object getTarget(FilterIterator t) { 
        return t.containsElem;
    }

    String getFieldName() { 
        if (containsArrayName != null) { 
            return containsArrayName + "." + mth.getName();
        } else { 
            return null;
        }
    }
}

class ElementNode extends Node { 
    String arrayName;
    Field  field;
    Class  type;

    public boolean equals(Object o) { 
        return o instanceof ElementNode 
            && equalObjects(((ElementNode)o).arrayName, arrayName)
            && equalObjects(((ElementNode)o).field, field)
            && equalObjects(((ElementNode)o).type, type);
    }

    ElementNode(String array, Field f) { 
        super(getFieldType(f.getType()), opElement);
        arrayName = array;
        type = f.getType();
        field = f;
    }

    String getFieldName() { 
        return arrayName != null ? arrayName + "." + field.getName() : null;
    }
    
    boolean evaluateBool(FilterIterator t) { 
        try { 
            return field.getBoolean(t.containsElem);
        } catch (IllegalAccessException x) { 
            throw new IllegalAccessError();
        }
    }
    long    evaluateInt(FilterIterator t) {
        try { 
            return field.getLong(t.containsElem);
        } catch (IllegalAccessException x) { 
            throw new IllegalAccessError();
        }
    }
    double  evaluateReal(FilterIterator t) {
        try { 
            return field.getDouble(t.containsElem);
        } catch (IllegalAccessException x) { 
            throw new IllegalAccessError();
        }
    }
    String  evaluateStr(FilterIterator t) {
        try { 
            return (String)field.get(t.containsElem);
        } catch (IllegalAccessException x) { 
            throw new IllegalAccessError();
        }
    }
    Object  evaluateObj(FilterIterator t) {
        try { 
            return field.get(t.containsElem);
        } catch (IllegalAccessException x) { 
            throw new IllegalAccessError();
        }
    }
    Class   getType() { 
        return type;
    }

}

class ContainsNode extends Node implements Comparator { 
    Node      containsExpr;
    Field     groupByField;
    Method    groupByMethod;
    String    groupByFieldName;
    Class     containsFieldClass;
    int       groupByType;
    Node      havingExpr;
    Node      withExpr;
    Resolver  resolver;
    ArrayList aggregateFunctions;

    public boolean equals(Object o) { 
        if (!(o instanceof ContainsNode)) { 
            return false;
        }
        ContainsNode node = (ContainsNode)o;
        return node.containsExpr.equals(containsExpr)
            && equalObjects(node.groupByField, groupByField)
            && equalObjects(node.groupByMethod, groupByMethod)
            && equalObjects(node.groupByFieldName, groupByFieldName)
            && equalObjects(node.containsFieldClass, containsFieldClass)
            && node.groupByType == groupByType
            && equalObjects(node.havingExpr, havingExpr)
            && equalObjects(node.withExpr, withExpr)
            && equalObjects(node.aggregateFunctions, aggregateFunctions);
    }

    public int compare(Object o1, Object o2) {
        if (o1 == o2) { 
            return 0;
        }
        try {
            if (groupByMethod != null) { 
                return ((Comparable)groupByMethod.invoke(o1, null)).compareTo(groupByMethod.invoke(o2, null));
            } 
            switch (groupByType) { 
              case tpInt:
                {
                    long v1 = groupByField.getLong(o1);
                    long v2 = groupByField.getLong(o2);
                    return v1 < v2 ? -1 : v1 == v2 ? 0 : 1;
                }
              case tpReal:
                {
                    double v1 = groupByField.getDouble(o1);
                    double v2 = groupByField.getDouble(o2);
                    return v1 < v2 ? -1 : v1 == v2 ? 0 : 1;
                }
              case tpBool:
                {
                    boolean v1 = groupByField.getBoolean(o1);
                    boolean v2 = groupByField.getBoolean(o2);
                    return v1 ? (v2 ? 0 : 1) : (v2 ? -1 : 0);
                }
              default:
                return ((Comparable)groupByField.get(o1)).compareTo(groupByField.get(o2));
            }
        } catch (InvocationTargetException x) {
            x.printStackTrace();
            throw new IllegalAccessError();            
        } catch(IllegalAccessException x) { 
            x.printStackTrace();
            throw new IllegalAccessError();
        }
    }


    boolean evaluateBool(FilterIterator t) { 
        int i, j, k, l, n = 0, len = 0;
        Object   collection;
        collection = containsExpr.evaluateObj(t);
        if (collection == null) {
            return false;
        }
        Object[] sortedArray = null;        
        if (havingExpr != null) { 
            n = (collection instanceof Collection) 
                ? ((Collection)collection).size() 
                : (collection instanceof ITable) 
                   ? ((ITable)collection).size() 
                   : ((Object[])collection).length;
            if (t.containsArray == null || t.containsArray.l

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -