Package com.jengine.orm.model

Examples of com.jengine.orm.model.ModelClassBase


    public Type getType() {
        return Type.MULTI_REFERENCE;
    }

    public Object getValue(Model obj) throws DBException {
        ModelClassBase referenceCls = getReferenceClass();
        ReferenceField reverseField = (ReferenceField) getReverseField();
        Object key = obj.getData().get(reverseField.getReferenceModelKey().getFieldName());
        return referenceCls.filter(reverseField.eq(key));
    }
View Full Code Here


    public Type getType() {
        return Type.REVERSE_SINGLE_REFERENCE;
    }

    public Object getValue(Model obj) throws DBException {
        ModelClassBase referenceCls = getReferenceClass();
        SingleReferenceField singleField = (SingleReferenceField) getReverseField();
        Object key = obj.getData().get(singleField.getReferenceModelKey().getFieldName());
        return referenceCls.filter(singleField.eq(key)).one();
    }
View Full Code Here

    public Type getType() {
        return Type.MANY_REFERENCE;
    }

    public Object getValue(Model obj) throws DBException {
        ModelClassBase middleCls = getMiddleClass();
        Field middleField = getMiddleField();
        Object keyValue = obj.getData().get(getKeyFieldName());
        return middleCls.filter(middleField.eq(keyValue)).target(middleField);
    }
View Full Code Here

        Object keyValue = obj.getData().get(getKeyFieldName());
        return middleCls.filter(middleField.eq(keyValue)).target(middleField);
    }

    public void createMiddleClass() throws DBException {
        ModelClassBase referenceModelClass = getReferenceClass();
        ModelClassBase middleModelClass = getMiddleClass();
        ManyReferenceField referenceField = getReverseField();
        if (middleModelClass == null) {
            middleModelClass = new DynamicModelClass(getMiddleModelName(), middleBaseClass, map("table", getMiddleModelTableName()));
            middleModelClass.getManager().addField(
                    referenceField.getMiddleModelFieldName(),
                    new ReferenceField(referenceModelClass.getManager().getModel(), map(
                            "referenceModelName", referenceModelClass.getName(),
                            "referenceModelKeyName", referenceField.getKeyFieldName(),
                            "columnName", referenceModelClass.getManager().getTableName().toLowerCase()))
            );
            middleModelClass.getManager().addField(
                    getMiddleModelFieldName(),
                    new ReferenceField(fieldClass, map(
                            "referenceModelName", manager.getName(),
                            "referenceModelKeyName", getKeyFieldName(),
                            "columnName", manager.getTableName().toLowerCase()))
            );
            middleModelClass.getManager().addField("id", new PrimaryKey());
        }
    }
View Full Code Here

        Map values = obj.getData();
        if (!values.containsKey(fieldName) || values.get(fieldName) == null) {
            return;
        }
        List keys = (List) values.get(fieldName);
        ModelClassBase middleModelClass = getMiddleClass();
        Field middleModelField = getMiddleField();
        Field middleModelReferenceField = getReverseField().getMiddleField();
        for (Object key : keys) {
            Model middleObj = middleModelClass.newInstance();
            middleObj.setValue(middleModelField, values.get(getKeyFieldName()));
            middleObj.setValue(middleModelReferenceField, key);
            middleObj.save();
        }
    }
View Full Code Here

            middleObj.save();
        }
    }

    public void remove(Model obj) throws DBException {
        ModelClassBase middleModelClass = getMiddleClass();
        Field middleModelField = getMiddleField();
        middleModelClass.filter(middleModelField.eq(obj.getValue(getKeyFieldName()))).remove();
    }
View Full Code Here

        for (MultiModelItem item : items) {
            if (item.getName().equals(joinItem.getName())) {
                continue;
            }
            ModelClassBase modelClass = item.getModelClass();
            HashMap<String, ReferenceField> referenceModels = modelClass.getManager().getReferenceModels();
            if (referenceModels.containsKey(joinItem.getModelClass().getName())) {
                ReferenceField referenceField = referenceModels.get(joinItem.getModelClass().getName());
                result[0] = joinItem.getMultiModelField(referenceField.getReferenceModelKey()).getName();
                result[1] = item.getMultiModelField(referenceField).getName();
                return result;
View Full Code Here

    public void joinRelatedModels(MultiModelItem item, List<String> path) {
        if (path.size() > 0) {
            String fieldName = path.get(0);
            ReferenceField currentField  = (ReferenceField) item.getModelClass().getManager().getField(fieldName);
            ModelClassBase referenceClass = currentField.getReferenceClass();
            String referenceItemName = item.getName() + "." + fieldName;
            if (!this.items.containsKey(referenceItemName)) {
                this.ljoin(referenceClass, referenceItemName,
                        String.format("%s.%s", referenceItemName, currentField.getReferenceModelKey().getFieldName()),
                        String.format("%s.%s", item.getName(), fieldName));
View Full Code Here

    protected ExpressionNode visit(Tree tree) {
        if (tree.getType() == ExprParser.GROUP) {
            return new Group(visit(tree.getChild(0)));
        } else if (tree.getType() == ExprParser.MODEL_NAME) {
            String modelClassName = tree.getChild(0).getText();
            ModelClassBase modelClass = getDB().getModelClass(modelClassName);
            MultiModelItem item = add(new MultiModelItem(this, modelClass, makeItemName(modelClass)));
            return new MultiModelNode(item);
        } else if (tree.getType() == ExprParser.RIGHT_JOIN) {
            ExpressionNode operand1 = visit(tree.getChild(0));
            ExpressionNode operand2 = visit(tree.getChild(1));
View Full Code Here

            if (field instanceof BaseReference) {
                BaseReference reference = (BaseReference) field;
                String reverseFieldName = reference.getReverseFieldName();
                if (reverseFieldName != null) {
                    Field reverseField = reference.newReverseField();
                    ModelClassBase referenceModelClass = reference.getReferenceClass();
                    if (referenceModelClass != null &&
                            !referenceModelClass.getManager().getFieldMap().containsValue(reverseFieldName)) {
                        referenceModelClass.getManager().addField(reverseFieldName, reverseField);
                    } else {
                        if (!deferredFields.containsKey(reference.getReferenceModelName())) {
                            deferredFields.put(reference.getReferenceModelName(), new LinkedHashMap<String, Field>());
                        }
                        deferredFields.get(reference.getReferenceModelName()).put(reverseFieldName, reverseField);
View Full Code Here

TOP

Related Classes of com.jengine.orm.model.ModelClassBase

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.