Author: taylor
Date: Tue Dec 16 19:52:50 2008
New Revision: 727264

URL: http://svn.apache.org/viewvc?rev=727264&view=rev
Log:
manage connections in db browser
use DatabaseMetadata when possible

Added:
    portals/applications/gems/.classpath   (with props)
    portals/applications/gems/.project   (with props)
Modified:
    
portals/applications/gems/src/java/org/apache/portals/gems/browser/DatabaseBrowserPortlet.java

Added: portals/applications/gems/.classpath
URL: 
http://svn.apache.org/viewvc/portals/applications/gems/.classpath?rev=727264&view=auto
==============================================================================
--- portals/applications/gems/.classpath (added)
+++ portals/applications/gems/.classpath Tue Dec 16 19:52:50 2008
@@ -0,0 +1,36 @@
+<classpath>
+  <classpathentry kind="src" path="src/java"/>
+  <classpathentry kind="output" path="target/classes"/>
+  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+  <classpathentry kind="var" 
path="M2_REPO/commons-dbcp/commons-dbcp/1.2.2/commons-dbcp-1.2.2.jar"/>
+  <classpathentry kind="var" 
path="M2_REPO/commons-pool/commons-pool/1.3/commons-pool-1.3.jar"/>
+  <classpathentry kind="var" 
path="M2_REPO/commons-httpclient/commons-httpclient/3.0.1/commons-httpclient-3.0.1.jar"/>
+  <classpathentry kind="var" 
path="M2_REPO/commons-logging/commons-logging/1.1/commons-logging-1.1.jar" 
sourcepath="M2_REPO/commons-logging/commons-logging/1.1/commons-logging-1.1-sources.jar"/>
+  <classpathentry kind="var" 
path="M2_REPO/commons-codec/commons-codec/1.3/commons-codec-1.3.jar"/>
+  <classpathentry kind="var" 
path="M2_REPO/commons-lang/commons-lang/2.1/commons-lang-2.1.jar" 
sourcepath="M2_REPO/commons-lang/commons-lang/2.1/commons-lang-2.1-sources.jar">
+    <attributes>
+      <attribute 
value="jar:file://Users/dtaylor/.m2/repository/commons-lang/commons-lang/2.1/commons-lang-2.1-javadoc.jar!/"
 name="javadoc_location"/>
+    </attributes>
+  </classpathentry>
+  <classpathentry kind="var" 
path="M2_REPO/javax/portlet/portlet-api/2.0/portlet-api-2.0.jar"/>
+  <classpathentry kind="var" 
path="M2_REPO/javax/servlet/servlet-api/2.4/servlet-api-2.4.jar"/>
+  <classpathentry kind="var" 
path="M2_REPO/javax/servlet/jsp/jsp-api/2.0/jsp-api-2.0.jar"/>
+  <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar" 
sourcepath="M2_REPO/junit/junit/3.8.1/junit-3.8.1-sources.jar"/>
+  <classpathentry kind="var" 
path="M2_REPO/org/apache/pluto/pluto-container-api/2.0.0-SNAPSHOT/pluto-container-api-2.0.0-SNAPSHOT.jar"
 
sourcepath="M2_REPO/org/apache/pluto/pluto-container-api/2.0.0-SNAPSHOT/pluto-container-api-2.0.0-SNAPSHOT-sources.jar"/>
+  <classpathentry kind="var" 
path="M2_REPO/org/apache/poi/poi/3.0-FINAL/poi-3.0-FINAL.jar"/>
+  <classpathentry kind="var" 
path="M2_REPO/log4j/log4j/1.2.14/log4j-1.2.14.jar"/>
+  <classpathentry kind="var" 
path="M2_REPO/org/apache/portals/bridges/portals-bridges-common/1.0.4/portals-bridges-common-1.0.4.jar"/>
+  <classpathentry kind="var" 
path="M2_REPO/org/apache/portals/bridges/portals-bridges-velocity/1.0.4/portals-bridges-velocity-1.0.4.jar"/>
+  <classpathentry kind="var" 
path="M2_REPO/velocity/velocity/1.5/velocity-1.5.jar"/>
+  <classpathentry kind="var" 
path="M2_REPO/commons-collections/commons-collections/3.2/commons-collections-3.2.jar"/>
+  <classpathentry kind="var" path="M2_REPO/oro/oro/2.0.8/oro-2.0.8.jar"/>
+  <classpathentry kind="var" 
path="M2_REPO/velocity-tools/velocity-tools/1.3/velocity-tools-1.3.jar"/>
+  <classpathentry kind="var" 
path="M2_REPO/org/apache/portals/jetspeed-2/jetspeed-api/2.2-SNAPSHOT/jetspeed-api-2.2-SNAPSHOT.jar"
 
sourcepath="M2_REPO/org/apache/portals/jetspeed-2/jetspeed-api/2.2-SNAPSHOT/jetspeed-api-2.2-SNAPSHOT-sources.jar"/>
+  <classpathentry kind="var" 
path="M2_REPO/org/apache/portals/jetspeed-2/jetspeed-commons/2.2-SNAPSHOT/jetspeed-commons-2.2-SNAPSHOT.jar"
 
sourcepath="M2_REPO/org/apache/portals/jetspeed-2/jetspeed-commons/2.2-SNAPSHOT/jetspeed-commons-2.2-SNAPSHOT-sources.jar"/>
+  <classpathentry kind="var" 
path="M2_REPO/org/springframework/spring-beans/2.5.2/spring-beans-2.5.2.jar"/>
+  <classpathentry kind="var" 
path="M2_REPO/org/springframework/spring-core/2.5.2/spring-core-2.5.2.jar"/>
+  <classpathentry kind="var" 
path="M2_REPO/org/springframework/spring-portlet/2.0.6/spring-portlet-2.0.6.jar"/>
+  <classpathentry kind="var" 
path="M2_REPO/org/springframework/spring-context/2.5.2/spring-context-2.5.2.jar"/>
+  <classpathentry kind="var" 
path="M2_REPO/aopalliance/aopalliance/1.0/aopalliance-1.0.jar"/>
+  <classpathentry kind="var" 
path="M2_REPO/org/springframework/spring-web/2.5.2/spring-web-2.5.2.jar"/>
+</classpath>
\ No newline at end of file

Propchange: portals/applications/gems/.classpath
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/applications/gems/.classpath
------------------------------------------------------------------------------
    svn:keywords = Id

Added: portals/applications/gems/.project
URL: 
http://svn.apache.org/viewvc/portals/applications/gems/.project?rev=727264&view=auto
==============================================================================
--- portals/applications/gems/.project (added)
+++ portals/applications/gems/.project Tue Dec 16 19:52:50 2008
@@ -0,0 +1,13 @@
+<projectDescription>
+  <name>portals-gems-2.2-SNAPSHOT</name>
+  <comment>Reusable Portlets (Gems) for your Portlet Applications.</comment>
+  <projects/>
+  <buildSpec>
+    <buildCommand>
+      <name>org.eclipse.jdt.core.javabuilder</name>
+    </buildCommand>
+  </buildSpec>
+  <natures>
+    <nature>org.eclipse.jdt.core.javanature</nature>
+  </natures>
+</projectDescription>
\ No newline at end of file

Propchange: portals/applications/gems/.project
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/applications/gems/.project
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: 
portals/applications/gems/src/java/org/apache/portals/gems/browser/DatabaseBrowserPortlet.java
URL: 
http://svn.apache.org/viewvc/portals/applications/gems/src/java/org/apache/portals/gems/browser/DatabaseBrowserPortlet.java?rev=727264&r1=727263&r2=727264&view=diff
==============================================================================
--- 
portals/applications/gems/src/java/org/apache/portals/gems/browser/DatabaseBrowserPortlet.java
 (original)
+++ 
portals/applications/gems/src/java/org/apache/portals/gems/browser/DatabaseBrowserPortlet.java
 Tue Dec 16 19:52:50 2008
@@ -488,7 +488,8 @@
     {
         try
         {
-            con.close();
+            if (con != null)
+                con.close();
         }
         catch (SQLException e)
         {
@@ -498,6 +499,7 @@
 
     public void doEdit(RenderRequest request, RenderResponse response) throws 
PortletException, IOException
     {
+        Connection con = null;
         response.setContentType("text/html");
         List tableList = null;
         StatusMessage msg = (StatusMessage) PortletMessaging.consume(request, 
"DatabaseBrowserPortlet", "dbConnectTest");
@@ -510,7 +512,8 @@
         {
             try
             {
-                fillColumnDropDown(getConnection(request), request);
+                con = getConnection(request);
+                fillColumnDropDown(con, request);
                 getContext(request).put("cols", getColNames());
                 getContext(request).put("colTitle", getTitleList(request));
                 getContext(request).put("colName", getColumNames(request));
@@ -520,13 +523,18 @@
                 // TODO Auto-generated catch block
                 e.printStackTrace();
             }
+            finally
+            {
+                this.closeConnection(con);
+            }
             request.setAttribute("EditPage", 
"/WEB-INF/view/database-edit1.vm");
         }
         else
         {
             try
             {
-                tableList = getTables(request, getConnection(request));
+                con = getConnection(request);
+                tableList = getTables(request, con);
             }
             catch (Exception e)
             {
@@ -548,12 +556,13 @@
             String test = request.getParameter("Test");
             if (test != null && test.equals("Test"))
             {
+                Connection con = null;
                 try
                 {
                     PortletPreferences prefs = request.getPreferences();
                     PreferencesHelper.requestParamsToPreferences(request);
                     prefs.store();
-                    getConnection(request);
+                    con = getConnection(request);
                     StatusMessage msg = new StatusMessage("Connection made 
successfully.", StatusMessage.SUCCESS);
                     PortletMessaging.publish(request, 
"DatabaseBrowserPortlet", "dbConnectTest", msg);
                 }
@@ -568,6 +577,10 @@
                     StatusMessage sm = new StatusMessage(msg, 
StatusMessage.ERROR);
                     PortletMessaging.publish(request, 
"DatabaseBrowserPortlet", "dbConnectTest", sm);
                 }
+                finally
+                {
+                    this.closeConnection(con);
+                }
                 response.setPortletMode(PortletMode.EDIT);
                 return;
             }
@@ -856,28 +869,32 @@
         }
     }
 
-    private List getTables(PortletRequest request, Connection conn)
+    private List<String> getTables(PortletRequest request, Connection conn)
     {
-        ArrayList list = new ArrayList();
+        List<String> list = new ArrayList<String>();
+        ResultSet rs = null;
+        PreparedStatement stmt = null;        
         try
         {
             String databaseName = conn.getMetaData().getDatabaseProductName();
             databaseName = databaseName.toLowerCase();
-            String query = getCatlogQuery(databaseName);
+            String query = getCatalogQuery(databaseName);
             if (query == null)
+            {
+                rs = conn.getMetaData().getTables(null, null, "%", null); 
//new String[] {"TABLE"});
+                while (rs.next())
+                {
+                    list.add(rs.getString("TABLE_NAME"));
+                }        
                 return list;
-            PreparedStatement stmt = conn.prepareStatement(query);
-            ResultSet set = stmt.executeQuery();
-            if(databaseName.equals("mysql"))
-            {
-                while (set.next())
-                {
-                    list.add(set.getString(1));
-                }    
-            }else{
-                while (set.next())
+            }
+            else
+            {
+                stmt = conn.prepareStatement(query);
+                rs = stmt.executeQuery();
+                while (rs.next())
                 {
-                    list.add(set.getString(1));
+                    list.add(rs.getString(1));
                 }
             }
             
@@ -886,28 +903,37 @@
         {
             e.printStackTrace();
         }
+        finally
+        {
+            try
+            {
+                if (stmt != null)
+                    stmt.close();
+                if (rs != null)
+                    rs.close();
+            }
+            catch (Exception e2) 
+            {}
+        }
         return list;
     }
 
-    private String getCatlogQuery(String databaseName)
+    private String getCatalogQuery(String databaseName)
     {
         String dataBaseQuery = null;
         if (databaseName.equals("oracle"))
         {
             dataBaseQuery = "SELECT table_name FROM user_tables";
         }
-        else if (databaseName.equals("mysql"))
-        {
-            dataBaseQuery = "show tables";
-        }
+//        else if (databaseName.equals("mysql"))
+//        {
+//            dataBaseQuery = "show tables";
+//        }
         else if (databaseName.equals("sqlserver"))
         {
             dataBaseQuery = "Select name from sys.objects where type='U'";
         }
-        else if (databaseName.equals("apache derby"))
-        {
-            dataBaseQuery = "SHOW TABLES";
-        }
+        //else if (databaseName.equals("apache derby"))
         return dataBaseQuery;
     }
 }


Reply via email to