Package webapp

Source Code of webapp.AppUtils

/**
* Copyright (C) 2006 - present dabuTech Corporation
* All Rights Reserved.
*
* This file is part of Easier Java Websites.
*
* EJW is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the accompanying license
* for more details.
*
* You should have received a copy of the license along with EJW; if not,
* go to http://www.EasierJava.com and download the latest version.
*/

package webapp;

import javax.servlet.ServletConfig;
import ejp.DatabaseManager;
import ejp.DatabaseException;
import ejw.InitDestroyHandler;
import ejw.ServerInterface;

/**
* InitDestroyHandler is typically (and optionally) extended to provide servlet
* initialization and destruction functionality.
*/
public class AppUtils extends InitDestroyHandler
  {
    /**
     * Called during servlet initialization.
     */
    public void init(ServletConfig config) throws DatabaseException
      {
        /*
         * The following is a normal (and typical) JNDI definition for a website database
         */
        // DatabaseManager dbm = DatabaseManager.getJndiDefinedDatabaseManager("contacts", 15,
        //                                                                     "jdbc/contacts", null, null);

        // HSQL in memory database (for example only)
        DatabaseManager dbm = DatabaseManager.getDatabaseManager("contacts", 5,
                                                                 "org.hsqldb.jdbcDriver",
                                                                 "jdbc:hsqldb:mem:contacts",
                                                                 "sa", "");
       
        dbm.executeUpdate("CREATE MEMORY TABLE simple_storage (" +
                          "account varchar(40) NOT NULL," +
                          "container varchar(40) NOT NULL," +
                          "object varchar(40) NOT NULL," +
                          "data longvarbinary NOT NULL," +
                          "PRIMARY KEY (account, container, object))");

        config.getServletContext().setAttribute("databaseManager", dbm);
        config.getServletContext().setAttribute("simpleStorageManager", new SimpleStorageManager(dbm));
      }

    public static DatabaseManager getDatabaseManager(ServerInterface serverInterface)
      {
        return (DatabaseManager)serverInterface.getServletContext().getAttribute("databaseManager");
      }

    public static SimpleStorageManager getSimpleStorageManager(ServerInterface serverInterface)
      {
        return (SimpleStorageManager)serverInterface.getServletContext().getAttribute("simpleStorageManager");
      }
  }
TOP

Related Classes of webapp.AppUtils

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.