Package com.alibaba.druid.hdriver.impl.mapping

Examples of com.alibaba.druid.hdriver.impl.mapping.HMapping


    }

    @Override
    public HScannerResultSetImpl executeQuery(HPreparedStatementImpl statement) throws SQLException {
        try {
            HMapping mapping = this.getMapping();
            if (mapping == null) {
                mapping = new HMappingDefaultImpl();
            }

            HBaseConnectionImpl connection = statement.getConnection();
View Full Code Here


            this.statement = null;
        }
    }

    private Filter setFilter(SQLBinaryOpExpr condition, Filter filter, boolean and) throws IOException, SQLException {
        HMapping mapping = this.getMapping();

        if (condition.getOperator() == SQLBinaryOperator.BooleanAnd) {
            filter = setFilter((SQLBinaryOpExpr) condition.getLeft(), filter, true);
            filter = setFilter((SQLBinaryOpExpr) condition.getRight(), filter, true);
            return filter;
        } else if (condition.getOperator() == SQLBinaryOperator.BooleanOr) {
            filter = setFilter((SQLBinaryOpExpr) condition.getLeft(), filter, false);
            filter = setFilter((SQLBinaryOpExpr) condition.getRight(), filter, false);
            return filter;
        }
       
        String fieldName = ((SQLIdentifierExpr) condition.getLeft()).getName();
        Object value = SQLEvalVisitorUtils.eval(dbType, condition.getRight(), statement.getParameters());

        byte[] bytes = mapping.toBytes(fieldName, value);
        if (mapping.isRow(fieldName)) {
            if (filter == null && condition.getOperator() == SQLBinaryOperator.GreaterThanOrEqual) {
                scan.setStartRow(bytes);
                return null;
            } else if (filter == null && condition.getOperator() == SQLBinaryOperator.LessThan) {
                scan.setStopRow(bytes);
                return null;
            } else {
                CompareOp compareOp = toCompareOp(condition.getOperator());
                RowFilter rowFilter = new RowFilter(compareOp, new BinaryComparator(bytes));

                return setFilter(filter, rowFilter, and);
            }
        } else {
            byte[] qualifier = mapping.getQualifier(fieldName);
            byte[] family = mapping.getFamily(fieldName);

            CompareOp compareOp = toCompareOp(condition.getOperator());

            SingleColumnValueFilter columnFilter = new SingleColumnValueFilter(family, qualifier, compareOp, bytes);
            return setFilter(filter, columnFilter, and);
View Full Code Here

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public HMapping getMapping() {
        HMapping mapping = this.mapping;
        if (mapping == null) {
            mapping = new HMappingDefaultImpl();
        }
        return mapping;
    }
View Full Code Here

    private Map<String, SQLExpr> columns = new LinkedHashMap<String, SQLExpr>();

    @Override
    public boolean execute(HPreparedStatementImpl statement) throws SQLException {
        try {
            HMapping mapping = this.getMapping();
            if (mapping == null) {
                mapping = new HMappingDefaultImpl();
            }
           
            HBaseConnectionImpl connection = statement.getConnection();
            String dbType = connection.getConnectProperties().getProperty("dbType");

            Put put = null;
            for (Map.Entry<String, SQLExpr> entry : columns.entrySet()) {
                String column = entry.getKey();
                SQLExpr valueExpr = entry.getValue();

                Object value = SQLEvalVisitorUtils.eval(dbType, valueExpr, statement.getParameters());

                if (value == null) {
                    continue;
                }
               
                byte[] bytes = mapping.toBytes(column, value);

                if (mapping.isRow(column)) {
                    put = new Put(bytes);
                } else {
                    byte[] family = mapping.getFamily(column);
                    byte[] qualifier = mapping.getQualifier(column);
                    put.add(family, qualifier, bytes);
                }
            }

            HTableInterface htable = connection.getHTable(getTableName());
View Full Code Here

TOP

Related Classes of com.alibaba.druid.hdriver.impl.mapping.HMapping

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.