001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.tools.samplesqlbuilder;
016    
017    import com.liferay.portal.tools.ArgumentsUtil;
018    import com.liferay.portal.tools.DBLoader;
019    
020    import java.sql.Connection;
021    import java.sql.DriverManager;
022    import java.sql.Statement;
023    
024    import java.util.Map;
025    
026    /**
027     * @author Tina Tian
028     * @author Shuyang Zhou
029     */
030    public class TestSampleSQLBuilder {
031    
032            public static void main(String[] args) throws Exception {
033                    Map<String, String> arguments = ArgumentsUtil.parseArguments(args);
034    
035                    String sqlDir = arguments.get("sql.dir");
036                    String outputDir = arguments.get("sample.sql.output.dir");
037    
038                    SampleSQLBuilder.main(args);
039    
040                    new TestSampleSQLBuilder(sqlDir, outputDir);
041            }
042    
043            public TestSampleSQLBuilder(String sqlDir, String outputDir)
044                    throws Exception {
045    
046                    _sqlDir = sqlDir;
047                    _outputDir = outputDir;
048    
049                    _loadHypersonic();
050            }
051    
052            private void _loadHypersonic() throws Exception {
053                    Class.forName("org.hsqldb.jdbcDriver");
054    
055                    Connection con = DriverManager.getConnection(
056                            "jdbc:hsqldb:mem:testSampleSQLBuilderDB;shutdown=true", "sa", "");
057    
058                    DBLoader.loadHypersonic(
059                            con, _sqlDir + "/portal-minimal/portal-minimal-hypersonic.sql");
060                    DBLoader.loadHypersonic(
061                            con, _sqlDir + "/indexes/indexes-hypersonic.sql");
062                    DBLoader.loadHypersonic(con, _outputDir + "/sample-hypersonic.sql");
063    
064                    Statement statement = con.createStatement();
065    
066                    statement.execute("SHUTDOWN COMPACT");
067    
068                    statement.close();
069    
070                    con.close();
071            }
072    
073            private String _outputDir;
074            private String _sqlDir;
075    
076    }