Package org.syrup.jndi

Source Code of org.syrup.jndi.MySQLDeployment

package org.syrup.jndi;

import org.syrup.sql.SQLImpl;
import org.syrup.sql.SQLWorkSpace;
import org.syrup.sql.mysql.MySQLImpl;

import javax.naming.Context;
import javax.naming.InitialContext;

/**
* Deploys a SQL implementation of Syrup.
*
* @author Robbert van Dalen
*/
public class MySQLDeployment
{
    static final String COPYRIGHT = "Copyright 2005 Robbert van Dalen."
        + "At your option, you may copy, distribute, or make derivative works under "
        + "the terms of The Artistic License. This License may be found at "
        + "http://www.opensource.org/licenses/artistic-license.php. "
        + "THERE IS NO WARRANTY; USE THIS PRODUCT AT YOUR OWN RISK.";

    /**
     * The MySQL deployment function.
     *
     * @param args
     *            The command line arguments
     */
    public static void main(String[] args) throws Throwable
    {
        String url = "jdbc:mysql://localhost/test";
        String password = null;
        String user = null;

        // If the first arg is specified than this will be the connection
        // specification
        if (args.length > 0)
        {
            url = args[0];
        }
        if (args.length > 1)
        {
            user = args[1];
        }
        if (args.length > 2)
        {
            password = args[2];
        }

        Context ctx = new InitialContext();

        SQLWorkSpace sp = new SQLWorkSpace();
        ctx.rebind("syrupWorkSpace", sp);

        com.mysql.jdbc.jdbc2.optional.MysqlDataSource ds = new com.mysql.jdbc.jdbc2.optional.MysqlDataSource();
        ds.setURL(url);

        if (user != null)
        {
            ds.setUser(user);
        }
        if (password != null)
        {
            ds.setPassword(password);
        }
        ctx.rebind("syrupDataSource", ds);

        SQLImpl impl = new MySQLImpl();
        ctx.rebind("syrupSQLImpl", impl);
    }
}
TOP

Related Classes of org.syrup.jndi.MySQLDeployment

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.