This project has retired. For details please refer to its
Attic page.
TypeDefinitionCache xref
1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing,13 * software distributed under the License is distributed on an14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15 * KIND, either express or implied. See the License for the16 * specific language governing permissions and limitations17 * under the License.18 */19package org.apache.chemistry.opencmis.client.bindings.impl;
2021import java.io.Serializable;
2223import org.apache.chemistry.opencmis.client.bindings.cache.Cache;
24import org.apache.chemistry.opencmis.client.bindings.cache.impl.CacheImpl;
25import org.apache.chemistry.opencmis.client.bindings.cache.impl.LruCacheLevelImpl;
26import org.apache.chemistry.opencmis.client.bindings.cache.impl.MapCacheLevelImpl;
27import org.apache.chemistry.opencmis.client.bindings.spi.BindingSession;
28import org.apache.chemistry.opencmis.commons.SessionParameter;
29import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
3031/**32 * A cache for type definition objects.33 */34publicclassTypeDefinitionCache implements Serializable {
3536privatestaticfinallong serialVersionUID = 1L;
3738privatestaticfinalint CACHE_SIZE_REPOSITORIES = 10;
39privatestaticfinalint CACHE_SIZE_TYPES = 100;
4041privatefinalCache cache;
4243/**44 * Constructor.45 * 46 * @param session47 * the session object48 */49publicTypeDefinitionCache(BindingSession session) {
50int repCount = session.get(SessionParameter.CACHE_SIZE_REPOSITORIES, CACHE_SIZE_REPOSITORIES);
51if (repCount < 1) {
52 repCount = CACHE_SIZE_REPOSITORIES;
53 }
5455int typeCount = session.get(SessionParameter.CACHE_SIZE_TYPES, CACHE_SIZE_TYPES);
56if (typeCount < 1) {
57 typeCount = CACHE_SIZE_TYPES;
58 }
5960 cache = newCacheImpl("Type Definition Cache");
61 cache.initialize(new String[] {
62 MapCacheLevelImpl.class.getName() + " " + MapCacheLevelImpl.CAPACITY + "=" + repCount, // repository63 LruCacheLevelImpl.class.getName() + " " + LruCacheLevelImpl.MAX_ENTRIES + "=" + typeCount // type64 });
65 }
6667/**68 * Adds a type definition object to the cache.69 * 70 * @param repositoryId71 * the repository id72 * @param typeDefinition73 * the type definition object74 */75publicvoid put(String repositoryId, TypeDefinition typeDefinition) {
76if ((typeDefinition == null) || (typeDefinition.getId() == null)) {
77return;
78 }
7980 cache.put(typeDefinition, repositoryId, typeDefinition.getId());
81 }
8283/**84 * Retrieves a type definition object from the cache.85 * 86 * @param repositoryId87 * the repository id88 * @param typeId89 * the type id90 * @return the type definition object or <code>null</code> if the object is91 * not in the cache92 */93public TypeDefinition get(String repositoryId, String typeId) {
94return (TypeDefinition) cache.get(repositoryId, typeId);
95 }
9697/**98 * Removes a type definition object from the cache.99 * 100 * @param repositoryId101 * the repository id102 * @param typeId103 * the type id104 */105publicvoid remove(String repositoryId, String typeId) {
106 cache.remove(repositoryId, typeId);
107 }
108109/**110 * Removes all type definition objects of a repository from the cache.111 * 112 * @param repositoryId113 * the repository id114 */115publicvoid remove(String repositoryId) {
116 cache.remove(repositoryId);
117 }
118119 @Override
120public String toString() {
121return cache.toString();
122 }
123 }