View Javadoc
1   /***
2    * License Agreement.
3    * 
4    * JSPA (POJO-SP)
5    * 
6    * Copyright (C) 2009 HRX Pty Ltd
7    * 
8    * This file is part of JSPA.
9    * 
10   * JSPA is free software: you can redistribute it and/or modify it under the
11   * terms of the GNU Lesser General Public License version 3 as published by the
12   * Free Software Foundation.
13   * 
14   * JSPA is distributed in the hope that it will be useful, but WITHOUT ANY
15   * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16   * A PARTICULAR PURPOSE. See the Lesser General Public License for more details.
17   * 
18   * You should have received a copy of the GNU Lesser General Public License
19   * along with JSPA. If not, see <http://www.gnu.org/licenses/>.
20   */
21  package com.hrx.rasp.util.dao.metadata;
22  
23  import java.lang.annotation.Annotation;
24  import java.lang.reflect.Field;
25  
26  import javax.persistence.Id;
27  
28  /***
29   * @author dan.stoica <dan.stoica@acslink.net.au>
30   * 
31   */
32  public class StoredProcField<T extends Annotation>
33  {
34  	private final String name;
35  	private final Field field;
36  	private final T parameter;
37  
38  	/***
39  	 * @param name
40  	 * @param field
41  	 * @param parameters
42  	 */
43  	public StoredProcField(String name, Field field, T parameter)
44  	{
45  		super();
46  		this.name = name;
47  		this.field = field;
48  		this.parameter = parameter;
49  	}
50  
51  	/***
52  	 * @return the name
53  	 */
54  	public String getName()
55  	{
56  		return name;
57  	}
58  
59  	/***
60  	 * @return the field
61  	 */
62  	public Field getField()
63  	{
64  		return field;
65  	}
66  
67  	/***
68  	 * @return the parameter
69  	 */
70  	public T getParameter()
71  	{
72  		return parameter;
73  	}
74  
75  	/***
76  	 * @param isPrimaryKey
77  	 * @return <code>true</code> if this <code>Field</code> has an \@Id
78  	 *         annotation; <code>false</code> false if this <code>Field</code>
79  	 *         does note have the \@Id annotation
80  	 */
81  	public boolean isPrimaryKey()
82  	{
83  		return this.field.isAnnotationPresent(Id.class);
84  	}
85  
86  	@Override
87  	public String toString()
88  	{
89  		StringBuffer sb = new StringBuffer("StoreProcField[");
90  		sb.append("name=");
91  		sb.append(this.name);
92  		sb.append(", field=");
93  		sb.append(this.field);
94  		sb.append(", parameter=");
95  		sb.append(this.parameter);
96  		sb.append("]");
97  		return sb.toString();
98  	}
99  
100 	/*
101 	 * (non-Javadoc)
102 	 * 
103 	 * @see java.lang.Object#hashCode()
104 	 */
105 	@Override
106 	public int hashCode()
107 	{
108 		final int prime = 31;
109 		int result = 1;
110 		result = prime * result + ((field == null) ? 0 : field.hashCode());
111 		return result;
112 	}
113 
114 	/*
115 	 * (non-Javadoc)
116 	 * 
117 	 * @see java.lang.Object#equals(java.lang.Object)
118 	 */
119 	@SuppressWarnings("unchecked")
120 	@Override
121 	public boolean equals(Object obj)
122 	{
123 		// There should be only one Stored Procedure Field for each Class field.
124 		if (this == obj) return true;
125 		if (obj == null) return false;
126 		if (getClass() != obj.getClass()) return false;
127 		final StoredProcField other = (StoredProcField) obj;
128 		if (field == null)
129 		{
130 			if (other.field != null) return false;
131 		}
132 		else if (!field.equals(other.field)) return false;
133 		return true;
134 	}
135 
136 }