01: /**
02: * Copyright (C) 2001-2005 France Telecom R&D
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */package org.objectweb.speedo.ejb.pobjects.basic;
18:
19: import junit.framework.Assert;
20:
21: import java.io.Serializable;
22:
23: import javax.persistence.Column;
24: import javax.persistence.Entity;
25: import javax.persistence.Id;
26: import javax.persistence.JoinColumn;
27: import javax.persistence.PrimaryKeyJoinColumn;
28: import javax.persistence.SecondaryTable;
29: import javax.persistence.SecondaryTables;
30: import javax.persistence.Table;
31:
32: /**
33: * This class defines a mapping to two tables: a main table and several
34: * secondary tables.
35: * @author P. Dechamboux
36: */
37: @Entity
38: @Table(name="EJB_SEVSECONDARYM")
39: @SecondaryTables({@SecondaryTable(name="EJB_SEVSECONDARYS1",pkJoinColumns=@PrimaryKeyJoinColumn(name="S1ID",referencedColumnName="ID")),@SecondaryTable(name="EJB_SEVSECONDARYS2",pkJoinColumns=@PrimaryKeyJoinColumn(name="S2ID",referencedColumnName="ID"))})
40: public class SeveralSecondary implements Serializable {
41: @Id
42: @Column(name="ID")
43: private Long id;
44: @Column(name="MAIN")
45: private int int_main;
46: // TODO: Does not support same column name into two different table: coorect it!!
47: @Column(name="SECONDARY1",table="EJB_SEVSECONDARYS1")
48: private int int_secondary1;
49: @Column(name="SECONDARY2",table="EJB_SEVSECONDARYS2")
50: private int int_secondary2;
51:
52: public void assign(long longval) {
53: this .int_main = (int) longval;
54: this .int_secondary1 = (int) longval + 1;
55: this .int_secondary2 = (int) longval + 2;
56: }
57:
58: public void check(long longval) {
59: Assert.assertEquals("bad int_main value", int_main,
60: (int) longval);
61: Assert.assertEquals("bad int_secondary value", int_secondary1,
62: (int) longval + 1);
63: Assert.assertEquals("bad int_secondary value", int_secondary2,
64: (int) longval + 2);
65: }
66:
67: public int retrieve_int_field() {
68: return int_main;
69: }
70:
71: public void assign_int_field(int int_field) {
72: this .int_main = int_field;
73: this .int_secondary1 = int_field + 1;
74: this .int_secondary2 = int_field + 2;
75: }
76: }
|