Skip to main content
summaryrefslogtreecommitdiffstats
blob: ece2f965a64a7917df561d290eea21184b354443 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<%@ jet	package="org.eclipse.jpt.ui" 
	imports="org.eclipse.jpt.ui.internal.wizards.entity.data.model.* java.util.* " 
	class="IdClassTemplate" 
%>
<% CreateEntityTemplateModel model = (CreateEntityTemplateModel) argument; 
if (model.getJavaPackageName()!=null && model.getJavaPackageName()!="") { %>package <%=model.getJavaPackageName()%>;<%}%>

<% Collection<String> imports = model.getImports(true);
for (String anImport : imports) { %>
import <%=anImport%>;
<% } %>

/**
 * ID class for entity: <%=model.getClassName()%>
 *
 */ 
public class <%=model.getIdClassName()%> 
<% List interfaces = model.getInterfaces(); 
	if (interfaces.size()>0) {%> implements <% }
	for (int i=0; i<interfaces.size(); i++) {
		String INTERFACE = (String) interfaces.get(i);
		if (i>0) { %>, <%}%><%=INTERFACE%><%}%> {   
   
	<% List<EntityRow> fields = model.getEntityFields();
	List<String> pkFields = model.getPKFields(); 
	for (int i=0; i<fields.size(); i++) {
		EntityRow entity = (EntityRow) fields.get(i);
		if (!pkFields.contains(entity.getName())) {
			continue;
		}
	%>         
	private <%=entity.getType()%> <%=entity.getName()%>;<%}%>
	private static final long serialVersionUID = 1L;

	public <%=model.getIdClassName()%>() {}

	<%
	fields = model.getEntityFields();
	if (fields != null) for (int i=0; i<fields.size(); i++) {
		EntityRow field = (EntityRow) fields.get(i);
		String TYPE = field.getType();
		String NAME = field.getName();
		if (!pkFields.contains(NAME)) {
			continue;
		} 		
		String METHOD = NAME.substring(0,1).toUpperCase() + NAME.substring(1);        
	%>

	public <%=TYPE%> get<%=METHOD%>() {
		return this.<%=NAME%>;
	}

	public void set<%=METHOD%>(<%=TYPE%> <%=NAME%>) {
		this.<%=NAME%> = <%=NAME%>;
	}
	<%}%>
   
	/*
	 * @see java.lang.Object#equals(Object)
	 */	
	public boolean equals(Object o) {
		if (o == this) {
			return true;
		}
		if (!(o instanceof <%=model.getIdClassName()%>)) {
			return false;
		}
		<%=model.getIdClassName()%> other = (<%=model.getIdClassName()%>) o;
		return true
<% if (fields != null) for (int i=0; i<fields.size(); i++) {
	EntityRow field = (EntityRow) fields.get(i); 
	String NAME = field.getName();
	if (!pkFields.contains(NAME)) {
       	continue;
    }%>
<% 	String TYPE = field.getType(); 
	String GET_METHOD = "get" + NAME.substring(0,1).toUpperCase() + NAME.substring(1); %>
<%	if (TYPE.equals("boolean") || TYPE.equals("byte") || TYPE.equals("char") || TYPE.equals("short") || TYPE.equals("int") || TYPE.equals("long")) { %>
			&& <%=GET_METHOD%>() == other.<%=GET_METHOD%>()
<% 	} else if (TYPE.equals("double")) { %>
			&& (Double.doubleToLongBits(<%=GET_METHOD%>()) == Double.doubleToLongBits(other.<%=GET_METHOD%>()))
<% 	} else if (TYPE.equals("float")) { %>
			&& (Float.floatToIntBits(<%=GET_METHOD%>()) == Float.floatToIntBits(other.<%=GET_METHOD%>()))
<% 	} else { %>
			&& (<%=GET_METHOD%>() == null ? other.<%=GET_METHOD%>() == null : <%=GET_METHOD%>().equals(other.<%=GET_METHOD%>()))
<% 	} %>
<% } %>;
	}
	
	/*	 
	 * @see java.lang.Object#hashCode()
	 */	
	public int hashCode() {
		final int prime = 31;
		int result = 1;
<% if (fields != null) for (int i=0; i<fields.size(); i++) { 
	EntityRow field = (EntityRow) fields.get(i);
	String NAME = field.getName();
	if (!pkFields.contains(NAME)) {
       	continue;
    }%>
<% 	String TYPE = field.getType(); 
	String GET_METHOD = "get" + NAME.substring(0,1).toUpperCase() + NAME.substring(1); %>
<%	if (TYPE.equals("boolean")) { %>
		result = prime * result + (<%=GET_METHOD%>() ? 1 : 0);
<% 	} else if (TYPE.equals("int")) { %>
		result = prime * result + <%=GET_METHOD%>();
<% 	} else if (TYPE.equals("byte") || TYPE.equals("char") || TYPE.equals("short")) { %>
		result = prime * result + ((int) <%=GET_METHOD%>());
<% 	} else if (TYPE.equals("long")) { %>
		result = prime * result + ((int) (<%=GET_METHOD%>() ^ (<%=GET_METHOD%>() >>> 32)));
<% 	} else if (TYPE.equals("double")) { %>
		result = prime * result + ((int) (Double.doubleToLongBits(<%=GET_METHOD%>() ) ^ (Double.doubleToLongBits(<%=GET_METHOD%>()) >>> 32)));
<% 	} else if (TYPE.equals("float")) { %>
		result = prime * result + Float.floatToIntBits(<%=GET_METHOD%>());
<% 	} else { %>
		result = prime * result + (<%=GET_METHOD%>() == null ? 0 : <%=GET_METHOD%>().hashCode());
<% 	} %>
<% } %>
		return result;
	}
   
   
}

Back to the top