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.kernel.dao.jdbc.DataAccess;
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.Properties;
025    
026    /**
027     * @author Tina Tian
028     * @author Shuyang Zhou
029     */
030    public class TestSampleSQLBuilder {
031    
032            public static void main(String[] args) {
033                    try {
034                            SampleSQLBuilder sampleSQLBuilder = new SampleSQLBuilder(args);
035    
036                            Properties properties = sampleSQLBuilder.getProperties(args);
037    
038                            String sqlDir = properties.getProperty("sql.dir");
039                            String outputDir = properties.getProperty("sample.sql.output.dir");
040    
041                            loadHypersonic(sqlDir, outputDir);
042                    }
043                    catch (Exception e) {
044                            e.printStackTrace();
045                    }
046            }
047    
048            protected static void loadHypersonic(String sqlDir, String outputDir)
049                    throws Exception {
050    
051                    Class.forName("org.hsqldb.jdbcDriver");
052    
053                    Connection connection = null;
054                    Statement statement = null;
055    
056                    try {
057                            connection = DriverManager.getConnection(
058                                    "jdbc:hsqldb:mem:testSampleSQLBuilderDB;shutdown=true", "sa",
059                                    "");
060    
061                            DBLoader.loadHypersonic(
062                                    connection,
063                                    sqlDir + "/portal-minimal/portal-minimal-hypersonic.sql");
064                            DBLoader.loadHypersonic(
065                                    connection, sqlDir + "/indexes/indexes-hypersonic.sql");
066                            DBLoader.loadHypersonic(
067                                    connection, outputDir + "/sample-hypersonic.sql");
068    
069                            statement = connection.createStatement();
070    
071                            statement.execute("SHUTDOWN COMPACT");
072                    }
073                    finally {
074                            DataAccess.cleanUp(connection, statement);
075                    }
076            }
077    
078    }