KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > tests > common > ejbs > entity > simpleentity > SimpleEntity


1 /**
2  * EasyBeans
3  * Copyright (C) 2006 Bull S.A.S.
4  * Contact: easybeans@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: SimpleEntity.java 786 2006-06-27 13:13:32Z pinheirg $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.easybeans.tests.common.ejbs.entity.simpleentity;
26
27 import java.io.Serializable JavaDoc;
28
29 import javax.persistence.Entity;
30 import javax.persistence.EntityResult;
31 import javax.persistence.FieldResult;
32 import javax.persistence.Id;
33 import javax.persistence.NamedNativeQuery;
34 import javax.persistence.NamedQueries;
35 import javax.persistence.NamedQuery;
36 import javax.persistence.SqlResultSetMapping;
37 import javax.persistence.SqlResultSetMappings;
38 import javax.persistence.Table;
39
40 /**
41  * Simple entity used in the EntityManager tests.
42  * @author Gisele Pinheiro Souza
43  * @author Eduardo Studzinski Estima de Castro
44  */

45 @Entity
46 @Table(name = "SIMPLE")
47 @NamedQueries({@NamedQuery(name = "findByName", query = "SELECT e FROM SimpleEntity e WHERE e.name = :entityName "),
48         @NamedQuery(name = "findByIdNamed", query = "SELECT e FROM SimpleEntity e WHERE e.id > :entityId")})
49 @SqlResultSetMappings({
50         @SqlResultSetMapping(name = "SimpleEntityResult", entities = @EntityResult(entityClass = SimpleEntity.class)),
51         @SqlResultSetMapping(name = "MappedSimpleEntity", entities = @EntityResult(entityClass = SimpleEntity.class, fields = {
52                 @FieldResult(name = "id", column = "entity_id"), @FieldResult(name = "name", column = "entity_name")}))})
53 @NamedNativeQuery(name = "findByAll", query = "SELECT e.id, e.name FROM SIMPLE e ORDER BY e.id",
54         resultSetMapping = "SimpleEntityResult")
55 public class SimpleEntity implements Serializable JavaDoc {
56
57     /**
58      * The serial version.
59      */

60     private static final long serialVersionUID = 7281003617281981005L;
61
62     /**
63      * The bean Id.
64      */

65     private int id;
66
67     /**
68      * The bean name.
69      */

70     private String JavaDoc name;
71
72     /**
73      * Gets the bean Id.
74      * @return the id of the bean.
75      */

76     @Id
77     public int getId() {
78         return id;
79     }
80
81     /**
82      * Sets bean Id.
83      * @param id the bean id.
84      */

85     public void setId(final int id) {
86         this.id = id;
87     }
88
89     /**
90      * Sets the bean name.
91      * @param name bean name.
92      */

93     public void setName(final String JavaDoc name) {
94         this.name = name;
95     }
96
97     /**
98      * Gets the bean name.
99      * @return bean name.
100      */

101     public String JavaDoc getName() {
102         return name;
103     }
104
105     /**
106      * Computes a string representation of this bean.
107      * @return string representation.
108      */

109     @Override JavaDoc
110     public String JavaDoc toString() {
111         StringBuilder JavaDoc sb = new StringBuilder JavaDoc();
112         sb.append("SimpleEntity[id=").append(id).append(", name=").append(getName()).append("]");
113         return sb.toString();
114     }
115
116 }
117
Popular Tags