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 public String getDataSourceName() { 048 return dataSourceName; 049 } 050 051 public void setDataSourceName(String dataSourceName) { 052 this.dataSourceName = dataSourceName; 053 } 054 055 public TableReferenceDescriptor[] getTableReferences() { 056 return tableReferences; 057 } 058 059 public int getQuerySizeLimit() { 060 return querySizeLimit == null ? QUERY_SIZE_LIMIT_DEFAULT : querySizeLimit.intValue(); 061 } 062 063 public void setQuerySizeLimit(int querySizeLimit) { 064 this.querySizeLimit = Integer.valueOf(querySizeLimit); 065 } 066 067 public SQLStaticFilter[] getStaticFilters() { 068 if (staticFilters == null) { 069 return new SQLStaticFilter[0]; 070 } 071 return staticFilters; 072 } 073 074 @Override 075 public void merge(BaseDirectoryDescriptor other) { 076 super.merge(other); 077 if (other instanceof SQLDirectoryDescriptor) { 078 merge((SQLDirectoryDescriptor) other); 079 } 080 } 081 082 protected void merge(SQLDirectoryDescriptor other) { 083 if (other.dataSourceName != null) { 084 dataSourceName = other.dataSourceName; 085 } 086 if (other.querySizeLimit != null) { 087 querySizeLimit = other.querySizeLimit; 088 } 089 if (other.tableReferences != null && other.tableReferences.length != 0) { 090 tableReferences = other.tableReferences; 091 } 092 if (other.staticFilters != null && other.staticFilters.length != 0) { 093 staticFilters = other.staticFilters; 094 } 095 if (other.nativeCase != null) { 096 nativeCase = other.nativeCase; 097 } 098 } 099 100 @Override 101 public SQLDirectoryDescriptor clone() { 102 SQLDirectoryDescriptor clone = (SQLDirectoryDescriptor) super.clone(); 103 // basic fields are already copied by super.clone() 104 if (tableReferences != null) { 105 clone.tableReferences = new TableReferenceDescriptor[tableReferences.length]; 106 for (int i = 0; i < tableReferences.length; i++) { 107 clone.tableReferences[i] = tableReferences[i].clone(); 108 } 109 } 110 if (staticFilters != null) { 111 clone.staticFilters = new SQLStaticFilter[staticFilters.length]; 112 for (int i = 0; i < staticFilters.length; i++) { 113 clone.staticFilters[i] = staticFilters[i].clone(); 114 } 115 } 116 return clone; 117 } 118 119 @Override 120 public SQLDirectory newDirectory() { 121 return new SQLDirectory(this); 122 } 123 124}