2121
2222import org .apache .cayenne .CayenneRuntimeException ;
2323import org .apache .cayenne .access .DataNode ;
24- import org .apache .cayenne .dba .QuotingStrategy ;
2524import org .apache .cayenne .dba .JdbcAdapter ;
2625import org .apache .cayenne .dba .JdbcPkGenerator ;
2726import org .apache .cayenne .map .DbEntity ;
@@ -54,6 +53,7 @@ public class OraclePkGenerator extends JdbcPkGenerator {
5453
5554 /**
5655 * Used by DI
56+ *
5757 * @since 4.1
5858 */
5959 public OraclePkGenerator () {
@@ -99,17 +99,7 @@ public void dropAutoPk(DataNode node, List<DbEntity> dbEntities) {
9999
100100 // drop obsolete sequences
101101 for (DbEntity dbEntity : dbEntities ) {
102- String name ;
103- if (dbEntity .getDataMap () != null && dbEntity .getDataMap ().isQuotingSQLIdentifiers ()) {
104- // the comparison name must be unquoted; render the bare sequence name without
105- // catalog/schema, matching the legacy behavior
106- StringBuilder buf = new StringBuilder ();
107- QuotingStrategy .NONE .appendFQN (buf , getSequencePrefix () + dbEntity .getName ().toLowerCase ());
108- name = stripSchemaName (buf .toString ());
109- } else {
110- name = stripSchemaName (sequenceName (dbEntity , QuotingStrategy .NONE ));
111- }
112- if (sequences .contains (name )) {
102+ if (sequences .contains (sequenceName (dbEntity ))) {
113103 runUpdate (node , dropSequenceString (dbEntity ));
114104 }
115105 }
@@ -129,15 +119,17 @@ public List<String> dropAutoPkStatements(List<DbEntity> dbEntities) {
129119 }
130120
131121 protected String createSequenceString (DbEntity ent ) {
132- return "CREATE SEQUENCE " + sequenceName (ent ) + " START WITH " + pkStartValue + " INCREMENT BY " + pkCacheSize (ent );
122+ String seqFQN = adapter .getQuotingStrategy (ent ).quotedFQN (ent .getCatalog (), ent .getSchema (), sequenceName (ent ));
123+ return "CREATE SEQUENCE " + seqFQN + " START WITH " + pkStartValue + " INCREMENT BY " + pkCacheSize (ent );
133124 }
134125
135126 /**
136127 * Returns a SQL string needed to drop any database objects associated with
137128 * automatic primary key generation process for a specific DbEntity.
138129 */
139130 protected String dropSequenceString (DbEntity ent ) {
140- return "DROP SEQUENCE " + sequenceName (ent );
131+ String seqFQN = adapter .getQuotingStrategy (ent ).quotedFQN (ent .getCatalog (), ent .getSchema (), sequenceName (ent ));
132+ return "DROP SEQUENCE " + seqFQN ;
141133 }
142134
143135 protected String selectNextValQuery (String pkGeneratingSequenceName ) {
@@ -167,7 +159,8 @@ protected long longPkFromDatabase(DataNode node, DbEntity entity) {
167159 && pkGenerator .getGeneratorName () != null ) {
168160 pkGeneratingSequenceName = pkGenerator .getGeneratorName ();
169161 } else {
170- pkGeneratingSequenceName = sequenceName (entity );
162+ pkGeneratingSequenceName = adapter .getQuotingStrategy (entity ).quotedFQN (entity .getCatalog (),
163+ entity .getSchema (), sequenceName (entity ));
171164 }
172165
173166 try (Connection con = node .getDataSource ().getConnection ()) {
@@ -200,41 +193,24 @@ protected int pkCacheSize(DbEntity entity) {
200193 }
201194 }
202195
203- /**
204- * Returns expected primary key sequence name for a DbEntity.
205- */
206196 protected String sequenceName (DbEntity entity ) {
207- return sequenceName (entity , adapter .getQuotingStrategy (entity ));
208- }
209-
210- /**
211- * Renders the sequence name for the entity using the provided quoting style.
212- */
213- private String sequenceName (DbEntity entity , QuotingStrategy quotes ) {
214197
215198 // use custom generator if possible
216199 DbKeyGenerator keyGenerator = entity .getPrimaryKeyGenerator ();
217- if (keyGenerator != null && DbKeyGenerator .ORACLE_TYPE .equals (keyGenerator .getGeneratorType ())
200+ if (keyGenerator != null
201+ && DbKeyGenerator .ORACLE_TYPE .equals (keyGenerator .getGeneratorType ())
218202 && keyGenerator .getGeneratorName () != null ) {
219203
220204 return keyGenerator .getGeneratorName ().toLowerCase ();
221205 } else {
222- String seqName = getSequencePrefix () + entity .getName ().toLowerCase ();
223- StringBuilder buf = new StringBuilder ();
224- quotes .appendFQN (buf , entity .getCatalog (), entity .getSchema (), seqName );
225- return buf .toString ();
206+ return getSequencePrefix () + entity .getName ().toLowerCase ();
226207 }
227208 }
228209
229210 protected String getSequencePrefix () {
230211 return _SEQUENCE_PREFIX ;
231212 }
232213
233- private String stripSchemaName (String sequenceName ) {
234- int ind = sequenceName .indexOf ('.' );
235- return ind >= 0 ? sequenceName .substring (ind + 1 ) : sequenceName ;
236- }
237-
238214 /**
239215 * Fetches a list of existing sequences that might match Cayenne generated
240216 * ones.
0 commit comments