org.apache.derby.jdbc
Class EmbeddedDataSource40

java.lang.Object
  extended by org.apache.derby.jdbc.ReferenceableDataSource
      extended by org.apache.derby.jdbc.EmbeddedDataSource
          extended by org.apache.derby.jdbc.EmbeddedDataSource40
All Implemented Interfaces:
java.io.Serializable, java.sql.Wrapper, javax.naming.Referenceable, javax.naming.spi.ObjectFactory, javax.sql.CommonDataSource, javax.sql.DataSource

public class EmbeddedDataSource40
extends org.apache.derby.jdbc.EmbeddedDataSource

EmbeddedDataSource40 is Derby's DataSource implementation for JDBC4.0.

A DataSource is a factory for Connection objects. An object that implements the DataSource interface will typically be registered with a JNDI service provider.

EmbeddedDataSource40 supports the JDBC 4.0 specification for the J2SE 6.0 Java Virtual Machine environment. Use EmbeddedDataSource if your application is running in one of the following older environments:

The following is a list of properties that can be set on a Derby DataSource object:

Standard DataSource properties (from JDBC 3.0 specification).


Derby specific DataSource properties.

Examples.

This is an example of setting a property directly using Derby's EmbeddedDataSource40 object. This code is typically written by a system integrator :

 

 import org.apache.derby.jdbc.*;

 // dbname is the database name
 // if create is true, create the database if necessary
 javax.sql.DataSource makeDataSource (String dbname, boolean create)
        throws Throwable 
 { 
        EmbeddedDataSource40 ds = new EmbeddedDataSource40(); 
        ds.setDatabaseName(dbname);

        if (create)
                ds.setCreateDatabase("create");
   
        return ds;
 }
        

Example of setting properties thru reflection. This code is typically generated by tools or written by a system integrator:

        
 javax.sql.DataSource makeDataSource(String dbname) 
        throws Throwable 
 {
        Class[] parameter = new Class[1];
        parameter[0] = dbname.getClass();
        DataSource ds =  new EmbeddedDataSource40();
        Class cl = ds.getClass();

        Method setName = cl.getMethod("setDatabaseName", parameter);
        Object[] arg = new Object[1];
        arg[0] = dbname;
        setName.invoke(ds, arg);

        return ds;
 }
        

Example on how to register a data source object with a JNDI naming service.

 DataSource ds = makeDataSource("mydb");
 Context ctx = new InitialContext();
 ctx.bind("jdbc/MyDB", ds);
        

Example on how to retrieve a data source object from a JNDI naming service.

 Context ctx = new InitialContext();
 DataSource ds = (DataSource)ctx.lookup("jdbc/MyDB");
        

See Also:
Serialized Form

Constructor Summary
EmbeddedDataSource40()
           
 
Method Summary
 boolean isWrapperFor(java.lang.Class<?> interfaces)
          Returns false unless interfaces is implemented
<T> T
unwrap(java.lang.Class<T> interfaces)
          Returns this if this class implements the interface
 
Methods inherited from class org.apache.derby.jdbc.EmbeddedDataSource
equals, getAttributesAsPassword, getConnection, getConnection, getConnectionAttributes, getCreateDatabase, getShutdownDatabase, setAttributesAsPassword, setConnectionAttributes, setCreateDatabase, setShutdownDatabase
 
Methods inherited from class org.apache.derby.jdbc.ReferenceableDataSource
getDatabaseName, getDataSourceName, getDescription, getLoginTimeout, getLogWriter, getObjectInstance, getPassword, getReference, getUser, setDatabaseName, setDataSourceName, setDescription, setLoginTimeout, setLogWriter, setPassword, setUser
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.sql.CommonDataSource
getLoginTimeout, getLogWriter, setLoginTimeout, setLogWriter
 

Constructor Detail

EmbeddedDataSource40

public EmbeddedDataSource40()
Method Detail

isWrapperFor

public boolean isWrapperFor(java.lang.Class<?> interfaces)
                     throws java.sql.SQLException
Returns false unless interfaces is implemented

Parameters:
interfaces - a Class defining an interface.
Returns:
true if this implements the interface or directly or indirectly wraps an object that does.
Throws:
java.sql.SQLException - if an error occurs while determining whether this is a wrapper for an object with the given interface.

unwrap

public <T> T unwrap(java.lang.Class<T> interfaces)
         throws java.sql.SQLException
Returns this if this class implements the interface

Parameters:
interfaces - a Class defining an interface
Returns:
an object that implements the interface
Throws:
java.sql.SQLExption - if no object if found that implements the interface
java.sql.SQLException

Built on Wed 2007-08-01 06:53:39-0700, from revision 561794

Apache Derby 10.3 API Documentation - Copyright © 2004,2007 The Apache Software Foundation. All Rights Reserved.