Package org.ofbiz.sql

Examples of org.ofbiz.sql.FieldValue


                    new FieldAll("a", Collections.<String>emptySet()),
                    new FieldAll("b", set("partyId")),
                    new FieldAll("c", set("partyId"))
                ),
                GenericTestCaseBase.<String, FieldDef>map(
                    "roleTypeId", new FieldDef(new FieldValue("d", "roleTypeId"), null),
                    "roleDescription", new FieldDef(new FieldValue("d", "description"), "roleDescription"),
                    "SUM"new FieldDef(new AggregateFunction("SUM", false, new FieldValue("a", "partyId")), null),
                    "baz"new FieldDef(new FunctionCall("FOO", GenericTestCaseBase.<Value>list(new FieldValue("a", "partyId"), new NumberValue<Integer>(Integer.valueOf(1)))), "baz"),
                    "one"new FieldDef(new MathValue("||", list(new FieldValue("a", "partyId"), new StringValue("-"), new FieldValue("a", "partyTypeId"))), "one"),
                    "cnt1", new FieldDef(new AggregateFunction("COUNT", false, new FieldValue("a", "partyId")), "cnt1"),
                    "cnt2", new FieldDef(new AggregateFunction("COUNT", false, new FieldValue(null, "partyId")), "cnt2"),
                    "cnt3", new FieldDef(new AggregateFunction("COUNT", true, new FieldValue("a", "partyId")), "cnt3")
                ),
                new Table(
                    new TableName("Party", "a"),
                    new Joined(true, new TableName("Person", "b"), list(new KeyMap("partyId", "partyId")),
                        new Joined(true, new TableName("PartyGroup", "c"), list(new KeyMap("partyId", "partyId")),
                            new Joined(false, new TableName("PartyRole", "d"), list(new KeyMap("partyId", "partyId"), new KeyMap("partyId", "partyId")))
                        )
                    )
                ),
                GenericTestCaseBase.<String, Relation>map(
                    "MainAPerson", new Relation("one", "MainA", "Person", list(new KeyMap("partyId", "partyId"))),
                    "MainBPerson", new Relation(null, "MainB", "Person", list(new KeyMap("partyId", "partyId"))),
                    "Person", new Relation("one", null, "Person", list(new KeyMap("partyId", "partyId"))),
                    "PartyGroup", new Relation(null, null, "PartyGroup", list(new KeyMap("partyId", "partyId")))
                ),
                new ConditionList(
                    Joiner.OR,
                    GenericTestCaseBase.<Condition>list(
                        new ConditionList(
                            Joiner.AND,
                            list(
                                new BooleanCondition(new FieldValue("a", "partyTypeId"), "=", new StringValue("PERSON")),
                                new BooleanCondition(new FieldValue("b", "lastName"), "LIKE", new ParameterValue("lastName")),
                                new BetweenCondition(new FieldValue("b", "birthDate"), new StringValue("1974-12-01"), new StringValue("1974-12-31"))
                            )
                        ),
                        new ConditionList(
                            Joiner.AND,
                            list(
                                new ListCondition(new FieldValue("b", "partyId"), "IN", GenericTestCaseBase.<Value>list(
                                    new StringValue("1"),
                                    new StringValue("2"),
                                    new StringValue("3"),
                                    new StringValue("4")
                                )),
                                new BooleanCondition(new FieldValue("b", "gender"), "=", new StringValue("M"))
                            )
                        )
                    )
                ),
                new BooleanCondition(new FieldValue("b", "firstName"), "LIKE", new StringValue("%foo%")),
                null,
                list(
                    new OrderByItem(OrderByItem.Order.DEFAULT, OrderByItem.Nulls.DEFAULT, new FunctionCall("LOWER", GenericTestCaseBase.<Value>list(new FieldValue(null, "lastName")))),
                    new OrderByItem(OrderByItem.Order.DEFAULT, OrderByItem.Nulls.DEFAULT, new FieldValue(null, "firstName")),
                    new OrderByItem(OrderByItem.Order.DESCENDING, OrderByItem.Nulls.DEFAULT, new FieldValue(null, "birthDate"))
                ),
                5,
                10
            );
            SQLStatement<?> stmt = stmtIt.next();
            assertEquals("firstSelect", select, stmt);
            assertEquals("firstSelect:parse", parser(select).SelectStatement(), parser(stmt).SelectStatement());
        }
        {
            SQLInsert insert = new SQLInsert(
                new TableName("Party", null),
                new InsertValues(
                    list(
                        new InsertRow(GenericTestCaseBase.<Value>list(new StringValue("a"), new StringValue("PERSON"), new StringValue("PARTY_DISABLED"))),
                        new InsertRow(list(new NumberValue<Integer>(Integer.valueOf(5)), new StringValue("PARTY_GROUP"), new ParameterValue("name")))
                    )
                ),
                list("partyId", "partyTypeId", "statusId")
            );
            SQLStatement<?> stmt = stmtIt.next();
            assertEquals("firstInsert", insert, stmt);
            assertEquals("firstInsert:parse", parser(insert).InsertStatement(), parser(stmt).InsertStatement());
        }
        {
            SQLInsert insert = new SQLInsert(
                new TableName("Person", null),
                new SQLSelect(
                    false,
                    null,
                    GenericTestCaseBase.<String, FieldDef>map(
                        "partyId", new FieldDef(new FieldValue(null, "partyId"), null),
                        "firstName"new FieldDef(new MathValue("||", list(new FieldValue(null, "partyId"), new StringValue("-auto"))), "firstName")
                    ),
                    new Table(new TableName("Party", null), null),
                    null,
                    new ListCondition(new FieldValue(null, "partyId"), "IN", GenericTestCaseBase.<Value>list(new StringValue("a"), new StringValue("b"))),
                    null,
                    null,
                    null,
                    -1,
                    -1
                ),
                list("partyId", "firstName")
            );
            SQLStatement<?> stmt = stmtIt.next();
            assertEquals("secondInsert", insert, stmt);
            assertEquals("secondInsert:parse", parser(insert).InsertStatement(), parser(stmt).InsertStatement());
        }
        {
            SQLUpdate update = new SQLUpdate(
                new Table(new TableName("Person", null), null),
                list(
                    new SetField("lastName", new MathValue("||", list(new StringValue("auto-"), new FieldValue(null, "partyId"))))
                ),
                new ListCondition(new FieldValue(null, "partyId"), "IN", GenericTestCaseBase.<Value>list(new StringValue("a"), new StringValue("b")))
            );
            SQLStatement<?> stmt = stmtIt.next();
            assertEquals("firstUpdate", update, stmt);
            assertEquals("firstUpdate:parse", parser(update).UpdateStatement(), parser(stmt).UpdateStatement());
        }
        {
            SQLUpdate update = new SQLUpdate(
                new Table(new TableName("Person", null), null),
                list(
                    new SetField("lastName", new MathValue("||", list(new StringValue("auto-"), new FieldValue(null, "partyId")))),
                    new SetField("height", new NumberValue<Integer>(Integer.valueOf(5))),
                    new SetField("width", new NumberValue<Integer>(Integer.valueOf(7)))
                ),
                new ListCondition(new FieldValue(null, "partyId"), "IN", GenericTestCaseBase.<Value>list(new StringValue("a"), new StringValue("b")))
            );
            SQLStatement<?> stmt = stmtIt.next();
            assertEquals("secondUpdate", update, stmt);
            assertEquals("secondUpdate:parse", parser(update).UpdateStatement(), parser(stmt).UpdateStatement());
        }
        {
            SQLUpdate update = new SQLUpdate(
                new Table(new TableName("Person", null), null),
                list(
                    new SetField("lastName", new MathValue("||", list(new StringValue("auto-"), new FieldValue(null, "partyId")))),
                    new SetField("height", new NumberValue<Integer>(Integer.valueOf(6))),
                    new SetField("width", new NumberValue<Integer>(Integer.valueOf(5))),
                    new SetField("nickname", new StringValue("a"))
                ),
                new ListCondition(new FieldValue(null, "partyId"), "IN", GenericTestCaseBase.<Value>list(new StringValue("a"), new StringValue("b")))
            );
            SQLStatement<?> stmt = stmtIt.next();
            assertEquals("thirdUpdate", update, stmt);
            assertEquals("thirdUpdate:parse", parser(update).UpdateStatement(), parser(stmt).UpdateStatement());
        }
        {
            SQLDelete delete = new SQLDelete(
                new Table(new TableName("Person", null), null),
                new ListCondition(new FieldValue(null, "partyId"), "IN", GenericTestCaseBase.<Value>list(new StringValue("a"), new StringValue("b")))
            );
            SQLStatement<?> stmt = stmtIt.next();
            assertEquals("firstDelete", delete, stmt);
            assertEquals("firstDelete:parse", parser(delete).DeleteStatement(), parser(stmt).DeleteStatement());
        }
        {
            SQLDelete delete = new SQLDelete(
                new Table(new TableName("Party", null), null),
                new ListCondition(new FieldValue(null, "partyId"), "IN", GenericTestCaseBase.<Value>list(new StringValue("a"), new StringValue("b")))
            );
            SQLStatement<?> stmt = stmtIt.next();
            assertEquals("secondDelete", delete, stmt);
            assertEquals("secondDelete:parse", parser(delete).DeleteStatement(), parser(stmt).DeleteStatement());
        }
        {
            SQLView view = new SQLView(
                "viewOne",
                new SQLSelect(
                    false,
                    list(new FieldAll("a", Collections.<String>emptySet())),
                    null,
                    new Table(new TableName("Party", "a"), null),
                    null,
                    null,
                    null,
                    null,
                    null,
                    -1,
                    -1
                )
            );
            SQLStatement<?> stmt = stmtIt.next();
            assertEquals("firstView", view, stmt);
            assertEquals("firstView:parse", parser(view).ViewStatement(), parser(stmt).ViewStatement());
        }
        {
            SQLIndex index = new SQLIndex(
                false,
                "testIndex",
                "Party",
                "btree",
                GenericTestCaseBase.<ConstantValue>list(
                    new FieldValue(null, "partyId")
                )
            );
            SQLStatement<?> stmt = stmtIt.next();
            assertEquals("firstIndex", index, stmt);
        }
View Full Code Here


        addFieldDef(dve, groupBy, alias, buildComplexMember(value));
    }

    private static ComplexAliasMember buildComplexMember(Value value) {
        if (value instanceof FieldValue) {
            FieldValue fv = (FieldValue) value;
            return new ComplexAliasField(fv.getTableName(), fv.getFieldName(), null, null);
        } else if (value instanceof FunctionCall) {
            FunctionCall fc = (FunctionCall) value;
            String name = fc.getName().toLowerCase();
            if (fc.getArgCount() == 1) {
                Value firstValue = fc.iterator().next();
                if (firstValue instanceof FieldValue) {
                    FieldValue fv = (FieldValue) firstValue;
                    return new ComplexAliasField(fv.getTableName(), fv.getFieldName(), null, name);
                } else if (firstValue instanceof FunctionCall) {
                    FunctionCall fc2 = (FunctionCall) firstValue;
                    if (fc2.getName().equalsIgnoreCase("coalesce") && fc2.getArgCount() == 2) {
                        Iterator<Value> it = fc2.iterator();
                        Value f1 = it.next(), f2 = it.next();
                        if (f1 instanceof FieldValue) {
                            FieldValue fv = (FieldValue) f1;
                            if (f2 instanceof NumberValue<?>) {
                                return new ComplexAliasField(fv.getTableName(), fv.getFieldName(), ((NumberValue<?>) f2).getNumber().toString(), name);
                            } else if (f2 instanceof StringValue) {
                                return new ComplexAliasField(fv.getTableName(), fv.getFieldName(), "'" + ((StringValue) f2).getString() + "'", name);
                           }
                        }
                    }
                }
            } else if (fc.getName().equalsIgnoreCase("coalesce") && fc.getArgCount() == 2) {
                Iterator<Value> it = fc.iterator();
                Value f1 = it.next(), f2 = it.next();
                if (f1 instanceof FieldValue) {
                    FieldValue fv = (FieldValue) f1;
                    if (f2 instanceof NumberValue<?>) {
                        return new ComplexAliasField(fv.getTableName(), fv.getFieldName(), ((NumberValue<?>) f2).getNumber().toString(), null);
                    } else if (f2 instanceof StringValue) {
                        return new ComplexAliasField(fv.getTableName(), fv.getFieldName(), "'" + ((StringValue) f2).getString() + "'", null);
                   }
                }
            }
        } else if (value instanceof MathValue) {
            MathValue mv = (MathValue) value;
View Full Code Here

        }
    }

    private static EntityFieldValue buildFieldValue(Value value) {
        if (value instanceof FieldValue) {
            FieldValue fv = (FieldValue) value;
            return EntityFieldValue.makeFieldValue(fv.getFieldName(), fv.getTableName(), null, null);
        }
        throw new UnsupportedOperationException(value.toString());
    }
View Full Code Here

        if (value instanceof NumberValue<?>) {
            return ((NumberValue<?>) value).getNumber();
        } else if (value instanceof StringValue) {
            return ((StringValue) value).getString();
        } else if (value instanceof FieldValue) {
            FieldValue fv = (FieldValue) value;
            return EntityFieldValue.makeFieldValue(fv.getFieldName(), fv.getTableName(), null, null);
        } else if (value instanceof List<?>) {
            List<Object> values = FastList.newInstance();
            for (Object sqlValue: (List<?>) value) {
                values.add(buildValue(sqlValue, params));
            }
View Full Code Here

        addFieldDef(dve, groupBy, alias, buildComplexMember(value));
    }

    private static ComplexAliasMember buildComplexMember(Value value) {
        if (value instanceof FieldValue) {
            FieldValue fv = (FieldValue) value;
            return new ComplexAliasField(fv.getTableName(), fv.getFieldName(), null, null);
        } else if (value instanceof FunctionCall) {
            FunctionCall fc = (FunctionCall) value;
            String name = fc.getName().toLowerCase();
            if (fc.getArgCount() == 1) {
                Value firstValue = fc.iterator().next();
                if (firstValue instanceof FieldValue) {
                    FieldValue fv = (FieldValue) firstValue;
                    return new ComplexAliasField(fv.getTableName(), fv.getFieldName(), null, name);
                } else if (firstValue instanceof FunctionCall) {
                    FunctionCall fc2 = (FunctionCall) firstValue;
                    if (fc2.getName().equalsIgnoreCase("coalesce") && fc2.getArgCount() == 2) {
                        Iterator<Value> it = fc2.iterator();
                        Value f1 = it.next(), f2 = it.next();
                        if (f1 instanceof FieldValue) {
                            FieldValue fv = (FieldValue) f1;
                            if (f2 instanceof NumberValue<?>) {
                                return new ComplexAliasField(fv.getTableName(), fv.getFieldName(), ((NumberValue<?>) f2).getNumber().toString(), name);
                            } else if (f2 instanceof StringValue) {
                                return new ComplexAliasField(fv.getTableName(), fv.getFieldName(), "'" + ((StringValue) f2).getString() + "'", name);
                           }
                        }
                    }
                }
            } else if (fc.getName().equalsIgnoreCase("coalesce") && fc.getArgCount() == 2) {
                Iterator<Value> it = fc.iterator();
                Value f1 = it.next(), f2 = it.next();
                if (f1 instanceof FieldValue) {
                    FieldValue fv = (FieldValue) f1;
                    if (f2 instanceof NumberValue<?>) {
                        return new ComplexAliasField(fv.getTableName(), fv.getFieldName(), ((NumberValue<?>) f2).getNumber().toString(), null);
                    } else if (f2 instanceof StringValue) {
                        return new ComplexAliasField(fv.getTableName(), fv.getFieldName(), "'" + ((StringValue) f2).getString() + "'", null);
                   }
                }
            }
        } else if (value instanceof MathValue) {
            MathValue mv = (MathValue) value;
View Full Code Here

        addFieldDef(dve, groupBy, alias, buildComplexMember(value));
    }

    private static ComplexAliasMember buildComplexMember(Value value) {
        if (value instanceof FieldValue) {
            FieldValue fv = (FieldValue) value;
            return new ComplexAliasField(fv.getTableName(), fv.getFieldName(), null, null);
        } else if (value instanceof FunctionCall) {
            FunctionCall fc = (FunctionCall) value;
            String name = fc.getName().toLowerCase();
            if (fc.getArgCount() == 1) {
                Value firstValue = fc.iterator().next();
                if (firstValue instanceof FieldValue) {
                    FieldValue fv = (FieldValue) firstValue;
                    return new ComplexAliasField(fv.getTableName(), fv.getFieldName(), null, name);
                } else if (firstValue instanceof FunctionCall) {
                    FunctionCall fc2 = (FunctionCall) firstValue;
                    if (fc2.getName().equalsIgnoreCase("coalesce") && fc2.getArgCount() == 2) {
                        Iterator<Value> it = fc2.iterator();
                        Value f1 = it.next(), f2 = it.next();
                        if (f1 instanceof FieldValue) {
                            FieldValue fv = (FieldValue) f1;
                            if (f2 instanceof NumberValue) {
                                return new ComplexAliasField(fv.getTableName(), fv.getFieldName(), ((NumberValue) f2).getNumber().toString(), name);
                            } else if (f2 instanceof StringValue) {
                                return new ComplexAliasField(fv.getTableName(), fv.getFieldName(), "'" + ((StringValue) f2).getString() + "'", name);
                           }
                        }
                    }
                }
            } else if (fc.getName().equalsIgnoreCase("coalesce") && fc.getArgCount() == 2) {
                Iterator<Value> it = fc.iterator();
                Value f1 = it.next(), f2 = it.next();
                if (f1 instanceof FieldValue) {
                    FieldValue fv = (FieldValue) f1;
                    if (f2 instanceof NumberValue) {
                        return new ComplexAliasField(fv.getTableName(), fv.getFieldName(), ((NumberValue) f2).getNumber().toString(), null);
                    } else if (f2 instanceof StringValue) {
                        return new ComplexAliasField(fv.getTableName(), fv.getFieldName(), "'" + ((StringValue) f2).getString() + "'", null);
                   }
                }
            }
        } else if (value instanceof MathValue) {
            MathValue mv = (MathValue) value;
View Full Code Here

        }
    }

    private static EntityFieldValue buildFieldValue(Value value) {
        if (value instanceof FieldValue) {
            FieldValue fv = (FieldValue) value;
            return EntityFieldValue.makeFieldValue(fv.getFieldName(), fv.getTableName(), null, null);
        }
        throw new UnsupportedOperationException(value.toString());
    }
View Full Code Here

        if (value instanceof NumberValue) {
            return ((NumberValue) value).getNumber();
        } else if (value instanceof StringValue) {
            return ((StringValue) value).getString();
        } else if (value instanceof FieldValue) {
            FieldValue fv = (FieldValue) value;
            return EntityFieldValue.makeFieldValue(fv.getFieldName(), fv.getTableName(), null, null);
        } else if (value instanceof List) {
            List<Object> values = FastList.newInstance();
            for (Object sqlValue: (List) value) {
                values.add(buildValue(sqlValue, params));
            }
View Full Code Here

            assertEquals("third arg count", 1, fc.getArgCount());
            Iterator<Value> valueIt = fc.iterator();
            assertTrue("third args hasNext", valueIt.hasNext());
            Value argValue = valueIt.next();
            assertTrue("third first arg is FieldValue", argValue instanceof FieldValue);
            FieldValue fieldValue = (FieldValue) argValue;
            assertEquals("third first arg tableName", "a", fieldValue.getTableName());
            assertEquals("third first arg fieldName", "partyId", fieldValue.getFieldName());
            assertFalse("third no more args", valueIt.hasNext());

            assertTrue("has fourth field def", fieldDefIt.hasNext());
            fieldDef = fieldDefIt.next();
            assertEquals("fourth fieldDef.alias", "baz", fieldDef.getAlias());
View Full Code Here

TOP

Related Classes of org.ofbiz.sql.FieldValue

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.