/**
* 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 ejw.InitDestroyHandler;
import ejw.ServerInterface;
import webapp.SimpleLogin.User;
public class AppUtils extends InitDestroyHandler
{
public void init(ServletConfig config)
{
try
{
// Normal JNDI definition for a website
//DatabaseManager dbm = DatabaseManager.getDatabaseManager("customers", 15, "jdbc/users");
// HSQL in memory database
DatabaseManager dbm = DatabaseManager.getDatabaseManager("users", 5, "org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:users", "sa", "");
dbm.executeUpdate("create memory table users(username varchar(30), password varchar(30), first_name varchar(40), last_name varchar(40), roles varchar(100))");
dbm.saveObject(new User("admin", "b8fOPfDKETezXTCgqbtF", "Admin", null, "admin, create, delete"));
dbm.saveObject(new User("jsmith", "njiaJzLtntWp6abHfRtU", "John", "Smith", "user"));
config.getServletContext().setAttribute("databaseManager", dbm);
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static DatabaseManager getDatabaseManager(ServerInterface serverInterface)
{
return (DatabaseManager)serverInterface.getServletContext().getAttribute("databaseManager");
}
}