home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 October / Chip_1997-10_cd.bin / tema / sybase / powerj / template.z / DBConnection.java < prev    next >
Text File  |  1996-12-09  |  4KB  |  121 lines

  1. /*
  2.  * DBConnection.java
  3.  *
  4.  *
  5.  * Copyright 1996 Sybase, Inc. All rights reserved.
  6.  */
  7.  
  8. /**
  9.  * <P>The DBConnection class provides an interface to the Dynamo connection
  10.  * object, for a single request from the NetImpact Dynamo web server.
  11.  * This allows access to the current connection for the current document.
  12.  * The current document corresponds to the template that originated this request
  13.  *
  14.  * <P>Lifetime: created from DynamoException.getDBConnection()
  15.  * Note that a public variable called connection will be predefined for
  16.  * each Java servlet, in the runtime startup.
  17.  * When the Java servlet is done, the connection object become garbage
  18.  */
  19.  
  20. public class DBConnection extends DynamoConnection 
  21. //************************************************
  22. {
  23.     //-------------------------------------------------------------
  24.     // Constructor
  25.     //-------------------------------------------------------------
  26.     
  27.     /**
  28.      * Constructs a new DBConnection object with the specified handle
  29.      * @param handle handle to Dynamo client
  30.      */
  31.      
  32.     public DBConnection(int handle) 
  33.     //*****************************
  34.     {
  35.         super(handle);
  36.     }
  37.     
  38.     //-------------------------------------------------------------
  39.     // Properties
  40.     //-------------------------------------------------------------
  41.  
  42.     /**
  43.      * Returns the name of this DBConnection object
  44.      * @exception DynamoException If an error has occured 
  45.      */
  46.      
  47.     public String getName() throws DynamoException 
  48.     //********************************************
  49.     {
  50.     return getStringProperty(CONNECTION, "name");
  51.     }
  52.         
  53.     /**
  54.      * Returns the description of this DBConnection object
  55.      * @exception DynamoException If an error has occured 
  56.      */
  57.      
  58.     public String getDescription() throws DynamoException
  59.     //***************************************************
  60.     {
  61.     return getStringProperty(CONNECTION, "description");
  62.     }
  63.         
  64.     /**
  65.      * Returns the data source of this DBConnection object
  66.      * @exception DynamoException If an error has occured 
  67.      */
  68.      
  69.     public String getDataSource() throws DynamoException 
  70.     //**************************************************
  71.     {
  72.     return getStringProperty(CONNECTION, "dataSource");
  73.     }    
  74.     
  75.     /**
  76.      * Returns the user id of this DBConnection object
  77.      * @exception DynamoException If an error has occured 
  78.      */
  79.      
  80.     public String getUserid() throws DynamoException
  81.     //**********************************************
  82.     {
  83.     return getStringProperty(CONNECTION, "userid");
  84.     }
  85.     
  86.         
  87.     //-------------------------------------------------------------
  88.     // Public Methods
  89.     //-------------------------------------------------------------
  90.     
  91.     /** 
  92.      * Creates a new query object with the specified SQL statement
  93.      * @param sqlStatement new SQL statement
  94.      * @exception DynamoException If an error has occured 
  95.      */
  96.      
  97.     public Query createQuery(String sqlStatement) throws DynamoException
  98.     //*****************************************************************
  99.     {
  100.         Query q = new Query( getHandle(), "__anonymous__", _count++ );
  101.         createQuery(q, sqlStatement);
  102.         return q;
  103.     }
  104.     
  105.     
  106.     //-------------------------------------------------------------
  107.     // Private Methods
  108.     //-------------------------------------------------------------
  109.  
  110.     private native void createQuery(Query q, String sqlstmt)
  111.         throws DynamoException;
  112.  
  113.  
  114.     //-------------------------------------------------------------
  115.     // Data
  116.     //-------------------------------------------------------------
  117.  
  118.     private static int _count;
  119. };
  120.  
  121.