All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.jackrabbit.commons.query.sql2.SQL2QOMBuilder Maven / Gradle / Ivy

The newest version!
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.jackrabbit.commons.query.sql2;

import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;

import javax.jcr.query.qom.QueryObjectModel;
import javax.jcr.query.qom.QueryObjectModelFactory;
import javax.jcr.query.InvalidQueryException;
import javax.jcr.query.Query;
import javax.jcr.ValueFactory;
import javax.jcr.RepositoryException;

import org.apache.jackrabbit.commons.query.QueryObjectModelBuilder;

/**
 * SQL2QOMBuilder implements QOM builder that understands
 * {@link Query#JCR_SQL2} and {@link Query#JCR_JQOM}. JCR_JQOM
 * might be surprising, but JSR 283 says that the serialization format of
 * JCR_JQOM is JCR_SQL2. This is important when
 * a JQOM is stored on a node as a serialized String and a language property
 * set to JCR_JQOM.
 */
public class SQL2QOMBuilder implements QueryObjectModelBuilder {

    /**
     * Supports {@link Query#JCR_JQOM} and {@link Query#JCR_SQL2}.
     */
    private static final List SUPPORTED = new ArrayList(
            Arrays.asList(Query.JCR_JQOM, Query.JCR_SQL2));

    /**
     * {@inheritDoc}
     */
    public QueryObjectModel createQueryObjectModel(String statement,
                                                   QueryObjectModelFactory qf,
                                                   ValueFactory vf)
            throws InvalidQueryException, RepositoryException {
        return new Parser(qf, vf).createQueryObjectModel(statement);
    }

    /**
     * {@inheritDoc}
     */
    public boolean canHandle(String language) {
        return SUPPORTED.contains(language);
    }

    /**
     * {@inheritDoc}
     */
    public String[] getSupportedLanguages() {
        return SUPPORTED.toArray(new String[SUPPORTED.size()]);
    }

    /**
     * {@inheritDoc}
     */
    public String toString(QueryObjectModel qom)
            throws InvalidQueryException {
        try {
            return QOMFormatter.format(qom);
        } catch (RepositoryException e) {
            throw new InvalidQueryException(e.getMessage(), e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy