KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > sequencing > NativeSequence


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2005, Oracle. All rights reserved.
22
package oracle.toplink.essentials.sequencing;
23
24 import oracle.toplink.essentials.queryframework.*;
25 import oracle.toplink.essentials.internal.databaseaccess.DatabasePlatform;
26 import oracle.toplink.essentials.internal.helper.Helper;
27 import oracle.toplink.essentials.exceptions.ValidationException;
28
29 /**
30  * <p>
31  * <b>Purpose</b>:
32  * <p>
33  */

34 public class NativeSequence extends QuerySequence {
35     public NativeSequence() {
36         super();
37         setShouldSkipUpdate(true);
38     }
39
40     public NativeSequence(String JavaDoc name) {
41         super(name);
42         setShouldSkipUpdate(true);
43     }
44
45     public NativeSequence(String JavaDoc name, int size) {
46         super(name, size);
47         setShouldSkipUpdate(true);
48     }
49
50     public NativeSequence(String JavaDoc name, int size, int initialValue) {
51         super(name, size, initialValue);
52         setShouldSkipUpdate(true);
53     }
54
55     public boolean equals(Object JavaDoc obj) {
56         if (obj instanceof NativeSequence) {
57             return equalNameAndSize(this, (NativeSequence)obj);
58         } else {
59             return false;
60         }
61     }
62
63     /**
64     * INTERNAL:
65     */

66     protected ValueReadQuery buildSelectQuery() {
67         return ((DatabasePlatform)getDatasourcePlatform()).buildSelectQueryForNativeSequence();
68     }
69
70     /**
71     * INTERNAL:
72     */

73     protected ValueReadQuery buildSelectQuery(String JavaDoc seqName, Integer JavaDoc size) {
74         return ((DatabasePlatform)getDatasourcePlatform()).buildSelectQueryForNativeSequence(seqName, size);
75     }
76
77     /**
78     * INTERNAL:
79     */

80     public void onConnect() {
81         DatabasePlatform dbPlatform = null;
82         try {
83             dbPlatform = (DatabasePlatform)getDatasourcePlatform();
84         } catch (ClassCastException JavaDoc ex) {
85             if (getSelectQuery() == null) {
86                 throw ValidationException.platformDoesNotSupportSequence(getName(), Helper.getShortClassName(getDatasourcePlatform()), Helper.getShortClassName(this));
87             }
88         }
89         if (!dbPlatform.supportsNativeSequenceNumbers() && (getSelectQuery() == null)) {
90             throw ValidationException.platformDoesNotSupportSequence(getName(), Helper.getShortClassName(getDatasourcePlatform()), Helper.getShortClassName(this));
91         }
92         super.onConnect();
93         if (dbPlatform != null) {
94             setShouldAcquireValueAfterInsert(dbPlatform.shouldNativeSequenceAcquireValueAfterInsert());
95             setShouldUseTransaction(dbPlatform.shouldNativeSequenceUseTransaction());
96         }
97     }
98
99     /**
100     * INTERNAL:
101     */

102     public void onDisconnect() {
103         setShouldAcquireValueAfterInsert(false);
104         setShouldUseTransaction(false);
105         super.onDisconnect();
106     }
107 }
108
Popular Tags