All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.glassfish.ha.store.criteria.ExpressionBuilder Maven / Gradle / Ivy

There is a newer version: 4.0.4
Show newest version
/*
 * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v. 2.0, which is available at
 * http://www.eclipse.org/legal/epl-2.0.
 *
 * This Source Code may also be made available under the following Secondary
 * Licenses when the conditions for such availability set forth in the
 * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
 * version 2 with the GNU Classpath Exception, which is available at
 * https://www.gnu.org/software/classpath/license.html.
 *
 * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
 */

package org.glassfish.ha.store.criteria;

import org.glassfish.ha.store.criteria.spi.*;
import org.glassfish.ha.store.spi.AttributeMetadata;

/**
 * A Class to construct portable Criteria objects
 *
 * @author [email protected]
 *
 */
public class ExpressionBuilder {

    Class entryClazz;

    public ExpressionBuilder(Class entryClazz) {
        this.entryClazz = entryClazz;
    }

    public Criteria setCriteria(Expression expr) {
        Criteria c = new Criteria(entryClazz);
        c.setExpression(expr);

        return c;
    }

    public  AttributeAccessNode attr(AttributeMetadata meta) {
        return new AttributeAccessNode(meta);
    }

    public  LiteralNode literal(Class type, T value) {
        return new LiteralNode(type, value);
    }

    public  LogicalExpressionNode eq(T value, AttributeMetadata meta) {
        return new LogicalExpressionNode(Opcode.EQ,
                new LiteralNode(meta.getAttributeType(), value),
                new AttributeAccessNode(meta));
    }

    public  LogicalExpressionNode eq(AttributeMetadata meta, T value) {
        return new LogicalExpressionNode(Opcode.EQ,
                new AttributeAccessNode(meta),
                new LiteralNode(meta.getAttributeType(), value));
    }

    public  LogicalExpressionNode eq(AttributeMetadata meta1,
                                           AttributeMetadata meta2) {
        return new LogicalExpressionNode(Opcode.EQ,
                new AttributeAccessNode(meta1),
                new AttributeAccessNode(meta2));
    }

    public  LogicalExpressionNode eq(ExpressionNode expr1, ExpressionNode expr2) {
        return new LogicalExpressionNode(Opcode.EQ, expr1, expr2);
    }

    public  LogicalExpressionNode eq(LiteralNode value, AttributeMetadata meta) {
        return new LogicalExpressionNode(Opcode.EQ,
                value, new AttributeAccessNode(meta));
    }

    public  LogicalExpressionNode eq(AttributeMetadata meta, LiteralNode value) {
        return new LogicalExpressionNode(Opcode.EQ,
                new AttributeAccessNode(meta), value);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy