View Javadoc
1   /*******************************************************************************
2    * Copyright 2012 pw999
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   ******************************************************************************/
16  package net.sf.oqt.model;
17  
18  import java.io.Serializable;
19  import java.util.ArrayList;
20  import java.util.Collection;
21  
22  /**
23   * Models a named query.
24   * 
25   * @author phillip
26   * 
27   */
28  public class QueryVO implements Serializable, Comparable<QueryVO> {
29  
30      /**
31       * UID
32       */
33      private static final long serialVersionUID = -3293726054842211923L;
34  
35      private final String name;
36  
37      private final String JPQLQuery;
38  
39      private String error = null;
40  
41      private final Collection<String> SQLQuery = new ArrayList<String>();
42  
43      public QueryVO(final String name, final String jPQLQuery) {
44          this.name = name;
45          JPQLQuery = jPQLQuery;
46      }
47  
48      public final String getName() {
49          return name;
50      }
51  
52      public final String getError() {
53          return error;
54      }
55  
56      public final void setError(final String error) {
57          this.error = error;
58      }
59  
60      public final void setError(final Throwable e) {
61          this.error = "Exception: " + e.getClass().getSimpleName() + ": " + e.getMessage();
62      }
63  
64      public final String getJPQLQuery() {
65          return JPQLQuery;
66      }
67  
68      public final Collection<String> getSQLQuery() {
69          return SQLQuery;
70      }
71  
72      @Override
73      public int compareTo(final QueryVO o) {
74          return getName().compareToIgnoreCase(o.getName());
75      }
76  
77      public boolean isValid() {
78          if (error == null) {
79              return true;
80          } else if (error.isEmpty()) {
81              return true;
82          }
83          return false;
84      }
85  
86      @Override
87      public int hashCode() {
88          final int prime = 31;
89          int result = 1;
90          result = prime * result + ((name == null) ? 0 : name.hashCode());
91          return result;
92      }
93  
94      @Override
95      public boolean equals(final Object obj) {
96          if (obj instanceof QueryVO) {
97              return getName().equals(((QueryVO) obj).getName());
98          }
99          return super.equals(obj);
100     }
101 
102 
103 }