001/* 002 * (C) Copyright 2006-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 * Nuxeo - initial API and implementation 018 * Florent Guillaume 019 */ 020package org.nuxeo.ecm.directory.sql; 021 022import org.nuxeo.common.xmap.annotation.XNode; 023import org.nuxeo.common.xmap.annotation.XNodeList; 024import org.nuxeo.common.xmap.annotation.XObject; 025import org.nuxeo.ecm.directory.BaseDirectoryDescriptor; 026 027@XObject(value = "directory") 028public class SQLDirectoryDescriptor extends BaseDirectoryDescriptor { 029 030 public static final int QUERY_SIZE_LIMIT_DEFAULT = 0; 031 032 @XNode("dataSource") 033 public String dataSourceName; 034 035 @XNode("querySizeLimit") 036 private Integer querySizeLimit; 037 038 @XNodeList(value = "references/tableReference", type = TableReferenceDescriptor[].class, componentType = TableReferenceDescriptor.class) 039 private TableReferenceDescriptor[] tableReferences; 040 041 @XNodeList(value = "filters/staticFilter", type = SQLStaticFilter[].class, componentType = SQLStaticFilter.class) 042 private SQLStaticFilter[] staticFilters; 043 044 @XNode("nativeCase") 045 public Boolean nativeCase; 046 047 @XNode("computeMultiTenantId") 048 private boolean computeMultiTenantId = true; 049 050 public String getDataSourceName() { 051 return dataSourceName; 052 } 053 054 public void setDataSourceName(String dataSourceName) { 055 this.dataSourceName = dataSourceName; 056 } 057 058 public TableReferenceDescriptor[] getTableReferences() { 059 return tableReferences; 060 } 061 062 public int getQuerySizeLimit() { 063 return querySizeLimit == null ? QUERY_SIZE_LIMIT_DEFAULT : querySizeLimit.intValue(); 064 } 065 066 public void setQuerySizeLimit(int querySizeLimit) { 067 this.querySizeLimit = Integer.valueOf(querySizeLimit); 068 } 069 070 public SQLStaticFilter[] getStaticFilters() { 071 if (staticFilters == null) { 072 return new SQLStaticFilter[0]; 073 } 074 return staticFilters; 075 } 076 077 /** 078 * Returns {@code true} if a multi tenant id should be computed for this directory, if the directory has support for 079 * multi tenancy, {@code false} otherwise. 080 * 081 * @since 5.6 082 */ 083 public boolean isComputeMultiTenantId() { 084 return computeMultiTenantId; 085 } 086 087 @Override 088 public void merge(BaseDirectoryDescriptor other) { 089 super.merge(other); 090 if (other instanceof SQLDirectoryDescriptor) { 091 merge((SQLDirectoryDescriptor) other); 092 } 093 } 094 095 protected void merge(SQLDirectoryDescriptor other) { 096 if (other.dataSourceName != null) { 097 dataSourceName = other.dataSourceName; 098 } 099 if (other.querySizeLimit != null) { 100 querySizeLimit = other.querySizeLimit; 101 } 102 if (other.tableReferences != null && other.tableReferences.length != 0) { 103 tableReferences = other.tableReferences; 104 } 105 if (other.staticFilters != null && other.staticFilters.length != 0) { 106 staticFilters = other.staticFilters; 107 } 108 if (other.nativeCase != null) { 109 nativeCase = other.nativeCase; 110 } 111 computeMultiTenantId = other.computeMultiTenantId; 112 } 113 114 @Override 115 public SQLDirectoryDescriptor clone() { 116 SQLDirectoryDescriptor clone = (SQLDirectoryDescriptor) super.clone(); 117 // basic fields are already copied by super.clone() 118 if (tableReferences != null) { 119 clone.tableReferences = new TableReferenceDescriptor[tableReferences.length]; 120 for (int i = 0; i < tableReferences.length; i++) { 121 clone.tableReferences[i] = tableReferences[i].clone(); 122 } 123 } 124 if (staticFilters != null) { 125 clone.staticFilters = new SQLStaticFilter[staticFilters.length]; 126 for (int i = 0; i < staticFilters.length; i++) { 127 clone.staticFilters[i] = staticFilters[i].clone(); 128 } 129 } 130 return clone; 131 } 132 133 @Override 134 public SQLDirectory newDirectory() { 135 return new SQLDirectory(this); 136 } 137 138}