View Javadoc

1   /**
2      This file is part of GoldenGate Project (named also GoldenGate or GG).
3   
4      Copyright 2009, Frederic Bregier, and individual contributors by the @author
5      tags. See the COPYRIGHT.txt in the distribution for a full listing of
6      individual contributors.
7   
8      All GoldenGate Project is free software: you can redistribute it and/or 
9      modify it under the terms of the GNU General Public License as published 
10     by the Free Software Foundation, either version 3 of the License, or
11     (at your option) any later version.
12  
13     GoldenGate is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17  
18     You should have received a copy of the GNU General Public License
19     along with GoldenGate .  If not, see <http://www.gnu.org/licenses/>.
20   */
21  package goldengate.common.database.model;
22  
23  
24  import goldengate.common.database.DbAdmin;
25  import goldengate.common.database.exception.GoldenGateDatabaseNoConnectionException;
26  
27  /**
28   * Factory to store the Database Model object
29   *
30   * @author Frederic Bregier
31   *
32   */
33  public class DbModelFactory {
34  
35      /**
36       * Info on JDBC Class is already loaded or not
37       */
38      static public volatile boolean classLoaded = false;
39      /**
40       * Database Model Object
41       */
42      public static DbModel dbModel = null;
43      /**
44       * Initialize the Database Model according to arguments.
45       * @param dbdriver
46       * @param dbserver
47       * @param dbuser
48       * @param dbpasswd
49       * @param write
50       * @throws GoldenGateDatabaseNoConnectionException
51       */
52      public static DbAdmin initialize(String dbdriver, String dbserver,
53              String dbuser, String dbpasswd, boolean write)
54              throws GoldenGateDatabaseNoConnectionException {
55          DbType type = DbType.getFromDriver(dbdriver);
56          switch (type) {
57              case H2:
58                  //dbModel = new DbModelH2(dbserver, dbuser, dbpasswd);
59                  break;
60              case Oracle:
61                  //dbModel = new DbModelOracle(dbserver, dbuser, dbpasswd);
62                  break;
63              case PostGreSQL:
64                  //dbModel = new DbModelPostgresql();
65                  break;
66              case MySQL:
67                  //dbModel = new DbModelMysql(dbserver, dbuser, dbpasswd);
68                  break;
69              default:
70                  throw new GoldenGateDatabaseNoConnectionException(
71                          "TypeDriver unknown: " + type);
72          }
73          if (dbModel == null) {
74              throw new GoldenGateDatabaseNoConnectionException(
75                      "TypeDriver not allocated: " + type);            
76          }
77          return new DbAdmin(type, dbserver, dbuser, dbpasswd,
78                  write);
79      }
80  }