View Javadoc

1   /*
2    * SymmetricDS is an open source database synchronization solution.
3    *   
4    * Copyright (C) Eric Long <erilong@users.sourceforge.net>
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 3 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, see
18   * <http://www.gnu.org/licenses/>.
19   */
20  
21  package org.jumpmind.symmetric.db.firebird;
22  
23  import org.apache.commons.logging.Log;
24  import org.apache.commons.logging.LogFactory;
25  import org.jumpmind.symmetric.db.AbstractDbDialect;
26  import org.jumpmind.symmetric.db.IDbDialect;
27  import org.jumpmind.symmetric.model.Trigger;
28  import org.jumpmind.symmetric.model.TriggerHistory;
29  
30  public class FirebirdDbDialect extends AbstractDbDialect implements IDbDialect {
31  
32      static final Log logger = LogFactory.getLog(FirebirdDbDialect.class);
33  
34      static final String TRANSACTION_ID_FUNCTION_NAME = "fn_transaction_id";
35  
36      static final String SYNC_TRIGGERS_DISABLED_USER_VARIABLE = "explain_pretty_print";
37  
38      protected void initForSpecificDialect() {
39          /*
40           * try { if (!isFunctionUpToDate(TRANSACTION_ID_FUNCTION_NAME)) {
41           * logger.info("Creating function " + TRANSACTION_ID_FUNCTION_NAME); new
42           * SqlScript(getTransactionIdSqlUrl(), getPlatform().getDataSource(),
43           * '/') .execute(); } } catch (Exception e) {
44           * 
45           * logger.error("Error while initializing PostgreSql.", e); }
46           */
47      }
48  
49      @Override
50      protected boolean doesTriggerExistOnPlatform(String catalogName, String schema, String tableName, String triggerName) {
51          return jdbcTemplate.queryForInt("select count(*) from rdb$triggers where rdb$trigger_name = ?",
52                  new Object[] { triggerName }) > 0;
53      }
54  
55      public void removeTrigger(String schemaName, String triggerName) {
56          throw new RuntimeException("Not implemented.  Use removeTrigger(schema, trigger, table) instead.");
57      }
58  
59      public void removeTrigger(String catalogName, String schemaName, String triggerName, String tableName, TriggerHistory oldHistory) {
60          schemaName = schemaName == null ? "" : (schemaName + ".");
61          try {
62              jdbcTemplate.update("drop trigger " + schemaName + triggerName);
63          } catch (Exception e) {
64              logger.warn("Trigger does not exist");
65          }
66      }
67  
68      public void disableSyncTriggers() {
69          // jdbcTemplate.update("set " + SYNC_TRIGGERS_DISABLED_USER_VARIABLE + "
70          // to off");
71      }
72  
73      public void disableSyncTriggers(String nodeId) {
74      }
75  
76      public void enableSyncTriggers() {
77          // jdbcTemplate.update("set " + SYNC_TRIGGERS_DISABLED_USER_VARIABLE + "
78          // to on");
79      }
80  
81      public String getSyncTriggersExpression() {
82          // return "current_setting('" + SYNC_TRIGGERS_DISABLED_USER_VARIABLE +
83          // "') = 'on'";
84          return "1 = 1";
85      }
86  
87      public String getTransactionTriggerExpression(Trigger trigger) {
88          return "null";
89      }
90  
91      public String getSelectLastInsertIdSql(String sequenceName) {
92          return "select gen_id(gen_" + sequenceName + ", 1) from rdb$database";
93      }
94  
95      public boolean isCharSpacePadded() {
96          return true;
97      }
98  
99      public boolean isCharSpaceTrimmed() {
100         return false;
101     }
102 
103     public boolean isEmptyStringNulled() {
104         return false;
105     }
106 
107     public boolean storesUpperCaseNamesInCatalog() {
108         return true;
109     }
110 
111     protected boolean allowsNullForIdentityColumn() {
112         return false;
113     }
114 
115     public void purge() {
116     }
117 
118     public String getName() {
119         return super.getName().substring(0, 49);
120     }
121 
122     public String getDefaultCatalog() {
123         return null;
124     }
125 
126     public String getDefaultSchema() {
127         return null;
128     }
129 
130 }