001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.tools;
022:
023: import com.liferay.portal.kernel.util.StringUtil;
024: import com.liferay.portal.tools.sql.DBUtil;
025: import com.liferay.util.FileUtil;
026:
027: import java.io.IOException;
028:
029: /**
030: * <a href="DBBuilder.java.html"><b><i>View Source</i></b></a>
031: *
032: * @author Brian Wing Shun Chan
033: * @author Charles May
034: * @author Alexander Chow
035: *
036: */
037: public class DBBuilder {
038:
039: public static void main(String[] args) {
040: if (args.length == 1) {
041: new DBBuilder(args[0], DBUtil.DB_TYPE_ALL);
042: } else if (args.length == 2) {
043: new DBBuilder(args[0], StringUtil.split(args[1]));
044: } else {
045: throw new IllegalArgumentException();
046: }
047: }
048:
049: public DBBuilder(String databaseName, String[] databaseTypes) {
050: try {
051: _databaseName = databaseName;
052: _databaseTypes = databaseTypes;
053:
054: _buildSQLFile("portal");
055: _buildSQLFile("portal-minimal");
056: _buildSQLFile("indexes");
057: _buildSQLFile("sequences");
058: _buildSQLFile("update-4.2.0-4.3.0");
059: _buildSQLFile("update-4.3.0-4.3.1");
060: _buildSQLFile("update-4.3.1-4.3.2");
061: _buildSQLFile("update-4.3.2-4.3.3");
062: _buildSQLFile("update-4.3.3-4.3.4");
063: _buildSQLFile("update-4.3.6-4.4.0");
064:
065: _buildCreateFile();
066: } catch (Exception e) {
067: e.printStackTrace();
068: }
069: }
070:
071: private void _buildCreateFile() throws IOException {
072: for (int i = 0; i < _databaseTypes.length; i++) {
073: String databaseType = _databaseTypes[i];
074:
075: if (databaseType.equals(DBUtil.DB_TYPE_HYPERSONIC)
076: || databaseType.equals(DBUtil.DB_TYPE_INTERBASE)
077: || databaseType.equals(DBUtil.DB_TYPE_JDATASTORE)
078: || databaseType.equals(DBUtil.DB_TYPE_SAP)) {
079:
080: continue;
081: }
082:
083: DBUtil dbUtil = _getDBUtil(_databaseTypes[i]);
084:
085: if (dbUtil != null) {
086: dbUtil.buildCreateFile(_databaseName);
087: }
088: }
089: }
090:
091: private void _buildSQLFile(String fileName) throws IOException {
092: if (!FileUtil.exists("../sql/" + fileName + ".sql")) {
093: return;
094: }
095:
096: for (int i = 0; i < _databaseTypes.length; i++) {
097: DBUtil dbUtil = _getDBUtil(_databaseTypes[i]);
098:
099: if (dbUtil != null) {
100: dbUtil.buildSQLFile(fileName);
101: }
102: }
103: }
104:
105: private DBUtil _getDBUtil(String dbType) {
106: return DBUtil.getInstance(dbType);
107: }
108:
109: private String _databaseName;
110:
111: private String[] _databaseTypes;
112:
113: }
|