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