001: /*
002: * Copyright 2004 Outerthought bvba and Schaubroeck nv
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: package org.outerj.daisy.repository.serverimpl;
017:
018: import org.outerj.daisy.repository.commonimpl.*;
019: import org.outerj.daisy.repository.commonimpl.comment.CommentStrategy;
020: import org.outerj.daisy.repository.commonimpl.variant.VariantStrategy;
021: import org.outerj.daisy.repository.commonimpl.acl.AclStrategy;
022: import org.outerj.daisy.repository.commonimpl.schema.SchemaStrategy;
023: import org.outerj.daisy.repository.commonimpl.user.UserManagementStrategy;
024: import org.outerj.daisy.repository.RepositoryException;
025: import org.outerj.daisy.repository.AvailableVariants;
026: import org.outerj.daisy.repository.Document;
027: import org.outerj.daisy.repository.spi.ExtensionProvider;
028: import org.outerj.daisy.repository.serverimpl.query.LocalQueryManager;
029: import org.outerj.daisy.repository.query.QueryManager;
030: import org.outerj.daisy.repository.acl.AclResultInfo;
031: import org.outerj.daisy.cache.DocumentCache;
032: import org.outerj.daisy.jdbcutil.JdbcHelper;
033:
034: import java.util.Map;
035:
036: /**
037: * Extended version of CommonRepository that supports document caching.
038: */
039: public class LocalCommonRepository extends CommonRepository {
040: private DocumentCache cache;
041: private AuthenticatedUser systemUser;
042: private LocalRepositoryManager.Context context;
043: private JdbcHelper jdbcHelper;
044:
045: public LocalCommonRepository(RepositoryStrategy repositoryStrategy,
046: DocumentStrategy documentStrategy,
047: SchemaStrategy schemaStrategy, AclStrategy aclStrategy,
048: UserManagementStrategy userManagementStrategy,
049: VariantStrategy variantStrategy,
050: CollectionStrategy collectionStrategy,
051: CommentStrategy commentStrategy,
052: LocalRepositoryManager.Context context,
053: AuthenticatedUser systemUser, DocumentCache cache,
054: Map<String, ExtensionProvider> extensions,
055: JdbcHelper jdbcHelper) {
056: super (repositoryStrategy, documentStrategy, schemaStrategy,
057: aclStrategy, userManagementStrategy, variantStrategy,
058: collectionStrategy, commentStrategy, extensions,
059: systemUser);
060:
061: this .context = context;
062: this .cache = cache;
063: this .systemUser = systemUser;
064: this .jdbcHelper = jdbcHelper;
065: }
066:
067: public QueryManager getQueryManager(AuthenticatedUser user) {
068: return new LocalQueryManager(context, documentStrategy, user,
069: systemUser, jdbcHelper);
070: }
071:
072: public Document getDocument(DocId docId, long branchId,
073: long languageId, boolean updateable, AuthenticatedUser user)
074: throws RepositoryException {
075: if (updateable) {
076: // always load fresh data
077: return super .getDocument(docId, branchId, languageId,
078: updateable, user);
079: }
080:
081: Document document = cache.get(docId.toString(), branchId,
082: languageId);
083:
084: if (document == null) {
085: document = super .getDocument(docId, branchId, languageId,
086: updateable, systemUser);
087: cache.put(docId.toString(), branchId, languageId,
088: (DocumentImpl) document);
089: }
090:
091: AclResultInfo aclInfo = getAccessManager().getAclInfoOnLive(
092: systemUser, user.getId(), user.getActiveRoleIds(),
093: document);
094: return DocumentAccessUtil.protectDocument(aclInfo, document,
095: docId, user, this , documentStrategy);
096: }
097:
098: public AvailableVariants getAvailableVariants(DocId docId,
099: AuthenticatedUser user) throws RepositoryException {
100: AvailableVariants availableVariants = cache
101: .getAvailableVariants(docId.toString());
102: if (availableVariants == null) {
103: availableVariants = super.getAvailableVariants(docId, user);
104: cache.put(docId.toString(), availableVariants);
105: }
106: return availableVariants;
107: }
108: }
|