package examples.t3client; import weblogic.common.*; import weblogic.remote.common.*; import weblogic.workspace.common.*; import java.util.*; import java.io.*; import java.sql.*; /** * The StartupQuery example illustrates three different facets of the * WebLogic Server architecture: * *

* This example requres an Oracle database instance. You'll need to * register this class as a startup class in your weblogic.properties * file, as detailed in the description of the startup() * method. * * @author Copyright (c)1996-98 by WebLogic, Inc. All Rights Reserved. * @author Copyright (c) 1999 by BEA WebXpress. All Rights Reserved. */ public class StartupQuery implements T3ServletDef, T3StartupDef { /** * The startup() method is called at WebLogic startup, * as a result of placing the following lines in the * weblogic.properties file: *

weblogic.system.startupClass.doquery=examples.t3client.StartupQuery
   *    weblogic.system.startupArgs.doquery=\
   *    query=select * from emp,\
   *    db=jdbc:weblogic:pool:demoPool
*

* where "db" is the URL of your database pool that * contains a table that you include in the arg "query". *

* When startup is invoked as a result of these two lines, the * "name" argument will be "doquery" (from the left-hand of the * property), and the args hashtable will contain the name-value * pair "query", "select * from emp". */ public String startup(String name, Hashtable args) throws Exception { // Grab startup arguments String query = (String)args.get("query"); String db = (String)args.get("db"); Class.forName("weblogic.jdbc.pool.Driver").newInstance(); Connection conn = DriverManager.getConnection(db); weblogic.db.jdbc.QueryDataSet qds = new weblogic.db.jdbc.QueryDataSet(conn, query); qds.fetchRecords(); ParamSet ps = new ParamSet(); ps.setParam("name", name); ps.setParam("query", query); ps.setParam("dataset", qds); services.workspace().store(name, ps, WorkspaceDef.SCOPE_SERVER); qds.close(); conn.close(); return name + " started"; } private T3ServicesDef services; /** * This method implements the WebLogic T3Servlet interface. *

* The setServices() method is called to pass to the * T3Servlet the handle of an object that can be used to access WebLogic * services. This makes another reference to the services object so * it can be used later. * * @param services Services stub */ public void setServices(T3ServicesDef services) { this.services = services; } /** * This method implements the WebLogic T3Servlet interface. *

* The declareParams() method is called to specify the * parameters that this T3Servlet will accept. WebLogic * calls this method when the server-side object is * instantiated. * * @param ps ParamSet * @exception weblogic.common.ParamSetException * if there is an error in the ParamSet */ public void declareParams(ParamSet ps) throws ParamSetException { ps.declareParam("name", ParamTypes.STRING); ps.declareParam("dataset", ParamTypes.OBJECT); } /** * This method implements the WebLogic T3Servlet interface. *

* The execute() method is called when the client * requests the invocation of this servlet. the ParamSet * contains the arguments for the execute() method. * * @param ps ParamSet * @exception java.lang.Exception * if there is an error in execution */ public void execute(ParamSet ps) throws Exception { String name = ps.getParam("name").asString(); // Fetch the object out of the server scoped workspace ParamSet wsps = (ParamSet) services.workspace().fetch(name, WorkspaceDef.SCOPE_SERVER); // This takes the corresponding items out of wsps and // puts them into ps. ps.setParams(wsps); } }