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