public ClientDriver() {
}
public Connection connect(String url,
Properties properties) throws SQLException {
NetConnection conn;
checkURLNotNull( url );
try {
if (exceptionsOnLoadDriver__ != null) {
throw exceptionsOnLoadDriver__;
}
if (properties == null) {
properties = new Properties();
}
StringTokenizer urlTokenizer =
new StringTokenizer(url, "/:= \t\n\r\f", true);
int protocol = tokenizeProtocol(url, urlTokenizer);
if (protocol == 0) {
return null; // unrecognized database URL prefix.
}
String slashOrNull = null;
if (protocol == DERBY_REMOTE_PROTOCOL) {
try {
slashOrNull = urlTokenizer.nextToken(":/");
} catch (NoSuchElementException e) {
// A null log writer is passed, because jdbc 1 sqlexceptions are automatically traced
throw new SqlException(null,
new ClientMessageId(SQLState.MALFORMED_URL),
e, url);
}
}
String server = tokenizeServerName(urlTokenizer, url); // "/server"
int port = tokenizeOptionalPortNumber(urlTokenizer, url); // "[:port]/"
if (port == 0) {
port = BasicClientDataSource40.propertyDefault_portNumber;
}
// database is the database name and attributes. This will be
// sent to network server as the databaseName
String database = tokenizeDatabase(urlTokenizer, url); // "database"
Properties augmentedProperties =
tokenizeURLProperties(url, properties);
database = appendDatabaseAttributes(database,augmentedProperties);
int traceLevel;
try {
traceLevel =
BasicClientDataSource40.getTraceLevel(augmentedProperties);
} catch (NumberFormatException e) {
// A null log writer is passed, because jdbc 1 sqlexceptions are automatically traced
throw new SqlException(null,
new ClientMessageId(SQLState.TRACELEVEL_FORMAT_INVALID), e);
}
// Jdbc 1 connections will write driver trace info on a
// driver-wide basis using the jdbc 1 driver manager log writer.
// This log writer may be narrowed to the connection-level
// This log writer will be passed to the agent constructor.
LogWriter dncLogWriter =
BasicClientDataSource40.computeDncLogWriterForNewConnection(
DriverManager.getLogWriter(),
BasicClientDataSource40.getTraceDirectory(
augmentedProperties),
BasicClientDataSource40.getTraceFile(
augmentedProperties),
BasicClientDataSource40.getTraceFileAppend(
augmentedProperties),
traceLevel,
"_driver",
traceFileSuffixIndex_++);
conn = (NetConnection)getFactory().
newNetConnection(dncLogWriter,
DriverManager.getLoginTimeout(),
server,
port,
database,
augmentedProperties);
} catch(SqlException se) {
throw se.getSQLException();
}
if(conn.isConnectionNull())
return null;
return conn;
}