[Idrs-commit] CVS: Idrs/dev/src/net/sourceforge/idrs/jndi JndiConnection.java,NONE,1.1 JdbcJndiDrive
Brought to you by:
bigman921
|
From: Marc B. <big...@us...> - 2003-03-17 14:05:05
|
Update of /cvsroot/idrs/Idrs/dev/src/net/sourceforge/idrs/jndi
In directory sc8-pr-cvs1:/tmp/cvs-serv25653/dev/src/net/sourceforge/idrs/jndi
Added Files:
JndiConnection.java JdbcJndiDriver.java
Log Message:
Added Initial EJB Support
--- NEW FILE: JndiConnection.java ---
/*
* JndiLdapConnection.java
*
* Created on March 10, 2002, 3:22 PM
*/
package net.sourceforge.idrs.jndi;
import java.sql.*;
import javax.naming.*;
import javax.naming.directory.*;
import javax.naming.ldap.*;
import java.util.*;
import net.sourceforge.idrs.exceptions.*;
/**
* Wraps a Jndi Connection to an EJB server
*@author Marc Boorshtein
*/
public class JndiConnection implements java.sql.Connection {
/** JNDI connection */
Context con;
/**Stores properties for initialization */
Hashtable env;
/**
*Returns the context used to connect
*/
public Context getContext() {
return this.con;
}
/**
*Initializes the Connection with a set of properties
*@param url URL of the server in the form ldap://server:port/base dn
*@param props Properties correspinding to Conneciton Constants
*/
public JndiConnection(String url, Properties props) throws SQLException {
props.put(Context.PROVIDER_URL,url);
try {
//System.out.println("gonna create");
this.con = new InitialContext(props);
//System.out.println("created");
}
catch (NamingException e) {
e.printStackTrace();
e.printStackTrace(System.out);
throw new SQLNamingException(e);
}
if (this.isClosed()) {
throw new SQLException("Connection Failed");
}
}
public void setTransactionIsolation(int param) throws java.sql.SQLException {
}
public boolean getAutoCommit() throws java.sql.SQLException {
return false;
}
public void close() throws java.sql.SQLException {
try {
con.close();
}
catch (NamingException e) {
throw new SQLNamingException(e);
}
}
public void commit() throws java.sql.SQLException {
}
public boolean isClosed() throws java.sql.SQLException {
return con == null;
}
public void setCatalog(java.lang.String str) throws java.sql.SQLException {
}
public java.sql.Savepoint setSavepoint() throws java.sql.SQLException {
return null;
}
public boolean isReadOnly() throws java.sql.SQLException {
return false;
}
public void setHoldability(int param) throws java.sql.SQLException {
}
public void rollback() throws java.sql.SQLException {
}
public java.lang.String getCatalog() throws java.sql.SQLException {
return null;
}
public java.sql.PreparedStatement prepareStatement(java.lang.String str, int param) throws java.sql.SQLException {
return null;
}
public java.sql.PreparedStatement prepareStatement(java.lang.String str, int param, int param2, int param3) throws java.sql.SQLException {
return null;
}
public java.sql.PreparedStatement prepareStatement(java.lang.String str, int param, int param2) throws java.sql.SQLException {
return null;
}
public void setAutoCommit(boolean param) throws java.sql.SQLException {
}
public java.sql.CallableStatement prepareCall(java.lang.String str) throws java.sql.SQLException {
return null;
}
public java.sql.PreparedStatement prepareStatement(java.lang.String str, int[] values) throws java.sql.SQLException {
return null;
}
public void setTypeMap(java.util.Map map) throws java.sql.SQLException {
}
public int getHoldability() throws java.sql.SQLException {
return -1;
}
public java.sql.Savepoint setSavepoint(java.lang.String str) throws java.sql.SQLException {
return null;
}
public java.sql.Statement createStatement(int param, int param1, int param2) throws java.sql.SQLException {
return null;
}
public java.sql.Statement createStatement(int param, int param1) throws java.sql.SQLException {
return null;
}
public java.sql.Statement createStatement() throws java.sql.SQLException {
return null;
}
public java.lang.String nativeSQL(java.lang.String str) throws java.sql.SQLException {
return null;
}
public java.sql.CallableStatement prepareCall(java.lang.String str, int param, int param2) throws java.sql.SQLException {
return null;
}
public java.sql.CallableStatement prepareCall(java.lang.String str, int param, int param2, int param3) throws java.sql.SQLException {
return null;
}
public java.sql.SQLWarning getWarnings() throws java.sql.SQLException {
return null;
}
public java.sql.PreparedStatement prepareStatement(java.lang.String str) throws java.sql.SQLException {
return null;
}
public void setReadOnly(boolean param) throws java.sql.SQLException {
}
public java.util.Map getTypeMap() throws java.sql.SQLException {
return null;
}
public void releaseSavepoint(java.sql.Savepoint savepoint) throws java.sql.SQLException {
}
public java.sql.PreparedStatement prepareStatement(java.lang.String str, java.lang.String[] str1) throws java.sql.SQLException {
return null;
}
public int getTransactionIsolation() throws java.sql.SQLException {
return -1;
}
public java.sql.DatabaseMetaData getMetaData() throws java.sql.SQLException {
return null;
}
public void clearWarnings() throws java.sql.SQLException {
}
public void rollback(java.sql.Savepoint savepoint) throws java.sql.SQLException {
}
}
--- NEW FILE: JdbcJndiDriver.java ---
/*
* JdbcLdapDriver.java
*
* Created on March 9, 2002, 4:49 PM
*/
package net.sourceforge.idrs.jndi;
import java.sql.*;
import java.lang.reflect.*;
import java.util.*;
import javax.naming.*;
/**
* Establishes a JNDI connection to an EJB Server. URLs are in the form :<br>
*<b>jdbc:ejb:factoryClass?ContextField1=val1:serverUrl</b>
*for any properties the driver accepts.
*/
public class JdbcJndiDriver implements java.sql.Driver {
/** Identifies the URL prefix */
public static final String URL_ID = "jdbc:ejb:";
/**Major Version of driver */
public static final int MAJOR_VERSION = 0;
/**Minor Version of driver */
public static final int MINOR_VERSION = 1;
/**Is JDBC Type IV Driver? */
public static final boolean JDBC_IV = false;
public static final String PARAM_DELIM = "=";
static {
try {
System.out.println("in static");
DriverManager.registerDriver(
new net.sourceforge.idrs.jndi.JdbcJndiDriver());
} catch (SQLException e) {
e.printStackTrace(System.out);
}
}
/** Creates new JdbcLdapDriver */
public JdbcJndiDriver() throws SQLException {
DriverManager.registerDriver(this);
}
/**
*Accepts URLs in the form ldap://host:port/basedn
*/
public boolean acceptsURL(java.lang.String str)
throws java.sql.SQLException {
System.out.println("in accepts url");
return str.substring(0, 9).equalsIgnoreCase(URL_ID);
}
public java.sql.Connection connect(
java.lang.String str,
java.util.Properties properties)
throws java.sql.SQLException {
System.out.println("in connection");
String props;
StringTokenizer toker;
String prop, val, token;
String factoryClass;
int beginUrl = str.indexOf(":", URL_ID.length());
String factory = str.substring(URL_ID.length(), beginUrl);
// System.out.println("factory : " + factory);
int seperator = factory.indexOf('?');
Field f;
if (seperator != -1) {
props = factory.substring(seperator + 1);
//System.out.println("props : " + props);
toker = new StringTokenizer(props, "&", false);
while (toker.hasMoreTokens()) {
token = toker.nextToken();
prop = token.substring(0, token.indexOf(PARAM_DELIM));
val =
token.substring(
token.indexOf(PARAM_DELIM) + PARAM_DELIM.length());
try {
f = Context.class.getField(prop);
if (f != null) {
properties.put(f.get(null), val);
}
} catch (NoSuchFieldException e) {
properties.put(prop, val);
} catch (IllegalAccessException e) {
throw new SQLException(e.toString());
}
}
factoryClass = factory.substring(0, seperator);
properties.put(Context.INITIAL_CONTEXT_FACTORY, factoryClass);
} else {
properties.put(Context.INITIAL_CONTEXT_FACTORY, factory);
}
System.out.println("loading props");
String user = properties.getProperty("user");
if (user != null) {
properties.remove("user");
properties.put(Context.SECURITY_PRINCIPAL, user);
}
String pass = properties.getProperty("password");
if (pass != null) {
properties.remove("password");
properties.put(Context.SECURITY_CREDENTIALS, pass);
}
System.out.println("loaded props");
Connection con = new JndiConnection(str.substring(beginUrl + 1), properties);
return con;
}
public int getMajorVersion() {
return MAJOR_VERSION;
}
public int getMinorVersion() {
return MINOR_VERSION;
}
public java.sql.DriverPropertyInfo[] getPropertyInfo(
java.lang.String str,
java.util.Properties properties)
throws java.sql.SQLException {
return null;
}
public boolean jdbcCompliant() {
return JDBC_IV;
}
}
|