Author: shawkins
Date: 2010-04-10 21:56:24 -0400 (Sat, 10 Apr 2010)
New Revision: 2047
Modified:
trunk/connector-api/src/main/java/org/teiid/connector/basic/BasicManagedConnection.java
trunk/connector-api/src/main/java/org/teiid/connector/basic/BasicManagedConnectionFactory.java
trunk/connector-api/src/main/java/org/teiid/connector/basic/WrappedConnection.java
trunk/connector-api/src/main/java/org/teiid/connector/basic/WrappedConnector.java
trunk/connector-api/src/main/resources/org/teiid/connector/i18n.properties
Log:
TEIID-833 adding connection validation to teiid managedconnections
Modified:
trunk/connector-api/src/main/java/org/teiid/connector/basic/BasicManagedConnection.java
===================================================================
---
trunk/connector-api/src/main/java/org/teiid/connector/basic/BasicManagedConnection.java 2010-04-11
01:03:23 UTC (rev 2046)
+++
trunk/connector-api/src/main/java/org/teiid/connector/basic/BasicManagedConnection.java 2010-04-11
01:56:24 UTC (rev 2047)
@@ -136,4 +136,8 @@
l.connectionClosed(ce);
}
}
+
+ public boolean isValid() {
+ return this.conn.isAlive();
+ }
}
Modified:
trunk/connector-api/src/main/java/org/teiid/connector/basic/BasicManagedConnectionFactory.java
===================================================================
---
trunk/connector-api/src/main/java/org/teiid/connector/basic/BasicManagedConnectionFactory.java 2010-04-11
01:03:23 UTC (rev 2046)
+++
trunk/connector-api/src/main/java/org/teiid/connector/basic/BasicManagedConnectionFactory.java 2010-04-11
01:56:24 UTC (rev 2047)
@@ -24,6 +24,7 @@
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Collection;
+import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
@@ -34,6 +35,7 @@
import javax.resource.spi.ManagedConnectionFactory;
import javax.resource.spi.ResourceAdapter;
import javax.resource.spi.ResourceAdapterAssociation;
+import javax.resource.spi.ValidatingManagedConnectionFactory;
import javax.security.auth.Subject;
import org.teiid.connector.api.Connector;
@@ -46,7 +48,7 @@
import com.metamatrix.core.MetaMatrixCoreException;
import com.metamatrix.core.util.ReflectionHelper;
-public class BasicManagedConnectionFactory implements ManagedConnectionFactory,
ResourceAdapterAssociation, ConnectorEnvironment {
+public class BasicManagedConnectionFactory implements ManagedConnectionFactory,
ResourceAdapterAssociation, ConnectorEnvironment, ValidatingManagedConnectionFactory {
private static final long serialVersionUID = -7302713800883776790L;
private static final TypeFacility TYPE_FACILITY = new TypeFacilityImpl();
@@ -210,5 +212,19 @@
} catch(InstantiationException e) {
throw new ConnectorException(e);
}
- }
+ }
+
+ @Override
+ public Set<BasicManagedConnection> getInvalidConnections(Set arg0) throws
ResourceException {
+ HashSet<BasicManagedConnection> result = new
HashSet<BasicManagedConnection>();
+ for (Object object : arg0) {
+ if (object instanceof BasicManagedConnection) {
+ BasicManagedConnection bmc = (BasicManagedConnection)object;
+ if (!bmc.isValid()) {
+ result.add(bmc);
+ }
+ }
+ }
+ return result;
+ }
}
Modified:
trunk/connector-api/src/main/java/org/teiid/connector/basic/WrappedConnection.java
===================================================================
---
trunk/connector-api/src/main/java/org/teiid/connector/basic/WrappedConnection.java 2010-04-11
01:03:23 UTC (rev 2046)
+++
trunk/connector-api/src/main/java/org/teiid/connector/basic/WrappedConnection.java 2010-04-11
01:56:24 UTC (rev 2047)
@@ -26,6 +26,7 @@
import javax.resource.spi.LocalTransaction;
import javax.transaction.xa.XAResource;
+import org.teiid.connector.DataPlugin;
import org.teiid.connector.api.Connection;
import org.teiid.connector.api.ConnectorCapabilities;
import org.teiid.connector.api.ConnectorEnvironment;
@@ -70,11 +71,10 @@
@Override
public ConnectorCapabilities getCapabilities() throws ConnectorException {
if (this.caps == null) {
- ConnectorCapabilities caps = conn.getCapabilities();
+ this.caps = conn.getCapabilities();
if (caps != null && this.env.getOverrideCapabilities() != null) {
caps = (ConnectorCapabilities)
Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class[]
{ConnectorCapabilities.class}, new CapabilitesOverloader(caps,
this.env.getOverrideCapabilities()));
}
- this.caps = caps;
}
return this.caps;
}
@@ -99,7 +99,7 @@
if (this.conn instanceof MetadataProvider) {
((MetadataProvider) this.conn).getConnectorMetadata(metadataFactory);
} else {
- throw new ConnectorException("Connector is not capable of providing metadata.
Extend connector with MetadataProvider interface");
+ throw new
ConnectorException(DataPlugin.Util.getString("WrappedConnection.no_metadata")); //$NON-NLS-1$
}
}
Modified:
trunk/connector-api/src/main/java/org/teiid/connector/basic/WrappedConnector.java
===================================================================
---
trunk/connector-api/src/main/java/org/teiid/connector/basic/WrappedConnector.java 2010-04-11
01:03:23 UTC (rev 2046)
+++
trunk/connector-api/src/main/java/org/teiid/connector/basic/WrappedConnector.java 2010-04-11
01:56:24 UTC (rev 2047)
@@ -76,9 +76,6 @@
if (this.caps == null) {
try {
Object o = ReflectionHelper.create(this.mcf.getCapabilitiesClass(), null,
Thread.currentThread().getContextClassLoader());
- if(!(o instanceof ConnectorCapabilities)) {
- throw new ConnectorException("Invalid Connector Capabilities class
specified="+this.mcf.getCapabilitiesClass());
- }
this.caps = (ConnectorCapabilities)o;
} catch (MetaMatrixCoreException e) {
throw new ConnectorException(e);
Modified: trunk/connector-api/src/main/resources/org/teiid/connector/i18n.properties
===================================================================
--- trunk/connector-api/src/main/resources/org/teiid/connector/i18n.properties 2010-04-11
01:03:23 UTC (rev 2046)
+++ trunk/connector-api/src/main/resources/org/teiid/connector/i18n.properties 2010-04-11
01:56:24 UTC (rev 2047)
@@ -66,4 +66,6 @@
MetadataFactory.unknown_datatype=Unknown datatype {0}
MetadataFactory.no_column_found=No column found with name {0}
MetadataFactory.duplicate_name="Non-uniquely named record detected
''{0}''
-MetadataFactory.invalid_name=Invalid column name ''{0}'', cannot contain
the . character.
\ No newline at end of file
+MetadataFactory.invalid_name=Invalid column name ''{0}'', cannot contain
the . character.
+
+WrappedConnection.no_metadata=Connector is not capable of providing metadata. Extend
connector with MetadataProvider interface
\ No newline at end of file
Show replies by date