2626import org .apache .cayenne .dbsync .merge .token .db .DropColumnToDb ;
2727import org .apache .cayenne .dbsync .merge .token .db .SetAllowNullToDb ;
2828import org .apache .cayenne .dbsync .merge .token .db .SetNotNullToDb ;
29+ import org .apache .cayenne .map .DataMap ;
2930import org .apache .cayenne .map .DbAttribute ;
3031import org .apache .cayenne .map .DbEntity ;
3132
@@ -38,9 +39,16 @@ public class FirebirdMergerTokenFactory extends DefaultMergerTokenFactory {
3839 public MergerToken createDropColumnToDb (DbEntity entity , DbAttribute column ) {
3940 return new DropColumnToDb (entity , column ) {
4041 public List <String > createSql (DbAdapter adapter ) {
41- QuotingStrategy quoting = adapter .getQuotingStrategy ();
42- return Collections .singletonList ("ALTER TABLE " + quoting .quotedFullyQualifiedName (getEntity ())
43- + " DROP " + quoting .quotedName (getColumn ()));
42+ DataMap dataMap = getEntity ().getDataMap ();
43+ QuotingStrategy quotes = dataMap != null && dataMap .isQuotingSQLIdentifiers ()
44+ ? adapter .getQuotingStrategy () : QuotingStrategy .NONE ;
45+ StringBuilder sql = new StringBuilder ("ALTER TABLE " );
46+ quotes .appendFQN (sql , getEntity ().getCatalog (), getEntity ().getSchema (), getEntity ().getName ());
47+ sql .append (" DROP " );
48+ quotes .appendStart (sql );
49+ sql .append (getColumn ().getName ());
50+ quotes .appendEnd (sql );
51+ return Collections .singletonList (sql .toString ());
4452 }
4553 };
4654 }
@@ -49,12 +57,15 @@ public List<String> createSql(DbAdapter adapter) {
4957 public MergerToken createSetNotNullToDb (DbEntity entity , DbAttribute column ) {
5058 return new SetNotNullToDb (entity , column ) {
5159 public List <String > createSql (DbAdapter adapter ) {
52- QuotingStrategy context = adapter .getQuotingStrategy ();
53- String entityName = context .quotedFullyQualifiedName (getEntity ()) ;
54- String columnName = context .quotedName (getColumn ());
60+ DataMap dataMap = getEntity ().getDataMap ();
61+ QuotingStrategy quotes = dataMap != null && dataMap .isQuotingSQLIdentifiers ()
62+ ? adapter .getQuotingStrategy () : QuotingStrategy .NONE ;
63+ String entityName = quotes .quotedFQN (getEntity ().getCatalog (), getEntity ().getSchema (),
64+ getEntity ().getName ());
65+ String columnName = quotes .quoted (getColumn ().getName ());
5566 // Firebird doesn't support ALTER TABLE table_name ALTER column_name SET NOT NULL
56- // but this might be achived by modyfication of system tables
57- return Collections .singletonList (String .format ("UPDATE RDB$RELATION_FIELDS SET RDB$NULL_FLAG = 1 " +
67+ // but this might be achived by modyfication of system tables
68+ return Collections .singletonList (String .format ("UPDATE RDB$RELATION_FIELDS SET RDB$NULL_FLAG = 1 " +
5869 "WHERE RDB$FIELD_NAME = '%s' AND RDB$RELATION_NAME = '%s'" , columnName , entityName ));
5970 }
6071 };
@@ -64,11 +75,14 @@ public List<String> createSql(DbAdapter adapter) {
6475 public MergerToken createSetAllowNullToDb (DbEntity entity , DbAttribute column ) {
6576 return new SetAllowNullToDb (entity , column ) {
6677 public List <String > createSql (DbAdapter adapter ) {
67- QuotingStrategy context = adapter .getQuotingStrategy ();
68- String entityName = context .quotedFullyQualifiedName (getEntity ()) ;
69- String columnName = context .quotedName (getColumn ());
78+ DataMap dataMap = getEntity ().getDataMap ();
79+ QuotingStrategy quotes = dataMap != null && dataMap .isQuotingSQLIdentifiers ()
80+ ? adapter .getQuotingStrategy () : QuotingStrategy .NONE ;
81+ String entityName = quotes .quotedFQN (getEntity ().getCatalog (), getEntity ().getSchema (),
82+ getEntity ().getName ());
83+ String columnName = quotes .quoted (getColumn ().getName ());
7084 // Firebird doesn't support ALTER TABLE table_name ALTER column_name DROP NOT NULL
71- // but this might be achived by modyfication system tables
85+ // but this might be achived by modyfication system tables
7286 return Collections .singletonList (String .format ("UPDATE RDB$RELATION_FIELDS SET RDB$NULL_FLAG = NULL " +
7387 " WHERE RDB$FIELD_NAME = '%s' AND RDB$RELATION_NAME = '%s'" , columnName , entityName ));
7488 }
@@ -78,11 +92,13 @@ public List<String> createSql(DbAdapter adapter) {
7892 @ Override
7993 public MergerToken createAddColumnToDb (DbEntity entity , DbAttribute column ) {
8094 return new AddColumnToDb (entity , column ) {
81- protected void appendPrefix (StringBuffer sqlBuffer , QuotingStrategy context ) {
95+ protected void appendPrefix (StringBuffer sqlBuffer , QuotingStrategy quotes ) {
8296 sqlBuffer .append ("ALTER TABLE " );
83- sqlBuffer . append ( context . quotedFullyQualifiedName ( getEntity ()));
97+ quotes . appendFQN ( sqlBuffer , getEntity (). getCatalog (), getEntity (). getSchema (), getEntity (). getName ( ));
8498 sqlBuffer .append (" ADD " );
85- sqlBuffer .append (context .quotedName (getColumn ()));
99+ quotes .appendStart (sqlBuffer );
100+ sqlBuffer .append (getColumn ().getName ());
101+ quotes .appendEnd (sqlBuffer );
86102 sqlBuffer .append (" " );
87103 }
88104 };
0 commit comments