KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jorm > facility > naming > rdbsequence > RdbSequencePName


1 /**
2  * JORM: an implementation of a generic mapping system for persistent Java
3  * objects. Two mapping are supported: to RDBMS and to binary files.
4  * Copyright (C) 2001-2003 France Telecom R&D - INRIA
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 of the License, or (at your option) 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 USA
19  *
20  * Contact: jorm-team@objectweb.org
21  *
22  */

23
24 package org.objectweb.jorm.facility.naming.rdbsequence;
25
26 import org.objectweb.jorm.naming.lib.BasicPName;
27 import org.objectweb.jorm.naming.lib.BasicPolymorphicPName;
28 import org.objectweb.jorm.naming.api.PNameManager;
29 import org.objectweb.jorm.naming.api.PExceptionNaming;
30 import org.objectweb.jorm.naming.api.PNameGetter;
31 import org.objectweb.jorm.api.PException;
32
33 import java.util.Date JavaDoc;
34 import java.math.BigDecimal JavaDoc;
35 import java.math.BigInteger JavaDoc;
36
37 /**
38  *
39  * @author S.Chassande-Barrioz
40  */

41 public class RdbSequencePName extends BasicPolymorphicPName implements PNameGetter {
42     public final static Long JavaDoc NULL_VALUE = null;
43     Long JavaDoc value = NULL_VALUE;
44
45     public RdbSequencePName(PNameManager pnm, long value) {
46         this.pnc = pnm;
47         this.value = new Long JavaDoc(value);
48     }
49     public RdbSequencePName(PNameManager pnm, Long JavaDoc value) {
50         this.pnc = pnm;
51         this.value = value;
52     }
53     public RdbSequencePName(PNameManager pnm, Object JavaDoc hints) throws PExceptionNaming {
54         this.pnc = pnm;
55         if (!(hints instanceof RdbSequencePName)) {
56             throw new PExceptionNaming("Unsupported operation: bad pname type,"
57                                        + " expected RdbSequencePName: " + hints);
58         }
59         value = ((RdbSequencePName) hints).value;
60     }
61
62     public String JavaDoc toString() {
63         return super.toString() + " / pncRef:" + pnc + " / value:" + value;
64     }
65
66     public boolean equals(Object JavaDoc obj) {
67         if (!(obj instanceof RdbSequencePName)) {
68             return false;
69         }
70         RdbSequencePName rpn = (RdbSequencePName) obj;
71         boolean testPnc = true;
72         //if one of the pname is polymorphic, compare the ptypes
73
if (this.isPolymorphic() || rpn.isPolymorphic()) {
74             testPnc = (this.getPType().isa(rpn.getPType()) || rpn.getPType().isa(this.getPType()));
75         //if none of the pname is polymorphic, pnc must be compared
76
} else {
77             testPnc = (pnc == rpn.pnc);
78         }
79         return testPnc
80             && (value == null ? rpn.value == null : value.equals(rpn.value));
81     }
82
83     public int hashCode() {
84         return (value == null ? -1 : value.intValue());
85     }
86
87     public boolean isNull() {
88         return value == NULL_VALUE || (value != null && value.longValue() < 0);
89     }
90
91     public byte pngetByteField(String JavaDoc fn, Object JavaDoc ctxt) throws PException {
92         throw new PExceptionNaming("Bad type: expected long");
93     }
94
95     public Byte JavaDoc pngetObyteField(String JavaDoc fn, Object JavaDoc ctxt) throws PException {
96         throw new PExceptionNaming("Bad type: expected long");
97     }
98
99     public char pngetCharField(String JavaDoc fn, Object JavaDoc ctxt) throws PException {
100         throw new PExceptionNaming("Bad type: expected long");
101     }
102
103     public Character JavaDoc pngetOcharField(String JavaDoc fn, Object JavaDoc ctxt) throws PException {
104         throw new PExceptionNaming("Bad type: expected long");
105     }
106
107     public short pngetShortField(String JavaDoc fn, Object JavaDoc ctxt) throws PException {
108         throw new PExceptionNaming("Bad type: expected long");
109     }
110
111     public Short JavaDoc pngetOshortField(String JavaDoc fn, Object JavaDoc ctxt) throws PException {
112         throw new PExceptionNaming("Bad type: expected long");
113     }
114
115     public int pngetIntField(String JavaDoc fn, Object JavaDoc ctxt) throws PException {
116         throw new PExceptionNaming("Bad type: expected long");
117     }
118
119     public Integer JavaDoc pngetOintField(String JavaDoc fn, Object JavaDoc ctxt) throws PException {
120         throw new PExceptionNaming("Bad type: expected long");
121     }
122
123     public long pngetLongField(String JavaDoc fn, Object JavaDoc ctxt) throws PException {
124         return value == null ? -1 : value.longValue();
125     }
126
127     public Long JavaDoc pngetOlongField(String JavaDoc fn, Object JavaDoc ctxt) throws PException {
128         return value;
129     }
130
131     public String JavaDoc pngetStringField(String JavaDoc fn, Object JavaDoc ctxt) throws PException {
132         throw new PExceptionNaming("Bad type: expected long");
133     }
134
135     public byte[] pngetByteArrayField(String JavaDoc fn, Object JavaDoc ctxt) throws PException {
136         throw new PExceptionNaming("Bad type: expected long");
137     }
138
139     public char[] pngetCharArrayField(String JavaDoc fn, Object JavaDoc ctxt) throws PException {
140         throw new PExceptionNaming("Bad type: expected long");
141     }
142
143     public Date JavaDoc pngetDateField(String JavaDoc fn, Object JavaDoc ctxt) throws PException {
144         throw new PExceptionNaming("Bad type: expected long");
145     }
146
147     public BigDecimal JavaDoc pngetBigDecimalField(String JavaDoc fn, Object JavaDoc ctxt) throws PException {
148         throw new PExceptionNaming("Bad type: expected long");
149     }
150
151     public BigInteger JavaDoc pngetBigIntegerField(String JavaDoc fn, Object JavaDoc ctxt) throws PException {
152         throw new PExceptionNaming("Bad type: expected long");
153     }
154 }
155
Popular Tags