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