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.Basic;
24: import javax.persistence.Column;
25: import javax.persistence.Entity;
26: import javax.persistence.Id;
27: import javax.persistence.SecondaryTable;
28: import javax.persistence.Table;
29: import javax.persistence.UniqueConstraint;
30:
31: /**
32: * This class defines some unique constraints.
33: * @author P. Dechamboux
34: */
35: @Entity
36: @Table(name="EJB_CONSTRAINTSDEFM",uniqueConstraints={@UniqueConstraint(columnNames={"f1","f2"})})
37: @SecondaryTable(name="EJB_CONSTRAINTSDEFS",uniqueConstraints={@UniqueConstraint(columnNames={"f4"}),@UniqueConstraint(columnNames={"f5","f3"}),@UniqueConstraint(columnNames={"f3","f5"})})
38: public class ConstraintsDef implements Serializable {
39: @Id
40: private Long oid;
41: @Column(name="INTFIELD",unique=true)
42: private int int_field;
43: @Basic
44: private int f1;
45: @Basic
46: private int f2;
47: @Column(table="EJB_CONSTRAINTSDEFS")
48: private int f3;
49: @Column(table="EJB_CONSTRAINTSDEFS")
50: private int f4;
51: @Column(table="EJB_CONSTRAINTSDEFS")
52: private int f5;
53:
54: public void assign(long longval) {
55: this .int_field = (int) longval;
56: this .f1 = this .int_field + 1;
57: this .f2 = this .int_field + 2;
58: this .f3 = this .int_field + 3;
59: this .f4 = this .int_field + 4;
60: this .f5 = this .int_field + 5;
61: }
62:
63: public void check(long longval) {
64: Assert.assertEquals("bad int_field value", int_field,
65: (int) longval);
66: Assert.assertEquals("bad f1 value", int_field,
67: (int) longval + 1);
68: Assert.assertEquals("bad f2 value", int_field,
69: (int) longval + 2);
70: Assert.assertEquals("bad f3 value", int_field,
71: (int) longval + 3);
72: Assert.assertEquals("bad f4 value", int_field,
73: (int) longval + 4);
74: Assert.assertEquals("bad f5 value", int_field,
75: (int) longval + 5);
76: }
77:
78: public int retrieve_int_field() {
79: return int_field;
80: }
81:
82: public void assign_int_field(int int_field) {
83: this .int_field = int_field;
84: this .f1 = this .int_field + 1;
85: this .f2 = this .int_field + 2;
86: this .f3 = this .int_field + 3;
87: this .f4 = this .int_field + 4;
88: this .f5 = this .int_field + 5;
89: }
90: }
|