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