001/*
002 * (C) Copyright 2014 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Florent Guillaume
018 */
019package org.nuxeo.ecm.core.storage.dbs;
020
021import java.io.Serializable;
022import java.util.List;
023import java.util.Map;
024import java.util.Set;
025
026import org.nuxeo.ecm.core.api.PartialList;
027import org.nuxeo.ecm.core.blob.BlobManager;
028import org.nuxeo.ecm.core.model.LockManager;
029import org.nuxeo.ecm.core.model.Repository;
030import org.nuxeo.ecm.core.query.sql.model.OrderByClause;
031import org.nuxeo.ecm.core.storage.FulltextConfiguration;
032import org.nuxeo.ecm.core.storage.State;
033import org.nuxeo.ecm.core.storage.State.StateDiff;
034
035/**
036 * Interface for a {@link Repository} for Document-Based Storage.
037 *
038 * @since 5.9.4
039 */
040public interface DBSRepository extends Repository, LockManager {
041
042    /**
043     * Gets the blob manager.
044     *
045     * @return the blob manager.
046     */
047    BlobManager getBlobManager();
048
049    /**
050     * Gets the fulltext configuration.
051     *
052     * @return the fulltext configuration
053     *
054     * @since 7.10-HF04, 8.1
055     */
056    FulltextConfiguration getFulltextConfiguration();
057
058    /**
059     * Checks if fulltext indexing is disabled.
060     *
061     * @return {@code true} if fulltext indexing is disabled, {@code false} if it is enabled
062     * @since 7.1, 6.0-HF02
063     */
064    boolean isFulltextDisabled();
065
066    /**
067     * Gets the root id.
068     *
069     * @return the root id.
070     */
071    String getRootId();
072
073    /**
074     * Generates a new id for a document.
075     *
076     * @return the new id
077     */
078    String generateNewId();
079
080    /**
081     * Reads the state of a document.
082     *
083     * @param id the document id
084     * @return the document state, or {@code null} if not found
085     */
086    State readState(String id);
087
088    /**
089     * Reads the states of several documents.
090     * <p>
091     * The returned states may be in a different order than the ids.
092     *
093     * @param ids the document ids
094     * @return the document states, an element by be {@code null} if not found
095     */
096    List<State> readStates(List<String> ids);
097
098    /**
099     * Creates a document.
100     *
101     * @param state the document state
102     */
103    void createState(State state);
104
105    /**
106     * Updates a document.
107     *
108     * @param id the document id
109     * @param diff the diff to apply
110     */
111    void updateState(String id, StateDiff diff);
112
113    /**
114     * Deletes a set of document.
115     *
116     * @param ids the document ids
117     */
118    void deleteStates(Set<String> ids);
119
120    /**
121     * Reads the state of a child document.
122     *
123     * @param parentId the parent document id
124     * @param name the name of the child
125     * @param ignored a set of document ids that should not be considered
126     * @return the state of the child document, or {@code null} if not found
127     */
128    State readChildState(String parentId, String name, Set<String> ignored);
129
130    /**
131     * Checks if a document has a child with the given name
132     *
133     * @param parentId the parent document id
134     * @param name the name of the child
135     * @param ignored a set of document ids that should not be considered
136     * @return {@code true} if the child exists, {@code false} if not
137     */
138    boolean hasChild(String parentId, String name, Set<String> ignored);
139
140    /**
141     * Queries the repository for documents having key = value.
142     *
143     * @param key the key
144     * @param value the value
145     * @param ignored a set of document ids that should not be considered
146     * @return the document states matching the query
147     */
148    List<State> queryKeyValue(String key, Object value, Set<String> ignored);
149
150    /**
151     * Queries the repository for documents having key1 = value1 and key2 = value2.
152     *
153     * @param key1 the first key
154     * @param value1 the first value
155     * @param key2 the second key
156     * @param value2 the second value
157     * @param ignored a set of document ids that should not be considered
158     * @return the document states matching the query
159     */
160    List<State> queryKeyValue(String key1, Object value1, String key2, Object value2, Set<String> ignored);
161
162    /**
163     * Queries the repository for document ids having value in key (an array).
164     *
165     * @param key the key
166     * @param value the value
167     * @param ids the set which receives the documents ids
168     * @param proxyTargets returns a map of proxy to target among the documents found
169     * @param targetProxies returns a map of target to proxies among the document found
170     */
171    void queryKeyValueArray(String key, Object value, Set<String> ids, Map<String, String> proxyTargets,
172            Map<String, Object[]> targetProxies);
173
174    /**
175     * Queries the repository to check if there are documents having key = value.
176     *
177     * @param key the key
178     * @param value the value
179     * @param ignored a set of document ids that should not be considered
180     * @return {@code true} if the query matches at least one document, {@code false} if the query matches nothing
181     */
182    boolean queryKeyValuePresence(String key, String value, Set<String> ignored);
183
184    /**
185     * Queries the repository for documents matching a NXQL query, and returns a projection of the documents.
186     *
187     * @param evaluator the map-based evaluator for the query
188     * @param orderByClause an ORDER BY clause
189     * @param limit the limit on the number of documents to return
190     * @param offset the offset in the list of documents to return
191     * @param countUpTo if {@code -1}, count the total size without offset/limit.<br>
192     *            If {@code 0}, don't count the total size, set it to {@code -1} .<br>
193     *            If {@code n}, count the total number if there are less than n documents otherwise set the total size
194     *            to {@code -2}.
195     * @return a partial list of maps containing the NXQL projections requested, and the total size according to
196     *         countUpTo
197     */
198    PartialList<Map<String, Serializable>> queryAndFetch(DBSExpressionEvaluator evaluator, OrderByClause orderByClause,
199            int limit, int offset, int countUpTo);
200
201    /**
202     * Gets the lock manager for this repository.
203     *
204     * @return the lock manager
205     * @since 7.4
206     */
207    LockManager getLockManager();
208
209}