Package com.alibaba.druid.mapping

Examples of com.alibaba.druid.mapping.Entity


        if (x.getOperator() == SQLBinaryOperator.Equality) {
            if (x.getLeft() instanceof SQLIdentifierExpr && isSimpleValue(visitor, x.getRight())) {
                visit(visitor, (SQLIdentifierExpr) x.getLeft());
                x.getRight().accept(visitor);

                Entity entity = (Entity) x.getLeft().getAttribute(MAPPING_ENTITY);
                Property property = (Property) x.getLeft().getAttribute(MAPPING_PROPERTY);
                Object value = x.getRight().getAttribute(MAPPING_VALUE);

                PropertyValue propertyValue = new PropertyValue(entity, property, value);
                propertyValue.putAttribute("mapping.expr", x.getRight());
               
                visitor.getPropertyValues().add(propertyValue);

                return false;
            }

            if (x.getLeft() instanceof SQLPropertyExpr && isSimpleValue(visitor, x.getRight())) {
                visit(visitor, (SQLPropertyExpr) x.getLeft());
                x.getRight().accept(visitor);

                Entity entity = (Entity) x.getLeft().getAttribute(MAPPING_ENTITY);
                Property property = (Property) x.getLeft().getAttribute(MAPPING_PROPERTY);
                Object value = x.getRight().getAttribute(MAPPING_VALUE);

                PropertyValue propertyValue = new PropertyValue(entity, property, value);
                propertyValue.putAttribute("mapping.expr", x.getRight());
View Full Code Here


    public static boolean resolve(MappingVisitor visitor, SQLIdentifierExpr x) {
        String propertyName = x.getName();

        for (SQLTableSource tableSource : visitor.getTableSources().values()) {
            Entity entity = (Entity) tableSource.getAttribute(MAPPING_ENTITY);
            if (entity != null) {
                Property property = entity.getProperty(propertyName);
                if (property != null) {
                    String columnName = visitor.resovleColumnName(entity, property);
                    x.setName(columnName);

                    x.putAttribute(MAPPING_ENTITY, entity);
View Full Code Here

    public static boolean resolve(MappingVisitor visitor, SQLPropertyExpr x) {
        if (x.getOwner() instanceof SQLIdentifierExpr) {
            String ownerName = ((SQLIdentifierExpr) x.getOwner()).getName();
            SQLTableSource tableSource = visitor.getTableSources().get(ownerName);
            Entity entity = (Entity) tableSource.getAttribute(MAPPING_ENTITY);

            if (entity != null) {
                Property property = entity.getProperty(x.getName());
                if (property != null) {
                    String columnName = visitor.resovleColumnName(entity, property);
                    x.setName(columnName);
                    x.putAttribute(MAPPING_ENTITY, entity);
                    x.putAttribute(MAPPING_PROPERTY, property);
View Full Code Here

            expr.setParent(selectItem);
        }

        if (x.getFrom() == null) {
            Entity firstEntity = visitor.getEngine().getFirstEntity(visitor.getContext());
            SQLExprTableSource from = new SQLExprTableSource(new SQLIdentifierExpr(firstEntity.getName()));
            from.putAttribute(MAPPING_ENTITY, firstEntity);
            x.setFrom(from);
            x.putAttribute(MAPPING_ENTITY, firstEntity);
        }
View Full Code Here

    public static Entity getEntity(MappingVisitor visitor, String name) {
        SQLTableSource tableSource = visitor.getTableSources().get(name);

        if (tableSource != null) {
            Entity entity = (Entity) tableSource.getAttribute(MAPPING_ENTITY);
            if (entity != null) {
                return entity;
            }

            if (tableSource instanceof SQLExprTableSource) {
                SQLExpr expr = ((SQLExprTableSource) tableSource).getExpr();

                if (expr instanceof SQLIdentifierExpr) {
                    name = ((SQLIdentifierExpr) expr).getName();
                } else {
                    return null;
                }
            } else {
                return null;
            }
        }

        Entity entity = visitor.getEntities().get(name);

        if (entity == null) {
            for (Map.Entry<String, Entity> entry : visitor.getEntities().entrySet()) {
                if (entry.getKey().equalsIgnoreCase(name)) {
                    entity = entry.getValue();
View Full Code Here

        return entity;
    }

    public static void setTableSource(MappingEngine engine, SQLDeleteStatement stmt, MappingContext context) {
        if (stmt.getExprTableSource() == null) {
            Entity entity = engine.getFirstEntity(context);
            stmt.setTableSource(new SQLIdentifierExpr(entity.getName()));
        }
    }
View Full Code Here

        }
    }

    public static void setTableSource(MappingEngine engine, SQLUpdateStatement stmt, MappingContext context) {
        if (stmt.getTableSource() == null) {
            Entity entity = engine.getFirstEntity(context);
            stmt.setTableSource(new SQLIdentifierExpr(entity.getName()));
        }
    }
View Full Code Here

        }
    }

    public static void setTableSource(MappingEngine engine, SQLInsertStatement stmt, MappingContext context) {
        if (stmt.getTableSource() == null) {
            Entity entity = engine.getFirstEntity(context);
            stmt.setTableSource(new SQLIdentifierExpr(entity.getName()));
        }
    }
View Full Code Here

        if (expr instanceof SQLIdentifierExpr) {
            SQLIdentifierExpr tableExpr = (SQLIdentifierExpr) expr;
            String entityName = tableExpr.getName();

            Entity entity = (Entity) x.getAttribute(MAPPING_ENTITY);

            if (entity == null) {
                entity = visitor.getEntity(entityName);
            }
View Full Code Here

        return true;
    }

    public static boolean fillSelectList(MappingVisitor visitor, SQLSelectQueryBlock x) {
        Entity entity = (Entity) x.getAttribute(MAPPING_ENTITY);

        if (entity == null && x.getFrom() != null) {
            entity = (Entity) x.getFrom().getAttribute(MAPPING_ENTITY);
        }

        if (entity == null) {
            return false;
        }

        x.getSelectList().clear();

        for (Property property : entity.getProperties().values()) {
            String columnName = visitor.resovleColumnName(entity, property);
            String alias = null;
            if (visitor.getContext().isGenerateAlias()) {
                alias = '"' + property.getName() + '"';
            }
View Full Code Here

TOP

Related Classes of com.alibaba.druid.mapping.Entity

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.