Diff
Added: trunk/openejb3/container/openejb-core/src/main/java/org/openejb/resource/jdbc/InstantdbPropertiesHack.java (2566 => 2567)
--- trunk/openejb3/container/openejb-core/src/main/java/org/openejb/resource/jdbc/InstantdbPropertiesHack.java 2006-03-22 01:54:34 UTC (rev 2566)
+++ trunk/openejb3/container/openejb-core/src/main/java/org/openejb/resource/jdbc/InstantdbPropertiesHack.java 2006-03-22 01:56:22 UTC (rev 2567)
@@ -0,0 +1,77 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openejb.resource.jdbc;
+
+import org.openejb.loader.SystemInstance;
+import org.openejb.util.ResourceFinder;
+
+import javax.resource.spi.ManagedConnectionFactory;
+import javax.resource.spi.ManagedConnection;
+import javax.resource.spi.ConnectionRequestInfo;
+import javax.resource.ResourceException;
+import javax.security.auth.Subject;
+import java.util.Properties;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+public class InstantdbPropertiesHack extends ManagedConnectionFactoryAdapter {
+
+ public InstantdbPropertiesHack(ManagedConnectionFactory factory, String jdbcUrl) {
+ super(factory);
+ // jdbc:idb:conf/instantdb.properties
+ String prefix = "jdbc:idb:";
+ int index = jdbcUrl.indexOf(prefix);
+ if (index == -1){
+ return;
+ }
+
+ String confFile = jdbcUrl.substring(index + prefix.length());
+
+ File base = SystemInstance.get().getBase().getDirectory();
+ File file = new File(base, confFile);
+
+
+ if (file.exists()) {
+ // The instantdb properties file is there, we're good
+ return;
+ }
+
+ if (!file.getParentFile().exists()){
+ // The directory the instantdb properties file should live in
+ // doesn't exist, don't bother
+ return;
+ }
+
+ FileOutputStream out = null;
+ try {
+ ResourceFinder finder = new ResourceFinder("");
+ String defaultProperties = finder.findString("default.instantdb.properties");
+ out = new FileOutputStream(file);
+ out.write(defaultProperties.getBytes());
+ out.flush();
+ } catch (IOException e) {
+ // TODO; Handle this
+ e.printStackTrace();
+ } finally {
+ try {
+ out.close();
+ } catch (IOException e) {
+ }
+ }
+ }
+}
Modified: trunk/openejb3/container/openejb-core/src/main/java/org/openejb/resource/jdbc/JdbcManagedConnectionFactory.java (2566 => 2567)
--- trunk/openejb3/container/openejb-core/src/main/java/org/openejb/resource/jdbc/JdbcManagedConnectionFactory.java 2006-03-22 01:54:34 UTC (rev 2566)
+++ trunk/openejb3/container/openejb-core/src/main/java/org/openejb/resource/jdbc/JdbcManagedConnectionFactory.java 2006-03-22 01:56:22 UTC (rev 2567)
@@ -29,6 +29,7 @@
factory = new BasicManagedConnectionFactory(this, driver, url, defaultUserName, defaultPassword);
if (driver.equals("org.enhydra.instantdb.jdbc.idbDriver")) {
+ factory = new InstantdbPropertiesHack(factory, url);
factory = new ManagedConnectionFactoryPathHack(factory);
}
Added: trunk/openejb3/container/openejb-core/src/main/java/org/openejb/resource/jdbc/ManagedConnectionFactoryAdapter.java (2566 => 2567)
--- trunk/openejb3/container/openejb-core/src/main/java/org/openejb/resource/jdbc/ManagedConnectionFactoryAdapter.java 2006-03-22 01:54:34 UTC (rev 2566)
+++ trunk/openejb3/container/openejb-core/src/main/java/org/openejb/resource/jdbc/ManagedConnectionFactoryAdapter.java 2006-03-22 01:56:22 UTC (rev 2567)
@@ -0,0 +1,71 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openejb.resource.jdbc;
+
+import javax.resource.spi.ConnectionManager;
+import javax.resource.spi.ManagedConnection;
+import javax.resource.spi.ConnectionRequestInfo;
+import javax.resource.spi.ManagedConnectionFactory;
+import javax.resource.ResourceException;
+import javax.security.auth.Subject;
+import java.util.Set;
+import java.io.PrintWriter;
+import java.io.Serializable;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public class ManagedConnectionFactoryAdapter implements javax.resource.spi.ManagedConnectionFactory, Serializable {
+
+ private final ManagedConnectionFactory factory;
+
+ public ManagedConnectionFactoryAdapter(ManagedConnectionFactory factory) {
+ this.factory = factory;
+ }
+
+ public Object createConnectionFactory(ConnectionManager connectionManager) throws ResourceException {
+ return factory.createConnectionFactory(connectionManager);
+ }
+
+ public Object createConnectionFactory() throws ResourceException {
+ return factory.createConnectionFactory();
+ }
+
+ public ManagedConnection createManagedConnection(Subject subject, ConnectionRequestInfo connectionRequestInfo) throws ResourceException {
+ return factory.createManagedConnection(subject, connectionRequestInfo);
+ }
+
+ public ManagedConnection matchManagedConnections(Set set, Subject subject, ConnectionRequestInfo connectionRequestInfo) throws ResourceException {
+ return factory.matchManagedConnections(set, subject, connectionRequestInfo);
+ }
+
+ public void setLogWriter(PrintWriter printWriter) throws ResourceException {
+ factory.setLogWriter(printWriter);
+ }
+
+ public PrintWriter getLogWriter() throws ResourceException {
+ return factory.getLogWriter();
+ }
+
+ public int hashCode() {
+ return factory.hashCode();
+ }
+
+ public boolean equals(Object o) {
+ return factory.equals(o);
+ }
+}
Modified: trunk/openejb3/container/openejb-core/src/main/java/org/openejb/resource/jdbc/ManagedConnectionFactoryPathHack.java (2566 => 2567)
--- trunk/openejb3/container/openejb-core/src/main/java/org/openejb/resource/jdbc/ManagedConnectionFactoryPathHack.java 2006-03-22 01:54:34 UTC (rev 2566)
+++ trunk/openejb3/container/openejb-core/src/main/java/org/openejb/resource/jdbc/ManagedConnectionFactoryPathHack.java 2006-03-22 01:56:22 UTC (rev 2567)
@@ -15,53 +15,23 @@
import java.io.File;
import java.sql.DriverManager;
-public class ManagedConnectionFactoryPathHack implements javax.resource.spi.ManagedConnectionFactory, java.io.Serializable {
- private final ManagedConnectionFactory factory;
+public class ManagedConnectionFactoryPathHack extends ManagedConnectionFactoryAdapter {
public ManagedConnectionFactoryPathHack(ManagedConnectionFactory factory) {
- this.factory = factory;
+ super(factory);
}
- public Object createConnectionFactory(ConnectionManager connectionManager) throws ResourceException {
- return factory.createConnectionFactory(connectionManager);
- }
-
- public Object createConnectionFactory() throws ResourceException {
- return factory.createConnectionFactory();
- }
-
public ManagedConnection createManagedConnection(Subject subject, ConnectionRequestInfo connectionRequestInfo) throws ResourceException {
-
Properties systemProperties = System.getProperties();
synchronized (systemProperties) {
String userDir = systemProperties.getProperty("user.dir");
try {
File base = SystemInstance.get().getBase().getDirectory();
systemProperties.setProperty("user.dir", base.getAbsolutePath());
- return factory.createManagedConnection(subject, connectionRequestInfo);
+ return super.createManagedConnection(subject, connectionRequestInfo);
} finally {
systemProperties.setProperty("user.dir", userDir);
}
}
}
-
- public ManagedConnection matchManagedConnections(Set set, Subject subject, ConnectionRequestInfo connectionRequestInfo) throws ResourceException {
- return factory.matchManagedConnections(set, subject, connectionRequestInfo);
- }
-
- public void setLogWriter(PrintWriter printWriter) throws ResourceException {
- factory.setLogWriter(printWriter);
- }
-
- public PrintWriter getLogWriter() throws ResourceException {
- return factory.getLogWriter();
- }
-
- public int hashCode() {
- return factory.hashCode();
- }
-
- public boolean equals(Object o) {
- return factory.equals(o);
- }
}