You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@portals.apache.org by vk...@apache.org on 2008/12/16 17:17:05 UTC

svn commit: r727076 - in /portals/applications: demo/src/webapp/WEB-INF/view/ gems/src/java/org/apache/portals/gems/browser/

Author: vkumar
Date: Tue Dec 16 08:17:04 2008
New Revision: 727076

URL: http://svn.apache.org/viewvc?rev=727076&view=rev
Log:
Fixing minor issues in database browser

Modified:
    portals/applications/demo/src/webapp/WEB-INF/view/database-edit.vm
    portals/applications/demo/src/webapp/WEB-INF/view/database-edit1.vm
    portals/applications/gems/src/java/org/apache/portals/gems/browser/BrowserPortlet.java
    portals/applications/gems/src/java/org/apache/portals/gems/browser/DatabaseBrowserPortlet.java

Modified: portals/applications/demo/src/webapp/WEB-INF/view/database-edit.vm
URL: http://svn.apache.org/viewvc/portals/applications/demo/src/webapp/WEB-INF/view/database-edit.vm?rev=727076&r1=727075&r2=727076&view=diff
==============================================================================
--- portals/applications/demo/src/webapp/WEB-INF/view/database-edit.vm (original)
+++ portals/applications/demo/src/webapp/WEB-INF/view/database-edit.vm Tue Dec 16 08:17:04 2008
@@ -69,13 +69,13 @@
   <tr>
     <th class="portlet-section-alternate"><font class="portlet-form-field-label">$MESSAGES.getString("label.jdbc.driver")</font></th>
     <td>
-      <input type="input" name="JdbcDriver" $!disableDBCP  value="$!prefsMap.get('JdbcDriver')" size="60" maxlength="60" class="portlet-form-field-label"/> 
+      <input type="input" name="JdbcDriver" $!disableDBCP  value="$!prefsMap.get('JdbcDriver')" size="60" maxlength="100" class="portlet-form-field-label"/> 
     </td>
   </tr>
   <tr>
     <th class="portlet-section-alternate"><font class="portlet-form-field-label">$MESSAGES.getString("label.jdbc.connection")</font></th>
     <td>
-      <input type="input" name="JdbcConnection" $!disableDBCP value="$!prefsMap.get('JdbcConnection')" size="60" maxlength="60" class="portlet-form-field-label"/> 
+      <input type="input" name="JdbcConnection" $!disableDBCP value="$!prefsMap.get('JdbcConnection')" size="60" maxlength="100" class="portlet-form-field-label"/> 
     </td>
   </tr>
   <tr>
@@ -98,19 +98,19 @@
 <tr>
     <th class="portlet-section-alternate"><font class="portlet-form-field-label">$MESSAGES.getString("label.jdbc.driver")</font></th>
     <td>
-      <input type="input" name="SSOJdbcDriver" $!disableSSO  value="$!prefsMap.get('SSOJdbcDriver')" size="60" maxlength="60" class="portlet-form-field-label"/> 
+      <input type="input" name="SSOJdbcDriver" $!disableSSO  value="$!prefsMap.get('SSOJdbcDriver')" size="60" maxlength="100" class="portlet-form-field-label"/> 
     </td>
   </tr>
   <tr>
     <th class="portlet-section-alternate"><font class="portlet-form-field-label">$MESSAGES.getString("label.jdbc.connection")</font></th>
     <td>
-      <input type="input" name="SSOJdbcConnection" $!disableSSO value="$!prefsMap.get('SSOJdbcConnection')" size="60" maxlength="60" class="portlet-form-field-label"/> 
+      <input type="input" name="SSOJdbcConnection" $!disableSSO value="$!prefsMap.get('SSOJdbcConnection')" size="60" maxlength="100" class="portlet-form-field-label"/> 
     </td>
   </tr>
   <tr>
     <th class="portlet-section-alternate"><font class="portlet-form-field-label">SSO Site</font></th>
     <td>
-      <input type="input" name="SSOSite" $!disableSSO value="$!prefsMap.get('SSOSite')" size="60" maxlength="60" class="portlet-form-field-label"/> 
+      <input type="input" name="SSOSite" $!disableSSO value="$!prefsMap.get('SSOSite')" size="60" maxlength="100" class="portlet-form-field-label"/> 
     </td>
   </tr>
   </tr>  
@@ -125,13 +125,26 @@
     </td>
   </tr>
   <tr>
-    <th class="portlet-section-alternate"><font class="portlet-form-field-label">$MESSAGES.getString("label.sql")</font></th>
+  #set($tabelPref = $!prefsMap.get('tableName'))
+    <th class="portlet-section-alternate"><font class="portlet-form-field-label">TABLE</font></th>
     <td>
-      <input type="input" name="tableName" class="portlet-form-field-label" value="$!prefsMap.get('tableName')" />
-    </td>
+	#if($tableLists)
+		<select name="tables" id="tables">
+		#foreach ($table in $tableLists )
+			<option value='$table'
+			#if($table == $tabelPref)    
+				selected
+			#end>$table</option>
+		#end					
+		</select>
+    #else
+	<input type="input" name="tables" id="tables" class="portlet-form-field-label" value="$!prefsMap.get('tableName')" />
+	#end
+	</td>
   </tr>
 </table>
 
+<input type="hidden" name="tableName" id="tableName" value=""/>
 <input type="hidden" name="configPage" value=""/>
 <input type="submit" name="Save" value="Save" onClick="javascript:presave();"/>
 <input type="submit" name="Test" value="Test" onClick="javascript:presave();"/>
@@ -141,6 +154,13 @@
 <script language="JavaScript">
   function nextPage()
   {
+	#if($tableLists)
+	var tables = document.getElementById('tables');
+	document.J2DBEdit.tableName.value = tables.options[tables.selectedIndex].value;
+	#else
+	var tables = document.getElementById('tables');
+	document.J2DBEdit.tableName.value = tables.value;
+	#end
 	document.J2DBEdit.configPage.value = 'configPage1';
 	document.J2DBEdit.submit();
   }
@@ -187,6 +207,13 @@
 
   function presave()
   {
+    #if($tableLists)
+	var tables = document.getElementById('tables');
+	document.J2DBEdit.tableName.value = tables.options[tables.selectedIndex].value;
+	#else
+	var tables = document.getElementById('tables');
+	document.J2DBEdit.tableName.value = tables.value;
+	#end
     disableDS(false);
     disableDBCP(false);
     disableSSO(false);

Modified: portals/applications/demo/src/webapp/WEB-INF/view/database-edit1.vm
URL: http://svn.apache.org/viewvc/portals/applications/demo/src/webapp/WEB-INF/view/database-edit1.vm?rev=727076&r1=727075&r2=727076&view=diff
==============================================================================
--- portals/applications/demo/src/webapp/WEB-INF/view/database-edit1.vm (original)
+++ portals/applications/demo/src/webapp/WEB-INF/view/database-edit1.vm Tue Dec 16 08:17:04 2008
@@ -31,7 +31,7 @@
 #parse ('/WEB-INF/view/status-include.vm')
 #end
 
-<h3 class="portlet-section-header">$MESSAGES.getString('label.prefs')</h3>
+<h3 class="portlet-section-header">Fields</h3>
 
 <form name='J2DBEdit' action="$renderResponse.createActionURL()" method="post">
 <table border="0" cellspacing="2" cellpadding="3">
@@ -58,7 +58,7 @@
   </tr>
 </table>
 
-<h4 class="portlet-section-header">$MESSAGES.getString('label.general.settings')</h4>
+<h4 class="portlet-section-header">Where clause</h4>
 <table border="0" cellspacing="2" cellpadding="3">
   <tr>
     <th class="portlet-section-alternate"><font class="portlet-form-field-label">$MESSAGES.getString("label.sql")</font></th>
@@ -70,7 +70,8 @@
 
 <input type="hidden" name="columnTitles" id="columnTitles" value=""/>
 <input type="hidden" name="columnNames" id="columnNames" value=""/>
-<input type="hidden" name="configPage" value=""/>
+<input type="hidden" id="configPage" name="configPage" value=""/>
+<input type="button" name="back" value="Back" onClick="javascript:goBack();"/>
 <input type="button" name="Save" value="Save" onClick="javascript:saveAdvanceData();"/>
 </form>
 
@@ -135,6 +136,12 @@
 		document.getElementById('columnTitles').value = tempValue.substring(1);
 		document.getElementById('columnNames').value =  sqlValue.substring(1);
 	}
+	function goBack()
+	{
+		listToString();		
+		document.getElementById('configPage').value = 'configPage';
+		document.J2DBEdit.submit();
+	}
 	function saveAdvanceData()
 	{
 		listToString();

Modified: portals/applications/gems/src/java/org/apache/portals/gems/browser/BrowserPortlet.java
URL: http://svn.apache.org/viewvc/portals/applications/gems/src/java/org/apache/portals/gems/browser/BrowserPortlet.java?rev=727076&r1=727075&r2=727076&view=diff
==============================================================================
--- portals/applications/gems/src/java/org/apache/portals/gems/browser/BrowserPortlet.java (original)
+++ portals/applications/gems/src/java/org/apache/portals/gems/browser/BrowserPortlet.java Tue Dec 16 08:17:04 2008
@@ -24,10 +24,10 @@
 
 import javax.portlet.ActionRequest;
 import javax.portlet.ActionResponse;
+import javax.portlet.PortletConfig;
 import javax.portlet.PortletContext;
 import javax.portlet.PortletException;
 import javax.portlet.PortletMode;
-import javax.portlet.PortletConfig;
 import javax.portlet.PortletPreferences;
 import javax.portlet.PortletRequest;
 import javax.portlet.PortletSession;
@@ -69,6 +69,7 @@
     protected static final String SQL_PARAM_PREFIX = "sqlparam";
     protected static final String LINKS_READ = "linksRead";
     protected static final String ROW_LINK = "rowLinks";
+    
     protected static final String TABLE_LINK = "tableLinks";
     protected static final String ROW_LINK_IDS = "row-link-ids";
     protected static final String ROW_LINK_TYPES = "row-link-types";
@@ -181,6 +182,7 @@
                 {
                     context.put(PREVIOUS, String.valueOf(prev));
                 }
+                       
                 context.put(BROWSER_ITERATOR, iterator);
                 context.put(BROWSER_TITLE_ITERATOR, getTitleList(request));
                 context.put(BROWSER_TABLE_SIZE, new Integer(resultSetSize));
@@ -425,8 +427,6 @@
             setSQLParameters(sqlParamList);
         }
     }
-    
-    
 
     public void setSQLParameters(List parameters)
     {
@@ -505,5 +505,5 @@
     public List getTitleList(PortletRequest request)
     {
         return null;
-    }
+    } 
 }
\ No newline at end of file

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=727076&r1=727075&r2=727076&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 08:17:04 2008
@@ -64,7 +64,6 @@
 import org.apache.portals.bridges.util.PreferencesHelper;
 import org.apache.portals.gems.util.StatusMessage;
 import org.apache.portals.messaging.PortletMessaging;
-import org.springframework.util.ReflectionUtils;
 
 /**
  * DatabaseBrowserPortlet
@@ -80,6 +79,7 @@
     private static final String EXPORT_TYPE = "exportType";
     private static final String XML_EXPORT = "xmlExport";
     private static final String XLS_EXPORT = "xlsExport";
+    protected static final String TABLE_LIST = "tableLists";
     String pathSeprator = System.getProperty("file.separator");
     String pageRoot = System.getProperty("java.io.tmpdir");
     private String[] catlogNames;
@@ -457,22 +457,22 @@
             switch (type)
             {
                 case Types.DATE:
-                    beanMethods[index] = ReflectionUtils.findMethod(ResultSet.class, "getDate", new Class[] { String.class });
+                    //beanMethods[index] = .findMethod(ResultSet.class, "getDate", new Class[] { String.class });
                     break;
                 case Types.VARCHAR:
-                    beanMethods[index] = ReflectionUtils.findMethod(ResultSet.class, "getString", new Class[] { String.class });
+                    //beanMethods[index] = ReflectionUtils.findMethod(ResultSet.class, "getString", new Class[] { String.class });
                     break;
                 case Types.CHAR:
-                    beanMethods[index] = ReflectionUtils.findMethod(ResultSet.class, "getString", new Class[] { String.class });
+                    //beanMethods[index] = ReflectionUtils.findMethod(ResultSet.class, "getString", new Class[] { String.class });
                     break;
                 case Types.INTEGER:
-                    beanMethods[index] = ReflectionUtils.findMethod(ResultSet.class, "getInt", new Class[] { String.class });
+                    //beanMethods[index] = ReflectionUtils.findMethod(ResultSet.class, "getInt", new Class[] { String.class });
                     break;
                 case Types.FLOAT:
-                    beanMethods[index] = ReflectionUtils.findMethod(ResultSet.class, "getFloat", new Class[] { String.class });
+                    //beanMethods[index] = ReflectionUtils.findMethod(ResultSet.class, "getFloat", new Class[] { String.class });
                     break;
                 case Types.DOUBLE:
-                    beanMethods[index] = ReflectionUtils.findMethod(ResultSet.class, "getDouble", new Class[] { String.class });
+                    //beanMethods[index] = ReflectionUtils.findMethod(ResultSet.class, "getDouble", new Class[] { String.class });
                     break;
             }
         }
@@ -499,6 +499,7 @@
     public void doEdit(RenderRequest request, RenderResponse response) throws PortletException, IOException
     {
         response.setContentType("text/html");
+        List tableList = null;
         StatusMessage msg = (StatusMessage) PortletMessaging.consume(request, "DatabaseBrowserPortlet", "dbConnectTest");
         if (msg != null)
         {
@@ -511,8 +512,8 @@
             {
                 fillColumnDropDown(getConnection(request), request);
                 getContext(request).put("cols", getColNames());
-                getContext(request).put("colTitle",getTitleList(request));
-                getContext(request).put("colName",getColumNames(request));
+                getContext(request).put("colTitle", getTitleList(request));
+                getContext(request).put("colName", getColumNames(request));
             }
             catch (Exception e)
             {
@@ -521,6 +522,21 @@
             }
             request.setAttribute("EditPage", "/WEB-INF/view/database-edit1.vm");
         }
+        else
+        {
+            try
+            {
+                tableList = getTables(request, getConnection(request));
+            }
+            catch (Exception e)
+            {
+                // TODO: handle exception
+            }
+            if (tableList != null && tableList.size() > 0)
+            {
+                getContext(request).put(TABLE_LIST, tableList);
+            }
+        }
         super.doEdit(request, response);
     }
 
@@ -556,20 +572,30 @@
                 return;
             }
             String editAction = request.getParameter("configPage");
-            if (editAction != null && (editAction.equals("configPage1") || editAction.equals("configPage2")))
+            if (editAction != null)
             {
-                response.setPortletMode(PortletMode.EDIT);
-                response.setRenderParameter("configPage", editAction);
-                response.setRenderParameter(TABLE_NAME, request.getParameter(TABLE_NAME));
-                return;
+                if (editAction.equals("configPage1"))
+                {
+                    PortletPreferences prefs = request.getPreferences();
+                    PreferencesHelper.requestParamsToPreferences(request);
+                    prefs.store();
+                    response.setPortletMode(PortletMode.EDIT);
+                    response.setRenderParameter("configPage", editAction);
+                    response.setRenderParameter(TABLE_NAME, request.getParameter(TABLE_NAME));
+                    return;
+                }
+                else if (editAction.equals("configPage"))
+                {
+                    response.setPortletMode(PortletMode.EDIT);
+                    return;
+                }
             }
-            super.processAction(request, response);
         }
-        else
+        else if (request.getParameter(EXPORT_TYPE) != null)
         {
             String exportParam = request.getParameter(EXPORT_TYPE);
             String xlsFileName = "thedata.xls";
-            String fileName ="";
+            String fileName = "";
             if (!StringUtils.isEmpty(exportParam))
             {
                 if (exportParam.equals(XLS_EXPORT))
@@ -619,6 +645,8 @@
                                       "/fileserver/content?file=" + userName + "_" + fileName);
             }
         }
+        super.processAction(request, response);
+        
     }
 
     private Subject getSubject()
@@ -801,7 +829,7 @@
 
     private String cleanUserFolder(String userName)
     {
-        String folderName="";
+        String folderName = "";
         synchronized (this)
         {
             folderName = getUserFolder(userName, false);
@@ -813,7 +841,6 @@
         }
         return folderName;
     }
-    
 
     private String getUserFolder(String userName, boolean fullPath)
     {
@@ -828,4 +855,59 @@
             return pageRoot + pathSeprator + userName;
         }
     }
+
+    private List getTables(PortletRequest request, Connection conn)
+    {
+        ArrayList list = new ArrayList();
+        try
+        {
+            String databaseName = conn.getMetaData().getDatabaseProductName();
+            databaseName = databaseName.toLowerCase();
+            String query = getCatlogQuery(databaseName);
+            if (query == null)
+                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())
+                {
+                    list.add(set.getString(1));
+                }
+            }
+            
+        }
+        catch (SQLException e)
+        {
+            e.printStackTrace();
+        }
+        return list;
+    }
+
+    private String getCatlogQuery(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("sqlserver"))
+        {
+            dataBaseQuery = "Select name from sys.objects where type='U'";
+        }
+        else if (databaseName.equals("apache derby"))
+        {
+            dataBaseQuery = "SHOW TABLES";
+        }
+        return dataBaseQuery;
+    }
 }