001/* 002 * (C) Copyright 2016 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.dbs; 020 021import java.util.ArrayList; 022import java.util.HashSet; 023import java.util.List; 024import java.util.Set; 025 026import org.nuxeo.common.xmap.annotation.XNode; 027import org.nuxeo.common.xmap.annotation.XNodeList; 028import org.nuxeo.ecm.core.api.repository.PoolConfiguration; 029import org.nuxeo.ecm.core.storage.FulltextDescriptor; 030import org.nuxeo.ecm.core.storage.FulltextDescriptor.FulltextIndexDescriptor; 031 032/** 033 * DBS Repository Descriptor. 034 * 035 * @since 7.10-HF04, 8.1 036 */ 037public class DBSRepositoryDescriptor implements Cloneable { 038 039 public DBSRepositoryDescriptor() { 040 } 041 042 @XNode("@name") 043 public String name; 044 045 @XNode("@label") 046 public String label; 047 048 @XNode("@isDefault") 049 protected Boolean isDefault; 050 051 public Boolean isDefault() { 052 return isDefault; 053 } 054 055 @XNode("@headless") 056 protected Boolean headless; 057 058 /** @since 11.2 */ 059 public Boolean isHeadless() { 060 return headless; 061 } 062 063 @XNode("idType") 064 public String idType; // "varchar", "uuid", "sequence" 065 066 protected FulltextDescriptor fulltextDescriptor = new FulltextDescriptor(); 067 068 public FulltextDescriptor getFulltextDescriptor() { 069 return fulltextDescriptor; 070 } 071 072 @XNode("fulltext@fieldSizeLimit") 073 public void setFulltextFieldSizeLimit(int fieldSizeLimit) { 074 fulltextDescriptor.setFulltextFieldSizeLimit(fieldSizeLimit); 075 } 076 077 @XNode("fulltext@disabled") 078 public void setFulltextDisabled(boolean disabled) { 079 fulltextDescriptor.setFulltextDisabled(disabled); 080 } 081 082 /** @since 11.1 */ 083 @XNode("fulltext@storedInBlob") 084 public void setFulltextStoredInBlob(boolean storedInBlob) { 085 fulltextDescriptor.setFulltextStoredInBlob(storedInBlob); 086 } 087 088 @XNode("fulltext@searchDisabled") 089 public void setFulltextSearchDisabled(boolean disabled) { 090 fulltextDescriptor.setFulltextSearchDisabled(disabled); 091 } 092 093 @XNodeList(value = "fulltext/index", type = ArrayList.class, componentType = FulltextIndexDescriptor.class) 094 public void setFulltextIndexes(List<FulltextIndexDescriptor> fulltextIndexes) { 095 fulltextDescriptor.setFulltextIndexes(fulltextIndexes); 096 } 097 098 @XNodeList(value = "fulltext/excludedTypes/type", type = HashSet.class, componentType = String.class) 099 public void setFulltextExcludedTypes(Set<String> fulltextExcludedTypes) { 100 fulltextDescriptor.setFulltextExcludedTypes(fulltextExcludedTypes); 101 } 102 103 @XNodeList(value = "fulltext/includedTypes/type", type = HashSet.class, componentType = String.class) 104 public void setFulltextIncludedTypes(Set<String> fulltextIncludedTypes) { 105 fulltextDescriptor.setFulltextIncludedTypes(fulltextIncludedTypes); 106 } 107 108 /** @since 8.10 */ 109 @XNode("cache@enabled") 110 private Boolean cacheEnabled; 111 112 /** @since 8.10 */ 113 public boolean isCacheEnabled() { 114 return defaultFalse(cacheEnabled); 115 } 116 117 /** @since 8.10 */ 118 protected void setCacheEnabled(boolean enabled) { 119 cacheEnabled = Boolean.valueOf(enabled); 120 } 121 122 /** @since 8.10 */ 123 @XNode("cache@ttl") 124 public Long cacheTTL; 125 126 /** @since 8.10 */ 127 @XNode("cache@maxSize") 128 public Long cacheMaxSize; 129 130 /** @since 8.10 */ 131 @XNode("cache@concurrencyLevel") 132 public Integer cacheConcurrencyLevel; 133 134 /** @since 8.10 */ 135 @XNode("clustering/invalidatorClass") 136 public Class<? extends DBSClusterInvalidator> clusterInvalidatorClass; 137 138 /** @since 9.1 */ 139 @XNode("changeTokenEnabled") 140 private Boolean changeTokenEnabled; 141 142 /** @since 9.1 */ 143 public boolean isChangeTokenEnabled() { 144 return defaultFalse(changeTokenEnabled); 145 } 146 147 /** @since 9.1 */ 148 public void setChangeTokenEnabled(boolean enabled) { 149 this.changeTokenEnabled = Boolean.valueOf(enabled); 150 } 151 152 @XNode("pool") 153 public PoolConfiguration pool; 154 155 @Override 156 public DBSRepositoryDescriptor clone() { 157 try { 158 DBSRepositoryDescriptor clone = (DBSRepositoryDescriptor) super.clone(); 159 clone.fulltextDescriptor = new FulltextDescriptor(fulltextDescriptor); 160 clone.pool = pool == null ? null : new PoolConfiguration(pool); 161 return clone; 162 } catch (CloneNotSupportedException e) { // cannot happen 163 throw new RuntimeException(e); 164 } 165 } 166 167 public void merge(DBSRepositoryDescriptor other) { 168 if (other.name != null) { 169 name = other.name; 170 } 171 if (other.label != null) { 172 label = other.label; 173 } 174 if (other.isDefault != null) { 175 isDefault = other.isDefault; 176 } 177 if (other.pool != null) { 178 if (pool == null) { 179 pool = new PoolConfiguration(other.pool); 180 } else { 181 pool.merge(other.pool); 182 } 183 } 184 if (other.idType != null) { 185 idType = other.idType; 186 } 187 fulltextDescriptor.merge(other.fulltextDescriptor); 188 if (other.cacheEnabled != null) { 189 cacheEnabled = other.cacheEnabled; 190 } 191 if (other.cacheTTL != null) { 192 cacheTTL = other.cacheTTL; 193 } 194 if (other.cacheMaxSize != null) { 195 cacheMaxSize = other.cacheMaxSize; 196 } 197 if (other.cacheConcurrencyLevel != null) { 198 cacheConcurrencyLevel = other.cacheConcurrencyLevel; 199 } 200 if (other.clusterInvalidatorClass != null) { 201 clusterInvalidatorClass = other.clusterInvalidatorClass; 202 } 203 if (other.changeTokenEnabled != null) { 204 changeTokenEnabled = other.changeTokenEnabled; 205 } 206 } 207 208 private static boolean defaultFalse(Boolean bool) { 209 return Boolean.TRUE.equals(bool); 210 } 211 212}