1   /**
2    * Copyright (c) 2000-2007 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.tools;
24  
25  import com.liferay.portal.tools.sql.DBUtil;
26  import com.liferay.util.FileUtil;
27  
28  import java.io.IOException;
29  
30  /**
31   * <a href="DBBuilder.java.html"><b><i>View Source</i></b></a>
32   *
33   * @author Brian Wing Shun Chan
34   * @author Charles May
35   * @author Alexander Chow
36   *
37   */
38  public class DBBuilder {
39  
40      public static void main(String[] args) {
41          if (args.length == 1) {
42              new DBBuilder(args[0]);
43          }
44          else {
45              throw new IllegalArgumentException();
46          }
47      }
48  
49      public DBBuilder(String databaseName) {
50          try {
51              _databaseName = databaseName;
52  
53              _buildSQLFile("portal");
54              _buildSQLFile("portal-minimal");
55              _buildSQLFile("indexes");
56              _buildSQLFile("sequences");
57              _buildSQLFile("update-4.2.0-4.3.0");
58              _buildSQLFile("update-4.3.0-4.3.1");
59              _buildSQLFile("update-4.3.1-4.3.2");
60              _buildSQLFile("update-4.3.2-4.3.3");
61              _buildSQLFile("update-4.3.3-4.3.4");
62              _buildCreateFile();
63          }
64          catch (Exception e) {
65              e.printStackTrace();
66          }
67      }
68  
69      private void _buildCreateFile() throws IOException {
70          _getDBUtil(DBUtil.DB_TYPE_DB2).buildCreateFile(_databaseName);
71          _getDBUtil(DBUtil.DB_TYPE_DERBY).buildCreateFile(_databaseName);
72          _getDBUtil(DBUtil.DB_TYPE_FIREBIRD).buildCreateFile(_databaseName);
73          _getDBUtil(DBUtil.DB_TYPE_INFORMIX).buildCreateFile(_databaseName);
74          _getDBUtil(DBUtil.DB_TYPE_MYSQL).buildCreateFile(_databaseName);
75          _getDBUtil(DBUtil.DB_TYPE_ORACLE).buildCreateFile(_databaseName);
76          _getDBUtil(DBUtil.DB_TYPE_POSTGRESQL).buildCreateFile(_databaseName);
77          _getDBUtil(DBUtil.DB_TYPE_SQLSERVER).buildCreateFile(_databaseName);
78          _getDBUtil(DBUtil.DB_TYPE_SYBASE).buildCreateFile(_databaseName);
79      }
80  
81      private void _buildSQLFile(String fileName) throws IOException {
82          if (!FileUtil.exists("../sql/" + fileName + ".sql")) {
83              return;
84          }
85  
86          _getDBUtil(DBUtil.DB_TYPE_DB2).buildSQLFile(fileName);
87          _getDBUtil(DBUtil.DB_TYPE_DERBY).buildSQLFile(fileName);
88          _getDBUtil(DBUtil.DB_TYPE_FIREBIRD).buildSQLFile(fileName);
89          _getDBUtil(DBUtil.DB_TYPE_HYPERSONIC).buildSQLFile(fileName);
90          _getDBUtil(DBUtil.DB_TYPE_INFORMIX).buildSQLFile(fileName);
91          _getDBUtil(DBUtil.DB_TYPE_INTERBASE).buildSQLFile(fileName);
92          _getDBUtil(DBUtil.DB_TYPE_JDATASTORE).buildSQLFile(fileName);
93          _getDBUtil(DBUtil.DB_TYPE_MYSQL).buildSQLFile(fileName);
94          _getDBUtil(DBUtil.DB_TYPE_ORACLE).buildSQLFile(fileName);
95          _getDBUtil(DBUtil.DB_TYPE_POSTGRESQL).buildSQLFile(fileName);
96          _getDBUtil(DBUtil.DB_TYPE_SAP).buildSQLFile(fileName);
97          _getDBUtil(DBUtil.DB_TYPE_SQLSERVER).buildSQLFile(fileName);
98          _getDBUtil(DBUtil.DB_TYPE_SYBASE).buildSQLFile(fileName);
99      }
100 
101     private DBUtil _getDBUtil(int dbType) throws IOException {
102         return DBUtil.getInstance(dbType);
103     }
104 
105     private String _databaseName;
106 
107 }