Package org.apache.chemistry.opencmis.commons.impl

Examples of org.apache.chemistry.opencmis.commons.impl.StringListBuilder


        }

        // SELECT
        stmt.append("SELECT ");

        StringListBuilder selectList = new StringListBuilder(",", stmt);

        if (isNullOrEmpty(selectPropertyIds)) {
            // select all properties
            for (String alias : types.keySet()) {
                selectList.add(alias + ".*");
            }
        } else {
            // select provided properties
            for (String propertyId : selectPropertyIds) {

                propertyId = propertyId.trim();

                if (propertyId.equals("*")) {
                    // found property "*" -> select all properties
                    for (String alias : types.keySet()) {
                        selectList.add(alias + ".*");
                    }
                    continue;
                }

                if (propertyId.endsWith(".*")) {
                    // found property "x.*"
                    // -> select all properties of the type with alias "x"
                    String starAlias = propertyId.substring(0, propertyId.length() - 2);
                    if (types.containsKey(starAlias)) {
                        selectList.add(starAlias + ".*");
                        continue;
                    } else {
                        throw new IllegalArgumentException("Alias '" + starAlias + "' is not defined!");
                    }
                }

                PropertyDefinition<?> propertyDef = null;
                String alias = null;

                for (Map.Entry<String, ObjectType> te : types.entrySet()) {
                    propertyDef = te.getValue().getPropertyDefinitions().get(propertyId);
                    if (propertyDef != null) {
                        alias = te.getKey();
                        break;
                    }
                }

                if (propertyDef == null) {
                    throw new IllegalArgumentException("Property '" + propertyId
                            + "' is not defined in the provided object types!");
                }

                if (propertyDef.getQueryName() == null) {
                    throw new IllegalArgumentException("Property '" + propertyId + "' has no query name!");
                }

                selectList.add(alias + "." + propertyDef.getQueryName());
            }
        }

        // FROM
        stmt.append(" FROM ");

        stmt.append(primaryType.getQueryName());
        stmt.append(" AS ");
        stmt.append(primaryAlias);

        for (Map.Entry<String, ObjectType> te : types.entrySet()) {
            if (te.getKey().equals(primaryAlias)) {
                continue;
            }

            stmt.append(" JOIN ");
            stmt.append(te.getValue().getQueryName());
            stmt.append(" AS ");
            stmt.append(te.getKey());
            stmt.append(" ON ");
            stmt.append(primaryAlias);
            stmt.append(".cmis:objectId=");
            stmt.append(te.getKey());
            stmt.append(".cmis:objectId");
        }

        // WHERE
        if (whereClause != null && whereClause.trim().length() > 0) {
            stmt.append(" WHERE ");
            stmt.append(whereClause.trim());
        }

        // ORDER BY
        if (isNotEmpty(orderByPropertyIds)) {
            stmt.append(" ORDER BY ");

            StringListBuilder orderByList = new StringListBuilder(",", stmt);

            for (String propertyId : orderByPropertyIds) {
                String realPropertyId = propertyId.trim();
                String realPropertyIdLower = realPropertyId.toLowerCase(Locale.ENGLISH);
                boolean desc = false;

                if (realPropertyIdLower.endsWith(" asc")) {
                    // property ends with " asc" -> remove it
                    realPropertyId = realPropertyId.substring(0, realPropertyId.length() - 4);
                }

                if (realPropertyIdLower.endsWith(" desc")) {
                    // property ends with " desc" -> remove it and mark it as
                    // descending
                    realPropertyId = realPropertyId.substring(0, realPropertyId.length() - 5);
                    desc = true;
                }

                PropertyDefinition<?> propertyDef = null;
                String alias = null;

                for (Map.Entry<String, ObjectType> te : types.entrySet()) {
                    propertyDef = te.getValue().getPropertyDefinitions().get(realPropertyId);
                    if (propertyDef != null) {
                        alias = te.getKey();
                        break;
                    }
                }

                if (propertyDef == null) {
                    throw new IllegalArgumentException("Property '" + realPropertyId
                            + "' is not defined in the provided object types!");
                }

                if (propertyDef.getQueryName() == null) {
                    throw new IllegalArgumentException("Property '" + realPropertyId + "' has no query name!");
                }

                if (Boolean.FALSE.equals(propertyDef.isOrderable())) {
                    throw new IllegalArgumentException("Property '" + realPropertyId + "' is not orderable!");
                }

                orderByList.add(alias + "." + propertyDef.getQueryName() + (desc ? " DESC" : ""));
            }
        }

        this.statement = stmt.toString();
    }
View Full Code Here


    public void setNumber(int parameterIndex, Number... num) {
        if (num == null || num.length == 0) {
            throw new IllegalArgumentException("Number must be set!");
        }

        StringListBuilder slb = new StringListBuilder(",");
        for (Number n : num) {
            if (n == null) {
                throw new IllegalArgumentException("Number is null!");
            }

            slb.add(n.toString());
        }

        parametersMap.put(parameterIndex, slb.toString());
    }
View Full Code Here

    public void setString(int parameterIndex, String... str) {
        if (str == null || str.length == 0) {
            throw new IllegalArgumentException("String must be set!");
        }

        StringListBuilder slb = new StringListBuilder(",");
        for (String s : str) {
            if (s == null) {
                throw new IllegalArgumentException("String is null!");
            }

            slb.add(escape(s));
        }

        parametersMap.put(parameterIndex, slb.toString());
    }
View Full Code Here

    public void setId(int parameterIndex, ObjectId... id) {
        if (id == null || id.length == 0) {
            throw new IllegalArgumentException("Id must be set!");
        }

        StringListBuilder slb = new StringListBuilder(",");
        for (ObjectId oid : id) {
            if (oid == null || oid.getId() == null) {
                throw new IllegalArgumentException("Id is null!");
            }

            slb.add(escape(oid.getId()));
        }

        parametersMap.put(parameterIndex, slb.toString());
    }
View Full Code Here

    public void setUri(int parameterIndex, URI... uri) {
        if (uri == null) {
            throw new IllegalArgumentException("URI must be set!");
        }

        StringListBuilder slb = new StringListBuilder(",");
        for (URI u : uri) {
            if (u == null) {
                throw new IllegalArgumentException("URI is null!");
            }

            slb.add(escape(u.toString()));
        }

        parametersMap.put(parameterIndex, slb.toString());
    }
View Full Code Here

    public void setUrl(int parameterIndex, URL... url) {
        if (url == null) {
            throw new IllegalArgumentException("URL must be set!");
        }

        StringListBuilder slb = new StringListBuilder(",");
        for (URL u : url) {
            if (u == null) {
                throw new IllegalArgumentException("URI is null!");
            }

            slb.add(escape(u.toString()));
        }

        parametersMap.put(parameterIndex, slb.toString());
    }
View Full Code Here

    public void setBoolean(int parameterIndex, boolean... bool) {
        if (bool == null || bool.length == 0) {
            throw new IllegalArgumentException("Boolean must not be set!");
        }

        StringListBuilder slb = new StringListBuilder(",");
        for (boolean b : bool) {
            slb.add(b ? "TRUE" : "FALSE");
        }

        parametersMap.put(parameterIndex, slb.toString());
    }
View Full Code Here

    protected void setDateTime(int parameterIndex, boolean prefix, Date... date) {
        if (date == null || date.length == 0) {
            throw new IllegalArgumentException("Date must be set!");
        }

        StringListBuilder slb = new StringListBuilder(",");
        for (Date d : date) {
            if (d == null) {
                throw new IllegalArgumentException("DateTime is null!");
            }

            slb.add((prefix ? "TIMESTAMP " : "") + convert(d));
        }

        parametersMap.put(parameterIndex, slb.toString());
    }
View Full Code Here

    protected void setDateTime(int parameterIndex, boolean prefix, long... ms) {
        if (ms == null || ms.length == 0) {
            throw new IllegalArgumentException("Timestamp must be set!");
        }

        StringListBuilder slb = new StringListBuilder(",");
        for (long l : ms) {
            slb.add((prefix ? "TIMESTAMP " : "") + convert(new Date(l)));
        }

        parametersMap.put(parameterIndex, slb.toString());
    }
View Full Code Here

TOP

Related Classes of org.apache.chemistry.opencmis.commons.impl.StringListBuilder

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.