[jboss-cvs] JBossAS SVN: r111946 - projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Aug 5 12:56:08 EDT 2011


Author: jesper.pedersen
Date: 2011-08-05 12:56:07 -0400 (Fri, 05 Aug 2011)
New Revision: 111946

Added:
   projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/ManagedConnectionMetaDataImpl.java
Modified:
   projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/BaseWrapperManagedConnection.java
Log:
[JBJCA-642] Use metadata from JDBC connection

Modified: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/BaseWrapperManagedConnection.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/BaseWrapperManagedConnection.java	2011-08-05 16:22:40 UTC (rev 111945)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/BaseWrapperManagedConnection.java	2011-08-05 16:56:07 UTC (rev 111946)
@@ -120,6 +120,9 @@
    /** Destroyed */
    protected boolean destroyed = false;
 
+   /** Metadata */
+   protected ManagedConnectionMetaData metadata;
+
    static
    {
       Class<?> connectionFactory = null;
@@ -202,6 +205,8 @@
       underlyingReadOnly = readOnly;
       jdbcReadOnly = readOnly;
       jdbcTransactionIsolation = this.transactionIsolation;
+
+      metadata = new ManagedConnectionMetaDataImpl(con, props.getProperty("user"));
    }
 
    /**
@@ -259,7 +264,7 @@
     */
    public ManagedConnectionMetaData getMetaData() throws ResourceException
    {
-      return null;
+      return metadata;
    }
 
    /**

Added: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/ManagedConnectionMetaDataImpl.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/ManagedConnectionMetaDataImpl.java	                        (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/ManagedConnectionMetaDataImpl.java	2011-08-05 16:56:07 UTC (rev 111946)
@@ -0,0 +1,133 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.adapters.jdbc;
+
+import java.io.Serializable;
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import javax.resource.spi.ManagedConnectionMetaData;
+
+/**
+ * Managed connection metadata
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class ManagedConnectionMetaDataImpl implements ManagedConnectionMetaData, Serializable
+{
+   /** Serial version UID */
+   private static final long serialVersionUID = 1L;
+
+   /** Product name */
+   private String productName;
+
+   /** Product version */
+   private String productVersion;
+
+   /** Max connections */
+   private int maxConnections;
+
+   /** User */
+   private String user;
+
+   /**
+    * Constructor
+    * @param connection The connection
+    * @param user The user
+    */
+   ManagedConnectionMetaDataImpl(Connection connection, String user)
+   {
+      try
+      {
+         if (connection != null && connection.getMetaData() != null)
+         {
+            productName = connection.getMetaData().getDatabaseProductName();
+            productVersion = connection.getMetaData().getDatabaseProductVersion();
+         }
+      }
+      catch (SQLException se)
+      {
+         // Nothing to do
+      }
+
+      if (productName == null)
+         productName = "";
+
+      if (productVersion == null)
+         productVersion = "";
+
+      this.maxConnections = 1;
+      this.user = user;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public String getEISProductName()
+   {
+      return productName;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public String getEISProductVersion()
+   {
+      return productVersion;
+   }
+    
+   /**
+    * {@inheritDoc}
+    */
+   public int getMaxConnections()
+   {
+      return maxConnections;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public String getUserName()
+   {
+      return user;
+   }
+
+   /**
+    * String representation
+    * @return The string
+    */
+   @Override
+   public String toString()
+   {
+      StringBuilder sb = new StringBuilder();
+
+      sb.append("ManagedConnectionMetaDataImpl@").append(Integer.toHexString(System.identityHashCode(this)));
+      sb.append("[");
+      sb.append(" productName=").append(productName);
+      sb.append(" productVersion=").append(productVersion);
+      sb.append(" maxConnections=").append(maxConnections);
+      sb.append(" user=").append(user);
+      sb.append("]");
+
+      return sb.toString();
+   }
+}



More information about the jboss-cvs-commits mailing list