View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.core.persistence.api.dao.search;
20  
21  import org.apache.commons.lang3.builder.EqualsBuilder;
22  import org.apache.commons.lang3.builder.HashCodeBuilder;
23  import org.apache.commons.lang3.builder.ToStringBuilder;
24  
25  /**
26   * Search condition to be applied when comparing attribute values.
27   */
28  public class AttrCond extends AbstractSearchCond {
29  
30      private static final long serialVersionUID = 3275277728404021417L;
31  
32      public enum Type {
33  
34          LIKE,
35          ILIKE,
36          EQ,
37          IEQ,
38          GT,
39          LT,
40          GE,
41          LE,
42          ISNULL,
43          ISNOTNULL
44  
45      }
46  
47      private Type type;
48  
49      private String schema;
50  
51      private String expression;
52  
53      public AttrCond() {
54          super();
55      }
56  
57      public AttrCond(final Type conditionType) {
58          super();
59          this.type = conditionType;
60      }
61  
62      public final String getExpression() {
63          return expression;
64      }
65  
66      public final void setExpression(final String conditionExpression) {
67          this.expression = conditionExpression;
68      }
69  
70      public final String getSchema() {
71          return schema;
72      }
73  
74      public final void setSchema(final String conditionSchema) {
75          this.schema = conditionSchema;
76      }
77  
78      public final Type getType() {
79          return type;
80      }
81  
82      public final void setType(final Type conditionType) {
83          this.type = conditionType;
84      }
85  
86      @Override
87      public final boolean isValid() {
88          return type != null && schema != null && (type == Type.ISNULL || type == Type.ISNOTNULL || expression != null);
89      }
90  
91      @Override
92      public int hashCode() {
93          return new HashCodeBuilder().
94                  append(type).
95                  append(schema).
96                  append(expression).
97                  build();
98      }
99  
100     @Override
101     public boolean equals(final Object obj) {
102         if (this == obj) {
103             return true;
104         }
105         if (obj == null) {
106             return false;
107         }
108         if (getClass() != obj.getClass()) {
109             return false;
110         }
111         final AttrCond other = (AttrCond) obj;
112         return new EqualsBuilder().
113                 append(type, other.type).
114                 append(schema, other.schema).
115                 append(expression, other.expression).
116                 build();
117     }
118 
119     @Override
120     public String toString() {
121         return new ToStringBuilder(this).
122                 append(type).
123                 append(schema).
124                 append(expression).
125                 build();
126     }
127 }