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 scrollId) {
062        return mapper.scroll(scrollId);
063    }
064
065    @Override
066    public Identification getIdentification() {
067        return mapper.getIdentification();
068    }
069
070    @Override
071    public void close() {
072        super.close();
073        mapper.close();
074    }
075
076    @Override
077    public int getTableSize(String tableName) {
078        return mapper.getTableSize(tableName);
079    }
080
081    @Override
082    public void createDatabase(String ddlMode) {
083        mapper.createDatabase(ddlMode);
084    }
085
086    @Override
087    public Serializable getRootId(String repositoryId) {
088        return mapper.getRootId(repositoryId);
089    }
090
091    @Override
092    public void setRootId(Serializable repositoryId, Serializable id) {
093        mapper.setRootId(repositoryId, id);
094    }
095
096    @Override
097    public PartialList<Serializable> query(String query, String queryType, QueryFilter queryFilter,
098            boolean countTotal) {
099        return mapper.query(query, queryType, queryFilter, countTotal);
100    }
101
102    @Override
103    public PartialList<Serializable> query(String query, String queryType, QueryFilter queryFilter, long countUpTo) {
104        return mapper.query(query, queryType, queryFilter, countUpTo);
105    }
106
107    @Override
108    public IterableQueryResult queryAndFetch(String query, String queryType, QueryFilter queryFilter,
109            boolean distinctDocuments, Object... params) {
110        return mapper.queryAndFetch(query, queryType, queryFilter, distinctDocuments, params);
111    }
112
113    @Override
114    public PartialList<Map<String, Serializable>> queryProjection(String query, String queryType,
115            QueryFilter queryFilter, boolean distinctDocuments, long countUpTo, Object... params) {
116        return mapper.queryProjection(query, queryType, queryFilter, distinctDocuments, countUpTo, params);
117    }
118
119    @Override
120    public Set<Serializable> getAncestorsIds(Collection<Serializable> ids) {
121        return mapper.getAncestorsIds(ids);
122    }
123
124    @Override
125    public void updateReadAcls() {
126        mapper.updateReadAcls();
127    }
128
129    @Override
130    public void rebuildReadAcls() {
131        mapper.rebuildReadAcls();
132    }
133
134    @Override
135    public int getClusterNodeIdType() {
136        return mapper.getClusterNodeIdType();
137    }
138
139    @Override
140    public void createClusterNode(Serializable nodeId) {
141        mapper.createClusterNode(nodeId);
142    }
143
144    @Override
145    public void removeClusterNode(Serializable nodeId) {
146        mapper.removeClusterNode(nodeId);
147    }
148
149    @Override
150    public void insertClusterInvalidations(Serializable nodeId, Invalidations invalidations) {
151        mapper.insertClusterInvalidations(nodeId, invalidations);
152    }
153
154    @Override
155    public Invalidations getClusterInvalidations(Serializable nodeId) {
156        return mapper.getClusterInvalidations(nodeId);
157    }
158
159    @Override
160    public Lock getLock(Serializable id) {
161        return mapper.getLock(id);
162    }
163
164    @Override
165    public Lock setLock(Serializable id, Lock lock) {
166        return mapper.setLock(id, lock);
167    }
168
169    @Override
170    public Lock removeLock(Serializable id, String owner, boolean force) {
171        return mapper.removeLock(id, owner, force);
172    }
173
174    @Override
175    public void markReferencedBinaries() {
176        mapper.markReferencedBinaries();
177    }
178
179    @Override
180    public int cleanupDeletedRows(int max, Calendar beforeTime) {
181        return mapper.cleanupDeletedRows(max, beforeTime);
182    }
183
184    @Override
185    public void start(Xid xid, int flags) throws XAException {
186        mapper.start(xid, flags);
187    }
188
189    @Override
190    public void end(Xid xid, int flags) throws XAException {
191        mapper.end(xid, flags);
192
193    }
194
195    @Override
196    public int prepare(Xid xid) throws XAException {
197        return mapper.prepare(xid);
198    }
199
200    @Override
201    public void commit(Xid xid, boolean onePhase) throws XAException {
202        mapper.commit(xid, onePhase);
203    }
204
205    // rollback interacts with caches so is in RowMapper
206
207    @Override
208    public void forget(Xid xid) throws XAException {
209        mapper.forget(xid);
210    }
211
212    @Override
213    public Xid[] recover(int flag) throws XAException {
214        return mapper.recover(flag);
215    }
216
217    @Override
218    public boolean setTransactionTimeout(int seconds) throws XAException {
219        return mapper.setTransactionTimeout(seconds);
220    }
221
222    @Override
223    public int getTransactionTimeout() throws XAException {
224        return mapper.getTransactionTimeout();
225    }
226
227    @Override
228    public boolean isSameRM(XAResource xares) throws XAException {
229        return mapper.isSameRM(xares);
230    }
231
232    @Override
233    public boolean isConnected() {
234        return mapper.isConnected();
235    }
236
237    @Override
238    public void connect(boolean noSharing) {
239        mapper.connect(noSharing);
240    }
241
242    @Override
243    public void disconnect() {
244        mapper.disconnect();
245    }
246
247}