1 21 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 34 public class NativeSequence extends QuerySequence { 35 public NativeSequence() { 36 super(); 37 setShouldSkipUpdate(true); 38 } 39 40 public NativeSequence(String name) { 41 super(name); 42 setShouldSkipUpdate(true); 43 } 44 45 public NativeSequence(String name, int size) { 46 super(name, size); 47 setShouldSkipUpdate(true); 48 } 49 50 public NativeSequence(String name, int size, int initialValue) { 51 super(name, size, initialValue); 52 setShouldSkipUpdate(true); 53 } 54 55 public boolean equals(Object obj) { 56 if (obj instanceof NativeSequence) { 57 return equalNameAndSize(this, (NativeSequence)obj); 58 } else { 59 return false; 60 } 61 } 62 63 66 protected ValueReadQuery buildSelectQuery() { 67 return ((DatabasePlatform)getDatasourcePlatform()).buildSelectQueryForNativeSequence(); 68 } 69 70 73 protected ValueReadQuery buildSelectQuery(String seqName, Integer size) { 74 return ((DatabasePlatform)getDatasourcePlatform()).buildSelectQueryForNativeSequence(seqName, size); 75 } 76 77 80 public void onConnect() { 81 DatabasePlatform dbPlatform = null; 82 try { 83 dbPlatform = (DatabasePlatform)getDatasourcePlatform(); 84 } catch (ClassCastException 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 102 public void onDisconnect() { 103 setShouldAcquireValueAfterInsert(false); 104 setShouldUseTransaction(false); 105 super.onDisconnect(); 106 } 107 } 108 | Popular Tags |