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