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