001/*
002 * (C) Copyright 2006-2017 Nuxeo (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.sql;
020
021import java.io.Serializable;
022import java.util.Calendar;
023import java.util.Collection;
024import java.util.Map;
025import java.util.Set;
026
027import javax.transaction.xa.XAException;
028import javax.transaction.xa.XAResource;
029import javax.transaction.xa.Xid;
030
031import org.nuxeo.ecm.core.api.IterableQueryResult;
032import org.nuxeo.ecm.core.api.Lock;
033import org.nuxeo.ecm.core.api.PartialList;
034import org.nuxeo.ecm.core.api.ScrollResult;
035import org.nuxeo.ecm.core.query.QueryFilter;
036
037/**
038 * A {@link Mapper} that uses a {@link SoftRefCachingRowMapper} for row-related operation, and delegates to the
039 * {@link Mapper} for others.
040 */
041public class SoftRefCachingMapper extends SoftRefCachingRowMapper implements CachingMapper {
042
043    /**
044     * The {@link Mapper} to which operations are delegated.
045     */
046    public Mapper mapper;
047
048    @Override
049    public void initialize(String repositoryName, Model model, Mapper mapper, InvalidationsPropagator cachePropagator,
050            Map<String, String> properties) {
051        super.initialize(repositoryName, model, mapper, cachePropagator, properties);
052        this.mapper = mapper;
053    }
054
055    @Override
056    public ScrollResult scroll(String query, int batchSize, int keepAliveSeconds) {
057        return mapper.scroll(query, batchSize, keepAliveSeconds);
058    }
059
060    @Override
061    public ScrollResult scroll(String query, QueryFilter queryFilter, int batchSize, int keepAliveSeconds) {
062        return mapper.scroll(query, queryFilter, batchSize, keepAliveSeconds);
063    }
064
065    @Override
066    public ScrollResult scroll(String scrollId) {
067        return mapper.scroll(scrollId);
068    }
069
070    @Override
071    public Identification getIdentification() {
072        return mapper.getIdentification();
073    }
074
075    @Override
076    public void close() {
077        super.close();
078        mapper.close();
079    }
080
081    @Override
082    public int getTableSize(String tableName) {
083        return mapper.getTableSize(tableName);
084    }
085
086    @Override
087    public void createDatabase(String ddlMode) {
088        mapper.createDatabase(ddlMode);
089    }
090
091    @Override
092    public Serializable getRootId(String repositoryId) {
093        return mapper.getRootId(repositoryId);
094    }
095
096    @Override
097    public void setRootId(Serializable repositoryId, Serializable id) {
098        mapper.setRootId(repositoryId, id);
099    }
100
101    @Override
102    public PartialList<Serializable> query(String query, String queryType, QueryFilter queryFilter,
103            boolean countTotal) {
104        return mapper.query(query, queryType, queryFilter, countTotal);
105    }
106
107    @Override
108    public PartialList<Serializable> query(String query, String queryType, QueryFilter queryFilter, long countUpTo) {
109        return mapper.query(query, queryType, queryFilter, countUpTo);
110    }
111
112    @Override
113    public IterableQueryResult queryAndFetch(String query, String queryType, QueryFilter queryFilter,
114            boolean distinctDocuments, Object... params) {
115        return mapper.queryAndFetch(query, queryType, queryFilter, distinctDocuments, params);
116    }
117
118    @Override
119    public PartialList<Map<String, Serializable>> queryProjection(String query, String queryType,
120            QueryFilter queryFilter, boolean distinctDocuments, long countUpTo, Object... params) {
121        return mapper.queryProjection(query, queryType, queryFilter, distinctDocuments, countUpTo, params);
122    }
123
124    @Override
125    public Set<Serializable> getAncestorsIds(Collection<Serializable> ids) {
126        return mapper.getAncestorsIds(ids);
127    }
128
129    @Override
130    public void updateReadAcls() {
131        mapper.updateReadAcls();
132    }
133
134    @Override
135    public void rebuildReadAcls() {
136        mapper.rebuildReadAcls();
137    }
138
139    @Override
140    public int getClusterNodeIdType() {
141        return mapper.getClusterNodeIdType();
142    }
143
144    @Override
145    public void createClusterNode(Serializable nodeId) {
146        mapper.createClusterNode(nodeId);
147    }
148
149    @Override
150    public void removeClusterNode(Serializable nodeId) {
151        mapper.removeClusterNode(nodeId);
152    }
153
154    @Override
155    public void insertClusterInvalidations(Serializable nodeId, Invalidations invalidations) {
156        mapper.insertClusterInvalidations(nodeId, invalidations);
157    }
158
159    @Override
160    public Invalidations getClusterInvalidations(Serializable nodeId) {
161        return mapper.getClusterInvalidations(nodeId);
162    }
163
164    @Override
165    public Lock getLock(Serializable id) {
166        return mapper.getLock(id);
167    }
168
169    @Override
170    public Lock setLock(Serializable id, Lock lock) {
171        return mapper.setLock(id, lock);
172    }
173
174    @Override
175    public Lock removeLock(Serializable id, String owner, boolean force) {
176        return mapper.removeLock(id, owner, force);
177    }
178
179    @Override
180    public void markReferencedBinaries() {
181        mapper.markReferencedBinaries();
182    }
183
184    @Override
185    public int cleanupDeletedRows(int max, Calendar beforeTime) {
186        return mapper.cleanupDeletedRows(max, beforeTime);
187    }
188
189    @Override
190    public void start(Xid xid, int flags) throws XAException {
191        mapper.start(xid, flags);
192    }
193
194    @Override
195    public void end(Xid xid, int flags) throws XAException {
196        mapper.end(xid, flags);
197
198    }
199
200    @Override
201    public int prepare(Xid xid) throws XAException {
202        return mapper.prepare(xid);
203    }
204
205    @Override
206    public void commit(Xid xid, boolean onePhase) throws XAException {
207        mapper.commit(xid, onePhase);
208    }
209
210    // rollback interacts with caches so is in RowMapper
211
212    @Override
213    public void forget(Xid xid) throws XAException {
214        mapper.forget(xid);
215    }
216
217    @Override
218    public Xid[] recover(int flag) throws XAException {
219        return mapper.recover(flag);
220    }
221
222    @Override
223    public boolean setTransactionTimeout(int seconds) throws XAException {
224        return mapper.setTransactionTimeout(seconds);
225    }
226
227    @Override
228    public int getTransactionTimeout() throws XAException {
229        return mapper.getTransactionTimeout();
230    }
231
232    @Override
233    public boolean isSameRM(XAResource xares) throws XAException {
234        return mapper.isSameRM(xares);
235    }
236
237    @Override
238    public boolean isConnected() {
239        return mapper.isConnected();
240    }
241
242    @Override
243    public void connect(boolean noSharing) {
244        mapper.connect(noSharing);
245    }
246
247    @Override
248    public void disconnect() {
249        mapper.disconnect();
250    }
251
252}