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.GeneratedValue;
26: import javax.persistence.Id;
27: import javax.persistence.GeneratedValue;
28: import javax.persistence.GenerationType;
29: import javax.persistence.JoinColumn;
30: import javax.persistence.PrimaryKeyJoinColumn;
31: import javax.persistence.SecondaryTable;
32: import javax.persistence.Table;
33:
34: /**
35: * This class defines a mapping to two tables: a main table and one secondary
36: * table.
37: * @author P. Dechamboux
38: */
39: @Entity
40: @Table(name="EJB_ONESECONDARYM")
41: @SecondaryTable(name="EJB_ONESECONDARYS",pkJoinColumns=@PrimaryKeyJoinColumn(name="SID",referencedColumnName="ID"))
42: public class OneSecondary implements Serializable {
43: @Id
44: @Column(name="ID")
45: @GeneratedValue(strategy=GenerationType.SEQUENCE,generator="EJB_ONESECONDARYSEQ")
46: private Long id;
47: @Column(name="MAIN")
48: private int int_main;
49: @Column(name="SECONDARY",table="EJB_ONESECONDARYS")
50: private int int_secondary;
51:
52: public void assign(long longval) {
53: this .int_main = (int) longval;
54: this .int_secondary = (int) longval + 1;
55: }
56:
57: public void check(long longval) {
58: Assert.assertEquals("bad int_main value", int_main,
59: (int) longval);
60: Assert.assertEquals("bad int_secondary value", int_secondary,
61: (int) longval + 1);
62: }
63:
64: public int retrieve_int_field() {
65: return int_main;
66: }
67:
68: public void assign_int_field(int int_field) {
69: this .int_main = int_field;
70: this .int_secondary = int_field + 1;
71: }
72: }
|