Package javax.jcr.query.qom

Examples of javax.jcr.query.qom.Selector


                s.toString());
    }

    @Test
    public void selector() throws RepositoryException {
        Selector s = f.selector("nodeTypeName", "selectorName");
        assertEquals("nodeTypeName", s.getNodeTypeName());
        assertEquals("selectorName", s.getSelectorName());
        assertEquals("[nodeTypeName] AS [selectorName]", s.toString());
        assertEquals("[n]", f.selector("n"null).toString());
    }
View Full Code Here


        assertEquals("UPPER(LENGTH([selectorName].[propertyName]))", u.toString());
    }

    @Test
    public void createQuery() throws RepositoryException {
        Selector s = f.selector("nt:file", "x");
        BindVariableValue b = f.bindVariable("var");
        Constraint c = f.propertyExistence("x", "c");
        PropertyValue p = f.propertyValue("x", "propertyName");
        c = f.and(f.comparison(p, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, b), c);
        Ordering o = f.ascending(p);
View Full Code Here

        assertEquals("selector2Path", s.getSelector2Path());
    }

    @Test
    public void selector() throws RepositoryException {
        Selector s = f.selector("nodeTypeName", "selectorName");
        assertEquals("nodeTypeName", s.getNodeTypeName());
        assertEquals("selectorName", s.getSelectorName());
    }
View Full Code Here

        assertEquals(length, u.getOperand());
    }

    @Test
    public void createQuery() throws RepositoryException {
        Selector s = f.selector("nodeTypeName", "x");
        BindVariableValue b = f.bindVariable("var");
        Constraint c = f.propertyExistence("x", "c");
        PropertyValue p = f.propertyValue("x", "propertyName");
        c = f.and(f.comparison(p, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, b), c);
        Ordering o = f.ascending(p);
View Full Code Here

    }

    private String getNodeTypeFromSelector(String selectorName,
                                           String propertyName) throws RepositoryException {
        selectorName = StringUtils.removeEnd(selectorName, "translationAdded");
        Selector foundSelector = selector;
//        for (SelectorImpl selector : ((SourceImpl) qomTree.getSource()).getSelectors()) {
//            if (StringUtils.isEmpty(selectorName) || selectorName.equals(selector.getSelectorName())) {
//                foundSelector = selector;
//                break;
//            }
//        }
        return foundSelector.getNodeTypeName();
    }
View Full Code Here

         * In MODIFY_MODE return the unchanged node.
         */
        @Override
        public Object visit(ChildNodeImpl node, Object data) throws Exception {
            if (getModificationInfo().getMode() == INITIALIZE_MODE) {
                Selector selector = getSelector(getOriginalSource(), node.getSelectorName());
                if (selector != null) {
                    String nodeTypeName = selector.getNodeTypeName();
                    if (Constants.NT_BASE.equals(nodeTypeName) || Constants.JAHIANT_CONTENT.equals(nodeTypeName)) {
                        Set<String> commonChildNodeTypes = new HashSet<String>();
                        String primaryChildNodeType = getCommonChildNodeTypes(node.getParentPath(),
                                commonChildNodeTypes);
                        if (primaryChildNodeType != null) {
View Full Code Here

            if (getModificationInfo().getMode() == INITIALIZE_MODE) {
                if (QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO.equals(node.getOperator())
                        && node.getOperand1() instanceof PropertyValue
                        && Constants.JCR_LANGUAGE.equals(((PropertyValue) node.getOperand1())
                                .getPropertyName())) {
                    Selector selector = getSelector(getOriginalSource(),
                            ((PropertyValue) node.getOperand1()).getSelectorName());
                    Set<String> languages = getLanguagesPerSelector().get(
                            selector.getSelectorName());
                    if (languages == null) {
                        languages = new HashSet<String>();
                        getLanguagesPerSelector().put(selector.getSelectorName(), languages);
                    }
                    String language = ((Literal) node.getOperand2()).getLiteralValue().getString();
                    if (!languages.contains(language)) {
                        languages.add(language);
                    }
View Full Code Here

            if (getModificationInfo().getMode() == INITIALIZE_MODE) {
                if (node.getJoinCondition() instanceof ChildNodeJoinCondition) {
                    ChildNodeJoinCondition childNodeJoin = (ChildNodeJoinCondition) node
                            .getJoinCondition();
                    String childSelectorName = childNodeJoin.getChildSelectorName();
                    Selector childSelector = getSelector(getOriginalSource(), childSelectorName);
                    if (Constants.JAHIANT_TRANSLATION.equals(childSelector.getNodeTypeName())) {
                        getSelectorsJoinedWithTranslation().put(
                                childNodeJoin.getParentSelectorName(), childSelector);
                    }
                }
            }
View Full Code Here

            return newNode;
        }

        private AbstractQOMNode getNewPropertyBasedNodeIfRequired(String selectorName,
                String propertyName, AbstractQOMNode node) throws RepositoryException {
            Selector selector = getSelector(getOriginalSource(), selectorName);
            if (selector == null) {
                return node;
            }

            try {
                if (getModificationInfo().getMode() == CHECK_FOR_MODIFICATION_MODE
                        || getModificationInfo().getMode() == MODIFY_MODE) {
                    // check for language dependent modifications and use the translation selector on
                    // jnt:translation node if user specified it in query
                   
                    if (getSelectorsJoinedWithTranslation().get(selector.getSelectorName()) != null) {
                        selector = getSelectorsJoinedWithTranslation().get(selector.getSelectorName());
                    }
                    Set<String> languageCodes = getLanguagesPerSelector().get(
                            selector.getSelectorName());
                    if ((languageCodes == null || languageCodes.isEmpty()) && session != null
                            && session.getLocale() != null) {
                        if (getModificationInfo().getMode() == CHECK_FOR_MODIFICATION_MODE) {
                           
                            Set<String> newLanguageCodes = getNewLanguagesPerSelector().get(
                                    selector.getSelectorName());
                            if (newLanguageCodes == null) {
                                newLanguageCodes = new HashSet<String>();
                                newLanguageCodes.add(session.getLocale().toString());
                                newLanguageCodes.add(NO_LOCALE);
                                getNewLanguagesPerSelector().put(selector.getSelectorName(),
                                        newLanguageCodes);
                            }
                            if (newLanguageCodes.contains(NO_LOCALE)) {
                                ExtendedNodeType nodeType = NodeTypeRegistry.getInstance()
                                        .getNodeType(selector.getNodeTypeName());
                                boolean isFulltextIncludingMultilingualProperties = (propertyName == null && node instanceof FullTextSearch) ? isFulltextIncludingMultilingualProperties(
                                        nodeType, selector) : false;
                                ExtendedPropertyDefinition propDef = propertyName != null ? getPropertyDefinition(
                                        nodeType, selector, propertyName) : null;
                                if (propDef != null && propDef.isInternationalized()
                                        || isFulltextIncludingMultilingualProperties) {
                                    newLanguageCodes.remove(NO_LOCALE);
                                }
                            }

                            getModificationInfo().setModificationNecessary(true);
                        } else {
                            QueryObjectModelFactory qomFactory = getModificationInfo()
                                    .getQueryObjectModelFactory();
                            Set<String> newLanguageCodes = getNewLanguagesPerSelector().get(
                                    selector.getSelectorName());
                            if (newLanguageCodes != null) {
                                Constraint langConstraint = null;
                                for (String newLanguageCode : newLanguageCodes) {
                                    Constraint currentConstraint = NO_LOCALE
                                            .equals(newLanguageCode) ? qomFactory.not(qomFactory
                                            .propertyExistence(selector.getSelectorName(),
                                                    Constants.JCR_LANGUAGE))
                                            : qomFactory
                                                    .comparison(
                                                            qomFactory.propertyValue(
                                                                    selector.getSelectorName(),
                                                                    Constants.JCR_LANGUAGE),
                                                            QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO,
                                                            qomFactory.literal(getValueFactory()
                                                                    .createValue(newLanguageCode)));
                                    langConstraint = langConstraint == null ? currentConstraint
                                            : qomFactory.or(langConstraint, currentConstraint);
                                }
                                getModificationInfo().getNewConstraints().add(langConstraint);
                                if (languageCodes == null) {
                                    languageCodes = new HashSet<String>();
                                    getLanguagesPerSelector().put(selector.getSelectorName(),
                                            languageCodes);
                                }
                                languageCodes.addAll(newLanguageCodes);
                            }
                        }
                    }
                    if (node instanceof Column) {
                        String columnName = ((Column) node).getColumnName();
                        if (StringUtils.startsWith(columnName, "rep:facet(")
                                && !StringUtils.contains(columnName, "locale=")) {
                            ExtendedNodeType nodeType = NodeTypeRegistry.getInstance().getNodeType(
                                    selector.getNodeTypeName());
                            ExtendedPropertyDefinition propDef = propertyName != null ? getPropertyDefinition(
                                    nodeType, selector, propertyName) : null;
                            if (propDef != null && propDef.isInternationalized()) {
                                if (getModificationInfo().getMode() == CHECK_FOR_MODIFICATION_MODE) {
                                    getModificationInfo().setModificationNecessary(true);
                                } else {
                                    String facetOptions = columnName.substring("rep:facet("
                                            .length());
                                    if (languageCodes == null) {
                                        languageCodes = getNewLanguagesPerSelector().get(
                                                selector.getSelectorName());
                                    }
                                    String languageCode = null;
                                    for (String currentLanguageCode : languageCodes) {
                                        if (!NO_LOCALE.equals(currentLanguageCode)) {
                                            languageCode = currentLanguageCode;
                                            break;
                                        }

                                    }
                                    if (!StringUtils.isEmpty(languageCode)) {
                                        columnName = "rep:facet(locale=" + languageCode
                                                + (facetOptions.trim().length() > 1 ? "&" : "")
                                                + facetOptions;
                                        QueryObjectModelFactory qomFactory = getModificationInfo()
                                                .getQueryObjectModelFactory();
                                        node = (AbstractQOMNode) qomFactory.column(
                                                selector.getSelectorName(), propertyName,
                                                columnName);
                                    }
                                }
                            }
                        }
                    }
                }
            } catch (NoSuchNodeTypeException e) {
                logger.debug("Type " + selector.getNodeTypeName() + " not found in registry", e);
            }
            return node;
        }
View Full Code Here

            assertEquals("Wrong operator", operator.toString(), comp.getOperator());
        }
    }

    public void testCreateQuery() throws RepositoryException {
        Selector selector = qf.selector(testNodeType, SELECTOR_NAME1);
        QueryObjectModel qom = qf.createQuery(selector, null, null, null);
        assertTrue("Not a selector source", qom.getSource() instanceof Selector);
        assertNull("Constraint must be null", qom.getConstraint());
        assertEquals("Wrong size of orderings", 0, qom.getOrderings().length);
        assertEquals("Wrong size of columns", 0, qom.getColumns().length);
View Full Code Here

TOP

Related Classes of javax.jcr.query.qom.Selector

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.