You are viewing a plain text version of this content. The canonical link for it is here.
Posted to portalapps-dev@portals.apache.org by vk...@apache.org on 2009/04/10 18:16:20 UTC
svn commit: r763970 [1/3] - in /portals/applications/databaseBrowser: ./
trunk/ trunk/dbBrowser-jar/ trunk/dbBrowser-jar/src/
trunk/dbBrowser-jar/src/main/ trunk/dbBrowser-jar/src/main/java/
trunk/dbBrowser-jar/src/main/java/org/ trunk/dbBrowser-jar/sr...
Author: vkumar
Date: Fri Apr 10 16:16:18 2009
New Revision: 763970
URL: http://svn.apache.org/viewvc?rev=763970&view=rev
Log:
Adding DatabaseBrowser project under applications
https://issues.apache.org/jira/browse/APA-4
Added:
portals/applications/databaseBrowser/
portals/applications/databaseBrowser/trunk/
portals/applications/databaseBrowser/trunk/dbBrowser-jar/
portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/
portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/
portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/
portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/
portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/
portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/
portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/
portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/
portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/ActionParameter.java (with props)
portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/Browser.java (with props)
portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/BrowserIterator.java (with props)
portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/BrowserPortlet.java (with props)
portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/DatabaseBrowserIterator.java (with props)
portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/DatabaseBrowserPortlet.java (with props)
portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/StatusMessage.java (with props)
portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/ValidationHelper.java (with props)
portals/applications/databaseBrowser/trunk/dbBrowser-war/
portals/applications/databaseBrowser/trunk/dbBrowser-war/src/
portals/applications/databaseBrowser/trunk/dbBrowser-war/src/main/
portals/applications/databaseBrowser/trunk/dbBrowser-war/src/main/java/
portals/applications/databaseBrowser/trunk/dbBrowser-war/src/main/java/org/
portals/applications/databaseBrowser/trunk/dbBrowser-war/src/main/java/org/apache/
portals/applications/databaseBrowser/trunk/dbBrowser-war/src/main/java/org/apache/portals/
portals/applications/databaseBrowser/trunk/dbBrowser-war/src/main/java/org/apache/portals/applications/
portals/applications/databaseBrowser/trunk/dbBrowser-war/src/main/java/org/apache/portals/applications/dbBrowser/
portals/applications/databaseBrowser/trunk/dbBrowser-war/src/main/java/org/apache/portals/applications/dbBrowser/resources/
portals/applications/databaseBrowser/trunk/dbBrowser-war/src/main/java/org/apache/portals/applications/dbBrowser/resources/Browser.properties (with props)
portals/applications/databaseBrowser/trunk/dbBrowser-war/src/main/java/org/apache/portals/applications/dbBrowser/resources/Browser_de.properties (with props)
portals/applications/databaseBrowser/trunk/dbBrowser-war/src/main/java/org/apache/portals/applications/dbBrowser/resources/Browser_en.properties (with props)
portals/applications/databaseBrowser/trunk/dbBrowser-war/src/main/java/org/apache/portals/applications/dbBrowser/resources/Browser_hu.properties (with props)
portals/applications/databaseBrowser/trunk/dbBrowser-war/src/main/java/org/apache/portals/applications/dbBrowser/resources/Browser_it.properties (with props)
portals/applications/databaseBrowser/trunk/dbBrowser-war/src/main/java/org/apache/portals/applications/dbBrowser/resources/Browser_ja.properties (with props)
portals/applications/databaseBrowser/trunk/dbBrowser-war/src/main/java/org/apache/portals/applications/dbBrowser/resources/Browser_ko.properties (with props)
portals/applications/databaseBrowser/trunk/dbBrowser-war/src/main/java/org/apache/portals/applications/dbBrowser/resources/Browser_ua.properties (with props)
portals/applications/databaseBrowser/trunk/dbBrowser-war/src/main/java/org/apache/portals/applications/dbBrowser/resources/Browser_zh.properties (with props)
portals/applications/databaseBrowser/trunk/dbBrowser-war/src/main/java/org/apache/portals/applications/dbBrowser/resources/Browser_zh_TW.properties (with props)
portals/applications/databaseBrowser/trunk/dbBrowser-war/src/main/webapp/
portals/applications/databaseBrowser/trunk/dbBrowser-war/src/main/webapp/WEB-INF/
portals/applications/databaseBrowser/trunk/dbBrowser-war/src/main/webapp/WEB-INF/jetspeed-portlet.xml (with props)
portals/applications/databaseBrowser/trunk/dbBrowser-war/src/main/webapp/WEB-INF/log4j.properties (with props)
portals/applications/databaseBrowser/trunk/dbBrowser-war/src/main/webapp/WEB-INF/portlet.tld (with props)
portals/applications/databaseBrowser/trunk/dbBrowser-war/src/main/webapp/WEB-INF/portlet.xml (with props)
portals/applications/databaseBrowser/trunk/dbBrowser-war/src/main/webapp/WEB-INF/view/
portals/applications/databaseBrowser/trunk/dbBrowser-war/src/main/webapp/WEB-INF/view/database-edit.vm
portals/applications/databaseBrowser/trunk/dbBrowser-war/src/main/webapp/WEB-INF/view/database-edit1.vm
portals/applications/databaseBrowser/trunk/dbBrowser-war/src/main/webapp/WEB-INF/view/database-help.vm
portals/applications/databaseBrowser/trunk/dbBrowser-war/src/main/webapp/WEB-INF/view/database-view.vm
portals/applications/databaseBrowser/trunk/dbBrowser-war/src/main/webapp/WEB-INF/view/status-include.vm
portals/applications/databaseBrowser/trunk/dbBrowser-war/src/main/webapp/WEB-INF/web.xml (with props)
portals/applications/databaseBrowser/trunk/dbBrowser-war/src/main/webapp/images/
portals/applications/databaseBrowser/trunk/dbBrowser-war/src/main/webapp/images/application-vnd.ms-excel.png (with props)
portals/applications/databaseBrowser/trunk/pom.xml (with props)
Added: portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/ActionParameter.java
URL: http://svn.apache.org/viewvc/portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/ActionParameter.java?rev=763970&view=auto
==============================================================================
--- portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/ActionParameter.java (added)
+++ portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/ActionParameter.java Fri Apr 10 16:16:18 2009
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.portals.applications.dbBrowser;
+
+import java.io.Serializable;
+
+/**
+ * Action Parameter
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
+ * @version $Id: ActionParameter.java 516448 2007-03-09 16:25:47Z ate $
+ *
+ */
+public class ActionParameter implements Serializable
+{
+ private static final long serialVersionUID = 1;
+
+ String name;
+
+ String action;
+
+ String type;
+
+ String page;
+
+ public ActionParameter(String name, String action, String type)
+ {
+ this.name = name;
+ if (type.equalsIgnoreCase("psml"))
+ {
+ int index = action.indexOf("/");
+ this.page = action.substring(0, index);
+ this.action = action.substring(index + 1);
+ } else
+ {
+ this.action = action;
+ }
+ this.type = type;
+ }
+
+ public String getName()
+ {
+ return this.name;
+ }
+
+ public String getPage()
+ {
+ return this.page;
+ }
+
+ public String getAction()
+ {
+ return this.action;
+ }
+
+ public String getType()
+ {
+ return this.type;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public void setAction(String action)
+ {
+ this.action = action;
+ }
+
+ public void setType(String type)
+ {
+ this.type = type;
+ }
+
+}
Propchange: portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/ActionParameter.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/Browser.java
URL: http://svn.apache.org/viewvc/portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/Browser.java?rev=763970&view=auto
==============================================================================
--- portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/Browser.java (added)
+++ portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/Browser.java Fri Apr 10 16:16:18 2009
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.portals.applications.dbBrowser;
+
+import java.util.List;
+
+import javax.portlet.RenderRequest;
+
+
+/**
+ * GemsBrowser - defines the inteface for Gems Browsers
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
+ * @version $Id: Browser.java 516448 2007-03-09 16:25:47Z ate $
+ */
+public interface Browser
+{
+ void getRows(RenderRequest request, String sql, int windowSize)
+ throws Exception;
+
+ boolean filter(List row, RenderRequest request);
+
+ public void populate(int rowIndex, int columnIndex, List row);
+
+}
\ No newline at end of file
Propchange: portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/Browser.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/BrowserIterator.java
URL: http://svn.apache.org/viewvc/portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/BrowserIterator.java?rev=763970&view=auto
==============================================================================
--- portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/BrowserIterator.java (added)
+++ portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/BrowserIterator.java Fri Apr 10 16:16:18 2009
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.portals.applications.dbBrowser;
+
+import java.io.Serializable;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * DatabaseBrowserPortlet
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
+ * @version $Id: BrowserIterator.java 516448 2007-03-09 16:25:47Z ate $
+ */
+public interface BrowserIterator extends Iterator, Comparator, Serializable
+{
+
+ /**
+ * This method returns the index of the row to which the cursor is pointing
+ * at.
+ *
+ */
+ public int getTop();
+
+ /**
+ * This method returns the window size.
+ *
+ */
+ public int getWindowSize();
+
+ /**
+ * This method returns the last index of the row in the window displayed.
+ *
+ */
+ public int getBottom();
+
+ /**
+ * This method points the cursor to the index provided.
+ *
+ * @param start
+ * Index to which cursor should point to
+ */
+ public void setTop(int start);
+
+ /**
+ * This method returns the result set vector.
+ *
+ */
+ public List getResultSet();
+
+ /**
+ * This method returns the number of rows in the result set.
+ *
+ */
+ public int getResultSetSize();
+
+ /**
+ * This method returns the List containg the column labels of the result
+ * set.
+ *
+ */
+ public List getResultSetTitleList();
+
+ /**
+ * This method returns the List containg the Types of the columns the result
+ * set.
+ *
+ * @see java.sql.Types
+ */
+ public List getResultSetTypesList();
+
+ /**
+ * This method sorts the result set according to the value of the column as
+ * specified by the parameter column name. Changes the order of the result
+ * set vector. If it is called on the same columnName more than once it
+ * toggles the ordering ie first it will be ascending, then it will be
+ * descending, then ascending and so on.
+ *
+ * @param String
+ * sortColumnName
+ */
+ public void sort(String sortColumnName);
+
+}
Propchange: portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/BrowserIterator.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/BrowserPortlet.java
URL: http://svn.apache.org/viewvc/portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/BrowserPortlet.java?rev=763970&view=auto
==============================================================================
--- portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/BrowserPortlet.java (added)
+++ portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/BrowserPortlet.java Fri Apr 10 16:16:18 2009
@@ -0,0 +1,515 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.portals.applications.dbBrowser;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Vector;
+
+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.PortletPreferences;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletSession;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.portals.bridges.velocity.GenericVelocityPortlet;
+import org.apache.portals.messaging.PortletMessaging;
+import org.apache.velocity.context.Context;
+
+/**
+ * AbstractBrowserPortlet
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
+ * @version $Id: BrowserPortlet.java 752495 2009-03-11 16:14:21Z vkumar $
+ */
+public class BrowserPortlet extends GenericVelocityPortlet implements Browser
+{
+ protected static final String SQL = "sql";
+ public static final String TABLE_NAME = "tableName";
+ public static final String CONDITIONS = "conditions";
+ public static final String Order_BY_COLUMNS = "orderByColumns";
+ public static final String COLUMNS = "columnNames";
+ protected static final String POOLNAME = "poolname";
+ protected static final String START = "start";
+ protected static final String FIND = "find";
+ protected static final String SEARCH_STRING = "searchString";
+ protected static final String SEARCH_COLUMN = "searchColumn";
+ protected static final String FILTERED = "filtered";
+ protected static final String FILTER = "filter";
+ protected static final String CUSTOMIZE_TEMPLATE = "customizeTemplate";
+ protected static final String WINDOW_SIZE = "WindowSize";
+ protected static final String USER_OBJECT_NAMES = "user-object-names";
+ protected static final String USER_OBJECT_TYPES = "user-object-types";
+ protected static final String USER_OBJECTS = "user-objects";
+ 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";
+ protected static final String ROW_LINK_TARGETS = "row-link-targets";
+ protected static final String TABLE_LINK_IDS = "table-link-ids";
+ protected static final String TABLE_LINK_TYPES = "table-link-types";
+ protected static final String TABLE_LINK_TARGETS = "table-link-targets";
+ protected static final String BROWSER_TABLE_SIZE = "tableSize";
+ protected static final String BROWSER_ACTION_KEY = "browser_action_key";
+ protected static final String BROWSER_ITERATOR = "table";
+ protected static final String BROWSER_TITLE_ITERATOR = "title";
+ protected static final String NEXT = "next";
+ protected static final String PREVIOUS = "prev";
+ protected static final String FIRST = "first";
+ protected static final String LAST = "last";
+ protected static final String VELOCITY_NULL_ENTRY = "-";
+ // portlet entry Id
+ protected static final String PEID = "js_peid";
+ protected static final String SORT_COLUMN_NAME = "js_dbcolumn";
+ protected static final String SORT_ORDER = "sortOrder";
+ protected List sqlParameters = new Vector();
+ /*
+ * SSO link
+ */
+ protected PortletContext context;
+
+ /**
+ * Static initialization of the logger for this class
+ */
+ protected Log log = LogFactory.getLog(BrowserPortlet.class);
+
+ public void init(PortletConfig config) throws PortletException
+ {
+ super.init(config);
+ context = getPortletContext();
+ }
+
+ public void getRows(RenderRequest request, String sql, int windowSize) throws Exception
+ {
+ }
+
+ public void getRows(RenderRequest request, String sql, int windowSize, String filter) throws Exception
+ {
+ }
+
+ public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException
+ {
+
+ int resultSetSize, next, prev, windowSize;
+ response.setContentType("text/html");
+ BrowserIterator iterator = getBrowserIterator(request);
+ Context context = this.getContext(request);
+ String sortColName = request.getParameter(SORT_COLUMN_NAME);
+ String sortorder = request.getParameter(SORT_ORDER);
+ int start = getStartVariable(request, START, sortColName, iterator);
+ PortletPreferences prefs = request.getPreferences();
+ windowSize = Integer.parseInt(prefs.getValue(WINDOW_SIZE, "10"));
+ StatusMessage message = (StatusMessage) PortletMessaging.consume(request, "DatabaseBrowserPortlet", "action");
+ if (sortorder==null)
+ {
+ sortorder = "DESC";
+ }
+ if (message != null)
+ {
+ this.getContext(request).put("statusMsg", message);
+ }
+ try
+ {
+ if (iterator == null)
+ {
+ String sql = getQueryString(request, context);
+ // System.out.println("buildNormalContext SQL: "+sql);
+ readUserParameters(request, context);
+ String filter = request.getParameter(FILTER);
+ if (filter != null)
+ getRows(request, sql, windowSize, filter);
+ else
+ getRows(request, sql, windowSize);
+ iterator = getBrowserIterator(request);
+ start = 0;
+ }
+ else
+ {
+ if (sortColName != null)
+ {
+ iterator.sort(sortColName);
+ }
+ }
+ resultSetSize = iterator.getResultSetSize();
+ if (start >= resultSetSize)
+ {
+ if ((start - windowSize) > 0)
+ start = resultSetSize - windowSize;
+ else
+ start = 0;
+ }
+ next = start + windowSize;
+ prev = start - windowSize;
+ if (prev < 0 && start > 0)
+ prev = 0;
+ iterator.setTop(start);
+ readLinkParameters(request, context);
+ if (iterator != null)
+ {
+ resultSetSize = iterator.getResultSetSize();
+ if (next < resultSetSize)
+ {
+ context.put(NEXT, String.valueOf(next));
+ }
+ if (prev <= resultSetSize && prev >= 0)
+ {
+ context.put(PREVIOUS, String.valueOf(prev));
+ }
+
+ context.put(BROWSER_ITERATOR, iterator);
+ context.put(BROWSER_TITLE_ITERATOR, iterator.getResultSetTitleList());
+ context.put(BROWSER_TABLE_SIZE, new Integer(resultSetSize));
+ context.put(WINDOW_SIZE, new Integer(windowSize));
+ context.put(START, new Integer(start));
+ if(sortorder.equals("ASC")){
+ context.put(SORT_ORDER, "DESC");
+ }else{
+ context.put(SORT_ORDER, "ASC");
+ }
+
+ /*
+ * System.out.println("buildNormalContext Sort column name= "+sortColName); System.out.println("buildNormalContext Iterator:
+ * "+iterator); System.out.println("buildNormalContext Titles= "+iterator.getResultSetTitleList()); System.out.println("buildNormalContext
+ * windowSize="+windowSize+" prev="+prev+ " next="+next+" start="+start+" resultSetSize="+resultSetSize);
+ */
+ }
+ }
+ catch (Exception e)
+ {
+ String msg = e.toString();
+ Throwable cause = e.getCause();
+ if (cause != null)
+ {
+ msg = msg + ", " + cause.getMessage();
+ }
+ context.put("statusMsg", new StatusMessage(msg, StatusMessage.ERROR));
+ // log the error msg
+ log.error("Exception", e);
+ /*
+ * TODO: error logging rundata.setMessage("Error in Portals Gems Browser: " + e.toString()); rundata.setStackTrace(StringUtils.stackTrace(e), e);
+ * rundata.setScreenTemplate(JetspeedResources.getString("template.error","Error"));
+ */
+ }
+ super.doView(request, response);
+ }
+
+ public void doEdit(RenderRequest request, RenderResponse response) throws PortletException, IOException
+ {
+ response.setContentType("text/html");
+ doPreferencesEdit(request, response);
+ }
+
+ public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException
+ {
+ if (request.getPortletMode() == PortletMode.EDIT)
+ {
+ processPreferencesAction(request, response);
+ clearBrowserIterator(request);
+ }
+ else
+ {
+ String browserAction = request.getParameter("db.browser.action");
+ if (browserAction != null)
+ {
+ if (browserAction.equals("refresh"))
+ {
+ clearBrowserIterator(request);
+ }
+ String start = request.getParameter(START);
+ if (start != null)
+ {
+ response.setRenderParameter(START, start);
+ }
+ String searchString = request.getParameter(SEARCH_STRING);
+ if (searchString != null)
+ {
+ String searchColumn = request.getParameter(SEARCH_COLUMN);
+ String filtered = request.getParameter(FILTERED);
+ if (filtered != null)
+ {
+ clearBrowserIterator(request);
+ response.setRenderParameter(FILTER, searchString);
+ }
+ else
+ {
+ int index = find(this.getBrowserIterator(request), searchString, searchColumn);
+ if (index == -1)
+ {
+ try
+ {
+ StatusMessage sm = new StatusMessage("Could not find match for: " + searchString, StatusMessage.ALERT);
+ PortletMessaging.publish(request, "DatabaseBrowserPortlet", "action", sm);
+ }
+ catch (Exception e)
+ {
+ }
+ }
+ else
+ {
+ response.setRenderParameter(START, Integer.toString(index));
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Centralizes the calls to session - to retrieve the BrowserIterator.
+ *
+ * @param data
+ * The turbine rundata context for this request.
+ */
+ protected BrowserIterator getBrowserIterator(PortletRequest request)
+ {
+ BrowserIterator iterator = (BrowserIterator) request.getPortletSession().getAttribute(BROWSER_ACTION_KEY, PortletSession.PORTLET_SCOPE);
+ return iterator;
+ }
+
+ /**
+ * Centralizes the calls to session - to set the BrowserIterator.
+ *
+ * @param data
+ * The turbine rundata context for this request.
+ * @param iterator
+ * .
+ */
+ protected void setBrowserIterator(RenderRequest request, BrowserIterator iterator)
+ {
+ request.getPortletSession().setAttribute(BROWSER_ACTION_KEY, iterator);
+ }
+
+ /**
+ * Centralizes the calls to session - to clear the BrowserIterator from the temp storage.
+ *
+ * @param data
+ * The turbine rundata context for this request.
+ */
+ protected void clearBrowserIterator(PortletRequest request)
+ {
+ request.getPortletSession().removeAttribute(BROWSER_ACTION_KEY);
+ }
+
+ protected int getStartVariable(RenderRequest request, String attrName, String sortColName, BrowserIterator iterator)
+ {
+ int start = -1;
+ // if users want to overwrite how the sorting affects the cursor for
+ // the window
+ if (sortColName != null)
+ start = getStartIndex();
+ if (start < 0)
+ {
+ // fallback routine for start
+ String startStr = request.getParameter(attrName);
+ if (startStr != null && startStr.length() > 0)
+ {
+ try
+ {
+ start = Integer.parseInt(startStr);
+ }
+ catch (Exception e)
+ {
+ if (iterator != null)
+ start = iterator.getTop();
+ else
+ start = 0;
+ }
+ }
+ else if (start == -1 && iterator != null)
+ {
+ start = iterator.getTop();
+ }
+ if (start < 0)
+ start = 0;
+ }
+ return start;
+ }
+
+ /**
+ * to be used if sorting behavior to be overwritten
+ */
+ protected int getStartIndex()
+ {
+ return 0;
+ }
+
+ /**
+ * This method returns the sql from the getQuery method which can be overwritten according to the needs of the application. If the getQuery() returns null,
+ * then it gets the value from the psml file. If the psml value is null then it returns the value from the xreg file.
+ */
+ protected String getQueryString(RenderRequest request, Context context)
+ {
+ String sql = getQueryString(request);
+ if (null == sql)
+ {
+ sql = getPreference(request, SQL, null);
+ }
+ return sql;
+ }
+
+ public String getQueryString(PortletRequest request)
+ {
+ return null;
+ }
+
+ protected String getPreference(PortletRequest request, String attrName, String attrDefValue)
+ {
+ return request.getPreferences().getValue(attrName, attrDefValue);
+ }
+
+ protected void readUserParameters(RenderRequest request, Context context)
+ {
+ Object userObjRead = request.getPortletSession().getAttribute(USER_OBJECTS, PortletSession.PORTLET_SCOPE);
+ if (userObjRead != null)
+ {
+ context.put(USER_OBJECTS, userObjRead);
+ // System.out.println("userObjectListSize: "+
+ // ((List)userObjRead).size());
+ }
+ else
+ {
+ /*
+ * TODO: implement user parameters String userObjTypes= getParameterFromRegistry(portlet,USER_OBJECT_TYPES,null); String userObjNames=
+ * getParameterFromRegistry(portlet,USER_OBJECT_NAMES,null); if( userObjTypes != null && userObjTypes.length() > 0 ) { userObjectList = new
+ * ArrayList(); int userObjectIndex = 0; StringTokenizer tokenizer1 = new StringTokenizer(userObjNames, ","); StringTokenizer tokenizer3 = new
+ * StringTokenizer(userObjTypes, ","); while(tokenizer1.hasMoreTokens() && tokenizer3.hasMoreTokens()) { userObjectList.add(userObjectIndex, new
+ * ActionParameter(tokenizer1.nextToken(), null, tokenizer3.nextToken())); userObjectIndex++; } context.put(USER_OBJECTS, userObjectList);
+ * setParameterToTemp(portlet, rundata, USER_OBJECTS, userObjectList); //System.out.println("readLink: userObjectTypesListSize:
+ * "+userObjectList.size()); }
+ */
+ }
+ }
+
+ protected void readSqlParameters(PortletRequest request)
+ {
+ List sqlParamList = null;
+ int i = 1;
+ while (true)
+ {
+ String param = getPreference(request, SQL_PARAM_PREFIX + i, null);
+ if (param == null)
+ {
+ break;
+ }
+ else
+ {
+ if (sqlParamList == null)
+ {
+ sqlParamList = new ArrayList();
+ }
+ sqlParamList.add(param);
+ }
+ i++;
+ }
+ if (sqlParamList != null)
+ {
+ setSQLParameters(sqlParamList);
+ }
+ }
+
+ public void setSQLParameters(List parameters)
+ {
+ this.sqlParameters = parameters;
+ }
+
+ protected void readLinkParameters(RenderRequest request, Context context)
+ {
+ // TODO: implement me
+ }
+
+ /**
+ * This method should be overwritten every time the user object needs to be populated with some user specific constraints. As an example if the user wanted
+ * to track the parent of an object based on some calculation per row, it could be done here.
+ */
+ public void populate(int rowIndex, int columnIndex, List row)
+ {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.jetspeed.modules.actions.portlets.browser.BrowserQuery#filter(java.util.List, RunData)
+ */
+ public boolean filter(List row, RenderRequest request)
+ {
+ return false;
+ }
+
+ public void publishStatusMessage(PortletRequest request, String portlet, String topic, Throwable e, String message)
+ {
+ String msg = message + ": " + e.toString();
+ Throwable cause = e.getCause();
+ if (cause != null)
+ {
+ msg = msg + ", " + cause.getMessage();
+ }
+ StatusMessage sm = new StatusMessage(msg, StatusMessage.ERROR);
+ try
+ {
+ // TODO: fixme, bug in Pluto on portlet session
+ PortletMessaging.publish(request, portlet, topic, sm);
+ }
+ catch (Exception ee)
+ {
+ System.err.println("Failed to publish message: " + e);
+ }
+ }
+
+ public int find(BrowserIterator iterator, String searchString, String searchColumn)
+ {
+ int index = 0;
+ int column = 1;
+ if (searchColumn != null)
+ column = Integer.parseInt(searchColumn);
+ Iterator it = iterator.getResultSet().iterator();
+ while (it.hasNext())
+ {
+ Object row = it.next();
+ String item = "";
+ if (row instanceof String)
+ item = (String) row;
+ else if (row instanceof List)
+ {
+ // TODO: this only works on String columns
+ item = (String) ((List) row).get(column);
+ }
+ if (item.startsWith(searchString))
+ {
+ return index;
+ }
+ index++;
+ }
+ return -1;
+ }
+
+ public List getTitleList(PortletRequest request)
+ {
+ return null;
+ }
+}
\ No newline at end of file
Propchange: portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/BrowserPortlet.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/DatabaseBrowserIterator.java
URL: http://svn.apache.org/viewvc/portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/DatabaseBrowserIterator.java?rev=763970&view=auto
==============================================================================
--- portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/DatabaseBrowserIterator.java (added)
+++ portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/DatabaseBrowserIterator.java Fri Apr 10 16:16:18 2009
@@ -0,0 +1,363 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.portals.applications.dbBrowser;
+
+import java.sql.Types;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * A class for iterating over the window. The window constitutes the selection
+ * of rows being displayed to the user from the List storing all the ResultSet.
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
+ * @version $Id: DatabaseBrowserIterator.java 517121 2007-03-12 07:45:49Z ate $
+ */
+public class DatabaseBrowserIterator implements BrowserIterator
+{
+ private static final long serialVersionUID = 1;
+
+ /**
+ * Static initialization of the logger for this class
+ */
+ transient protected Log log = LogFactory.getLog(DatabaseBrowserIterator.class);
+
+ private static final String VELOCITY_NULL_ENTRY = "-";
+
+ int top = 0;
+
+ int index = 0;
+
+ int bottom = -1;
+
+ int windowSize = -1;
+
+ int rsListSize = -1;
+
+ boolean ascendingOrder = true;
+
+ String sortColumnName = null;
+
+ List rsList;
+
+ List rsTitleList;
+
+ List rsTypeList;
+
+ /**
+ * Constructor for the database browser iterator
+ *
+ * @param result
+ * The List containg all the rows from the resultSet.
+ * @param columnTitles
+ * The List containg all the columnLabels from a resultSet.
+ * @param pageSize
+ * The number of rows to be displayed in a window configured by
+ * the user.
+ */
+ public DatabaseBrowserIterator(List result, List columnTitles,
+ List columnTypes, int pageSize)
+ {
+ this.rsList = result;
+ this.rsTitleList = columnTitles;
+ this.rsTypeList = columnTypes;
+ this.windowSize = pageSize;
+ this.rsListSize = result.size();
+ setBottom();
+ }
+
+ /**
+ * This method returns the result set.
+ *
+ */
+ public List getResultSet()
+ {
+ return rsList;
+ }
+
+ /**
+ * This method returns the number of rows in the result set.
+ *
+ */
+ public int getResultSetSize()
+ {
+ return rsListSize;
+ }
+
+ /**
+ * This method returns the List containg the column labels of the result
+ * set.
+ *
+ */
+ public List getResultSetTitleList()
+ {
+ return rsTitleList;
+ }
+
+ /**
+ * This method returns the List containg the column type names of the result
+ * set.
+ *
+ * @see java.sql.Types
+ */
+ public List getResultSetTypesList()
+ {
+ return rsTypeList;
+ }
+
+ /**
+ * This method returns the index of the row to which the cursor is pointing
+ * at.
+ *
+ */
+ public int getTop()
+ {
+ return top;
+ }
+
+ /**
+ * This method points the cursor to the index provided.
+ *
+ * @param start
+ * Index to which cursor should point to
+ */
+ public void setTop(int start)
+ {
+ top = start;
+ index = top;
+ setBottom();
+ }
+
+ /**
+ * This method returns the last index of the row in the window displayed.
+ *
+ */
+ public int getBottom()
+ {
+ return bottom;
+ }
+
+ /**
+ * This method returns the window size.
+ *
+ */
+ public int getWindowSize()
+ {
+ return windowSize;
+ }
+
+ /**
+ * This method sets the bottom based on which index the cursor points to and
+ * the size of the result set.
+ *
+ */
+ private void setBottom()
+ {
+ bottom = top + windowSize;
+ if (bottom > rsListSize)
+ {
+ bottom = rsListSize;
+ }
+ }
+
+ /**
+ * Returns true if the iteration has more elements
+ */
+ public boolean hasNext()
+ {
+ if (index <= rsListSize && index < bottom) { return true; }
+ return false;
+ }
+
+ /**
+ * Returns the next element in the iteration
+ */
+ public Object next()
+ {
+ index = index + 1;
+ return rsList.get(index - 1);
+ }
+
+ /**
+ * Logs as info - since remove operation is not supported by this Iterator.
+ */
+ public void remove()
+ {
+ log.info("The remove operation is not supported.");
+ }
+
+ /**
+ * This method sorts the result set according to the value of the column as
+ * specified by the parameter column name. Changes the order of the result
+ * set vector.
+ *
+ * @param String
+ * sortColumnName
+ */
+ public void sort(String columnName)
+ {
+ //System.out.println("current columnName="+columnName);
+ //System.out.println("old columnName="+sortColumnName);
+ if (columnName != null)
+ {
+ if (sortColumnName != null && sortColumnName.equals(columnName))
+ {
+ ascendingOrder = !ascendingOrder;
+ } else
+ {
+ ascendingOrder = true;
+ sortColumnName = columnName;
+ }
+ Collections.sort(rsList, this);
+ }
+ }
+
+ /*
+ * Compares its two arguments for order.
+ *
+ */
+ public int compare(Object obj1, Object obj2)
+ {
+ int idx = rsTitleList.indexOf(sortColumnName);
+ int order = 0;
+
+ if (idx != -1)
+ {
+ Object col1 = null;
+ Object col2 = null;
+
+ if (obj1 instanceof String)
+ {
+ col1 = obj1;
+ col2 = obj2;
+ }
+ else if (obj1 instanceof List)
+ {
+ col1 = ((List) obj1).get(idx);
+ col2 = ((List) obj2).get(idx);
+ }
+
+ if ((col1).equals(VELOCITY_NULL_ENTRY))
+ {
+ if ((col2).equals(VELOCITY_NULL_ENTRY))
+ {
+ order = 0;
+ } else
+ {
+ order = -1;
+ }
+ } else if ((col2).equals(VELOCITY_NULL_ENTRY))
+ {
+ order = 1;
+ } else
+ {
+ int type = Integer.parseInt((String) rsTypeList.get(idx));
+ switch (type)
+ {
+
+ case Types.NUMERIC:
+ order = (((java.math.BigDecimal) col1)
+ .compareTo((java.math.BigDecimal) col2));
+ break;
+
+ case Types.DECIMAL:
+ order = (((java.math.BigDecimal) col1)
+ .compareTo((java.math.BigDecimal) col2));
+ break;
+
+ case Types.TINYINT:
+ order = (((Byte) col1).compareTo((Byte) col2));
+ break;
+
+ case Types.SMALLINT:
+ order = (((Short) col1).compareTo((Short) col2));
+ break;
+
+ case Types.INTEGER:
+ order = (((Integer) col1).compareTo((Integer) col2));
+ break;
+
+ case Types.BIGINT:
+ order = (((Long) col1).compareTo((Long) col2));
+ break;
+
+ case Types.REAL:
+ order = (((Float) col1).compareTo((Float) col2));
+ break;
+
+ case Types.FLOAT:
+ order = (((Double) col1).compareTo((Double) col2));
+ break;
+
+ case Types.DOUBLE:
+ order = (((Double) col1).compareTo((Double) col2));
+ break;
+
+ case Types.DATE:
+ order = (((java.sql.Date) col1)
+ .compareTo((java.sql.Date) col2));
+ break;
+
+ case Types.TIME:
+ order = (((java.sql.Time) col1)
+ .compareTo((java.sql.Time) col2));
+ break;
+
+ case Types.TIMESTAMP:
+ order = (((java.sql.Timestamp) col1)
+ .compareTo((java.sql.Timestamp) col2));
+ break;
+
+ case Types.CHAR:
+ order = (((String) col1).compareTo((String) col2));
+ break;
+
+ case Types.VARCHAR:
+ order = (((String) col1).compareTo((String) col2));
+ break;
+
+ case Types.LONGVARCHAR:
+ order = (((String) col1).compareTo((String) col2));
+ break;
+
+ default:
+ log
+ .info("DatabaseBrowserIterator.compare DataType mapping not found"
+ + " in DatabaseBrowserIterator. "
+ + "Hence cannot sort based on provided column.");
+ break;
+ }
+ }
+ }
+ //System.out.println("index of type= "+idx +", order= "+order+",
+ // ascending= "+ascendingOrder);
+ if (!ascendingOrder)
+ {
+ order = 0 - order;
+ }
+ return order;
+ }
+
+ public boolean getAscendingOrder()
+ {
+ return ascendingOrder;
+ }
+
+}
Propchange: portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/DatabaseBrowserIterator.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/DatabaseBrowserPortlet.java
URL: http://svn.apache.org/viewvc/portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/DatabaseBrowserPortlet.java?rev=763970&view=auto
==============================================================================
--- portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/DatabaseBrowserPortlet.java (added)
+++ portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/DatabaseBrowserPortlet.java Fri Apr 10 16:16:18 2009
@@ -0,0 +1,952 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.portals.applications.dbBrowser;
+
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.lang.reflect.Method;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.Types;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletException;
+import javax.portlet.PortletMode;
+import javax.portlet.PortletPreferences;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletSession;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.ResourceRequest;
+import javax.portlet.ResourceResponse;
+import javax.sql.DataSource;
+
+import org.apache.commons.dbcp.BasicDataSource;
+import org.apache.commons.lang.StringUtils;
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFRow;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.portals.bridges.util.PreferencesHelper;
+import org.apache.portals.messaging.PortletMessaging;
+
+/**
+ * DatabaseBrowserPortlet
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
+ * @version $Id: DatabaseBrowserPortlet.java 748566 2009-02-27 15:57:03Z vkumar $
+ */
+public class DatabaseBrowserPortlet extends BrowserPortlet implements Browser
+{
+ private static final String COLUMNS_TITLE = "columnTitles";
+ 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[] colNames;
+ private SimpleDateFormat date_output;
+ private static final String DATE_OUTPUT_PATTERN = "M/d/yyyy HH:mm:ss z";
+ BrowserIterator dataBaseIterator;
+ private String BLANK_STRING_ARRAY[] = new String[0];
+ private static final int BLOCK_SIZE = 4096;
+
+ public BrowserIterator getLocalIterators(PortletRequest request, String sql, int windowSize) throws Exception
+ {
+ BrowserIterator iterator;
+ List resultSetList = new ArrayList();
+ List resultSetTitleList = new ArrayList();
+ List resultSetTypeList = new ArrayList();
+ Connection con = null;
+ PreparedStatement selectStmt = null;
+ ResultSet rs = null;
+ PortletSession session = request.getPortletSession();
+ try
+ {
+ String poolname = request.getPreferences().getValue(POOLNAME, null);
+ if (poolname == null || poolname.length() == 0)
+ {
+ con = getConnection(request);
+ }
+ else
+ {
+ con = getConnection(poolname);
+ }
+ selectStmt = con.prepareStatement(sql);
+ readSqlParameters(request);
+ Iterator it = sqlParameters.iterator();
+ int ix = 0;
+ while (it.hasNext())
+ {
+ ix++;
+ Object object = it.next();
+ selectStmt.setObject(ix, object);
+ }
+ rs = selectStmt.executeQuery();
+ ResultSetMetaData rsmd = rs.getMetaData();
+ int columnNum = rsmd.getColumnCount();
+ /*
+ * get the user object types to be displayed and add them to the title list as well as the result set list
+ */
+ List userObjList = (List) session.getAttribute(USER_OBJECTS);
+ int userObjListSize = 0;
+ if (userObjList != null)
+ {
+ userObjListSize = userObjList.size();
+ }
+ // System.out.println("User List Size = "+ userObjListSize);
+ /*SSOProvider
+ * the array columnDisplayed maintains a boolean value for each column index. Only the columns that are set to true are added to the resultSetList,
+ * resultSetTitleList and resultSetTypeList.
+ */
+ boolean[] columnDisplayed = new boolean[columnNum + userObjListSize];
+ /*
+ * this for loop constructs the columnDisplayed array as well as adds to the resultSetTitleList and resultSetTypeList
+ */
+ for (int i = 1; i <= columnNum; i++)
+ {
+ int type = rsmd.getColumnType(i);
+ if (!((type == Types.BLOB) || (type == Types.CLOB) || (type == Types.BINARY) || (type == Types.LONGVARBINARY) || (type == Types.VARBINARY)))
+ {
+ resultSetTitleList.add(rsmd.getColumnName(i));
+ resultSetTypeList.add(String.valueOf(type));
+ columnDisplayed[i - 1] = true;
+ }
+ else
+ {
+ columnDisplayed[i - 1] = false;
+ }
+ }
+ for (int i = columnNum; i < columnNum + userObjListSize; i++)
+ {
+ ActionParameter usrObj = (ActionParameter) userObjList.get(i - columnNum);
+ resultSetTitleList.add(usrObj.getName());
+ resultSetTypeList.add(usrObj.getType());
+ columnDisplayed[i] = true;
+ // System.out.println("User List Name = "+ usrObj.getName()+"
+ // Type = "+usrObj.getType());
+ }
+ /*
+ * this while loop adds each row to the resultSetList
+ */
+ int index = 0;
+ while (rs.next())
+ {
+ List row = new ArrayList(columnNum);
+ for (int i = 1; i <= columnNum; i++)
+ {
+ if (columnDisplayed[i - 1])
+ {
+ Object obj = rs.getObject(i);
+ if (obj == null)
+ {
+ obj = VELOCITY_NULL_ENTRY;
+ }
+ row.add(obj);
+ }
+ }
+ for (int i = columnNum; i < columnNum + userObjListSize; i++)
+ {
+ ActionParameter usrObj = (ActionParameter) userObjList.get(i - columnNum);
+ if (columnDisplayed[i])
+ {
+ Class c = Class.forName(usrObj.getType());
+ row.add(c.newInstance());
+ populate(index, i, row);
+ }
+ }
+ resultSetList.add(row);
+ index++;
+ }
+ if (windowSize == -1)
+ {
+ iterator = new DatabaseBrowserIterator(resultSetList, resultSetTitleList, resultSetTypeList, resultSetList.size());
+ }
+ else
+ {
+ iterator = new DatabaseBrowserIterator(resultSetList, resultSetTitleList, resultSetTypeList, windowSize);
+ }
+ }
+ catch (SQLException e)
+ {
+ throw e;
+ }
+ finally
+ {
+ try
+ {
+ if (null != selectStmt)
+ selectStmt.close();
+ if (null != rs)
+ rs.close();
+ if (null != con) // closes con also
+ {
+ closeConnection(con);
+ }
+ }
+ catch (Exception e)
+ {
+ throw e;
+ }
+ }
+ return iterator;
+ }
+
+ /**
+ * Execute the sql statement as specified by the user or the default, and store the resultSet in a vector.
+ *
+ * @param sqlt
+ * The sql statement to be executed.
+ * @param data
+ * The turbine rundata context for this request.
+ */
+ public void getRows(RenderRequest request, String sql, int windowSize) throws Exception
+ {
+ List resultSetList = new ArrayList();
+ List resultSetTitleList = new ArrayList();
+ List resultSetTypeList = new ArrayList();
+ Connection con = null;
+ PreparedStatement selectStmt = null;
+ ResultSet rs = null;
+ PortletSession session = request.getPortletSession();
+ try
+ {
+ String poolname = getPreference(request, POOLNAME, null);
+ if (poolname == null || poolname.length() == 0)
+ {
+ con = getConnection(request);
+ }
+ else
+ {
+ con = getConnection(poolname);
+ }
+ selectStmt = con.prepareStatement(sql);
+ readSqlParameters(request);
+ Iterator it = sqlParameters.iterator();
+ int ix = 0;
+ while (it.hasNext())
+ {
+ ix++;
+ Object object = it.next();
+ selectStmt.setObject(ix, object);
+ }
+ rs = selectStmt.executeQuery();
+ ResultSetMetaData rsmd = rs.getMetaData();
+ int columnNum = rsmd.getColumnCount();
+ /*
+ * get the user object types to be displayed and add them to the title list as well as the result set list
+ */
+ List userObjList = (List) session.getAttribute(USER_OBJECTS);
+ int userObjListSize = 0;
+ if (userObjList != null)
+ {
+ userObjListSize = userObjList.size();
+ }
+ // System.out.println("User List Size = "+ userObjListSize);
+ /*
+ * the array columnDisplayed maintains a boolean value for each column index. Only the columns that are set to true are added to the resultSetList,
+ * resultSetTitleList and resultSetTypeList.
+ */
+ boolean[] columnDisplayed = new boolean[columnNum + userObjListSize];
+ /*
+ * this for loop constructs the columnDisplayed array as well as adds to the resultSetTitleList and resultSetTypeList
+ */
+ for (int i = 1; i <= columnNum; i++)
+ {
+ int type = rsmd.getColumnType(i);
+ if (!((type == Types.BLOB) || (type == Types.CLOB) || (type == Types.BINARY) || (type == Types.LONGVARBINARY) || (type == Types.VARBINARY)))
+ {
+ resultSetTitleList.add(rsmd.getColumnName(i));
+ resultSetTypeList.add(String.valueOf(type));
+ columnDisplayed[i - 1] = true;
+ }
+ else
+ {
+ columnDisplayed[i - 1] = false;
+ }
+ }
+ for (int i = columnNum; i < columnNum + userObjListSize; i++)
+ {
+ ActionParameter usrObj = (ActionParameter) userObjList.get(i - columnNum);
+ resultSetTitleList.add(usrObj.getName());
+ resultSetTypeList.add(usrObj.getType());
+ columnDisplayed[i] = true;
+ // System.out.println("User List Name = "+ usrObj.getName()+"
+ // Type = "+usrObj.getType());
+ }
+ /*
+ * this while loop adds each row to the resultSetList
+ */
+ int index = 0;
+ while (rs.next())
+ {
+ List row = new ArrayList(columnNum);
+ for (int i = 1; i <= columnNum; i++)
+ {
+ if (columnDisplayed[i - 1])
+ {
+ Object obj = rs.getObject(i);
+ if (obj == null)
+ {
+ obj = VELOCITY_NULL_ENTRY;
+ }
+ row.add(obj);
+ }
+ }
+ for (int i = columnNum; i < columnNum + userObjListSize; i++)
+ {
+ ActionParameter usrObj = (ActionParameter) userObjList.get(i - columnNum);
+ if (columnDisplayed[i])
+ {
+ Class c = Class.forName(usrObj.getType());
+ row.add(c.newInstance());
+ populate(index, i, row);
+ }
+ }
+ if (filter(row, request))
+ {
+ continue;
+ }
+ resultSetList.add(row);
+ index++;
+ }
+ BrowserIterator iterator = new DatabaseBrowserIterator(resultSetList, resultSetTitleList, resultSetTypeList, windowSize);
+ setBrowserIterator(request, iterator);
+ }
+ catch (SQLException e)
+ {
+ throw e;
+ }
+ finally
+ {
+ try
+ {
+ if (null != selectStmt)
+ selectStmt.close();
+ if (null != rs)
+ rs.close();
+ if (null != con) // closes con also
+ {
+ closeConnection(con);
+ }
+ }
+ catch (Exception e)
+ {
+ throw e;
+ }
+ }
+ }
+
+ /*
+ * Connection Management
+ */
+ public Connection getConnection(PortletRequest request) throws Exception
+ {
+ Connection con = null;
+ try
+ {
+ PortletPreferences prefs = request.getPreferences();
+ String dsType = prefs.getValue("DatasourceType", null);
+ if (dsType == null)
+ {
+ throw new SQLException("No DataSource provided");
+ }
+ if (dsType.equals("jndi"))
+ {
+ Context ctx = new InitialContext();
+ String dsName = prefs.getValue("JndiDatasource", "");
+ Context envContext = (Context) ctx.lookup("java:/comp/env");
+ DataSource ds = (DataSource) envContext.lookup(dsName);
+ con = ds.getConnection();
+ }
+ else if (dsType.equals("dbcp"))
+ {
+ BasicDataSource ds = new BasicDataSource();
+ ds.setDriverClassName(prefs.getValue("JdbcDriver", ""));
+ ds.setUrl(prefs.getValue("JdbcConnection", ""));
+ ds.setUsername(prefs.getValue("JdbcUsername", ""));
+ ds.setPassword(prefs.getValue("JdbcPassword", ""));
+ // ds.setUrl("jdbc:mysql://j2-server/j2");
+ con = ds.getConnection();
+ }
+ else
+ {
+ throw new SQLException("No DataSource provided");
+ }
+ }
+ catch (Exception e)
+ {
+ throw new Exception("Failed to connect", e); // TODO: complete this
+ }
+ return con;
+ }
+
+ private Method[] getResultMethods(List types)
+ {
+ Method beanMethods[] = new Method[types.size()];
+ int type;
+ for (int index = 0; index < beanMethods.length; index++)
+ {
+ type = Integer.parseInt((String) types.get(index));
+ switch (type)
+ {
+ case Types.DATE:
+ //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 });
+ break;
+ case Types.CHAR:
+ //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 });
+ break;
+ case Types.FLOAT:
+ //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 });
+ break;
+ }
+ }
+ return beanMethods;
+ }
+
+ public Connection getConnection(String poolName)
+ {
+ return null;
+ }
+
+ public void closeConnection(Connection con)
+ {
+ try
+ {
+ if (con != null)
+ con.close();
+ }
+ catch (SQLException e)
+ {
+ log.error("Cant close connection", e);
+ }
+ }
+
+ public void serveResource(ResourceRequest request, ResourceResponse response)
+ throws PortletException, IOException
+ {
+ String exportParam = request.getParameter(EXPORT_TYPE);
+ String xlsFileName = "thedata.xls";
+ String fileName = "";
+ if (!StringUtils.isEmpty(exportParam))
+ {
+ if (exportParam.equals(XLS_EXPORT))
+ {
+ try
+ {
+ dataBaseIterator = getLocalIterators(request, getQueryString(request), -1);
+ HSSFWorkbook excelWorkbook = generateExcel(dataBaseIterator.getResultSet(), getColumNames(request),
+ (String[]) getTitleList(request).toArray(new String[getTitleList(request).size()]),
+ getResultMethods(dataBaseIterator.getResultSetTypesList()));
+ if (excelWorkbook != null)
+ {
+ response.setContentType("application/octet-stream");
+ response.setProperty("Content-Disposition", "attachment; filename=export.xls");
+ response.getPortletOutputStream().write(excelWorkbook.getBytes());
+ }
+ }
+ catch (Exception e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ else if (exportParam.equals(XML_EXPORT))
+ {
+ }
+
+ /*RequestContext jsReqContext = (RequestContext) request.getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE);
+ response.sendRedirect(request.getContextPath().replace(
+ request.getContextPath(),
+ jsReqContext.getPortalURL().getBasePath().subSequence(
+ 0,
+ jsReqContext.getPortalURL()
+ .getBasePath()
+ .lastIndexOf("/"))) +
+ "/fileserver/content?file=" + userName + "_" + fileName);*/
+
+ }
+ }
+
+ 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");
+ if (msg != null)
+ {
+ this.getContext(request).put("statusMsg", msg);
+ }
+ String editAction = request.getParameter("configPage");
+ if (editAction != null && editAction.equals("configPage1"))
+ {
+ try
+ {
+ con = getConnection(request);
+ fillColumnDropDown(con, request);
+ getContext(request).put("cols", getColNames());
+ getContext(request).put("colTitle", getTitleList(request));
+ getContext(request).put("colName", getColumNames(request));
+ getContext(request).put("sortCols", getSortColums(request));
+ }
+ catch (Exception e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ finally
+ {
+ this.closeConnection(con);
+ }
+ request.setAttribute("EditPage", "/WEB-INF/view/database-edit1.vm");
+ }
+ else
+ {
+ try
+ {
+ con = getConnection(request);
+ tableList = getTables(request, con);
+ }
+ catch (Exception e)
+ {
+ // TODO: handle exception
+ }
+ if (tableList != null && tableList.size() > 0)
+ {
+ getContext(request).put(TABLE_LIST, tableList);
+ }
+ }
+ super.doEdit(request, response);
+ }
+
+ public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException
+ {
+ String userName = "";
+ if (request.getPortletMode() == PortletMode.EDIT)
+ {
+ String test = request.getParameter("Test");
+ if (test != null && test.equals("Test"))
+ {
+ Connection con = null;
+ try
+ {
+ PortletPreferences prefs = request.getPreferences();
+ PreferencesHelper.requestParamsToPreferences(request);
+ prefs.store();
+ con = getConnection(request);
+ StatusMessage msg = new StatusMessage("Connection made successfully.", StatusMessage.SUCCESS);
+ PortletMessaging.publish(request, "DatabaseBrowserPortlet", "dbConnectTest", msg);
+ }
+ catch (Exception e)
+ {
+ String msg = e.toString();
+ Throwable cause = e.getCause();
+ if (cause != null)
+ {
+ msg = msg + ", " + cause.getMessage();
+ }
+ StatusMessage sm = new StatusMessage(msg, StatusMessage.ERROR);
+ PortletMessaging.publish(request, "DatabaseBrowserPortlet", "dbConnectTest", sm);
+ }
+ finally
+ {
+ this.closeConnection(con);
+ }
+ response.setPortletMode(PortletMode.EDIT);
+ return;
+ }
+ String editAction = request.getParameter("configPage");
+ if (editAction != null)
+ {
+ 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;
+ }
+ else if (editAction.equals("save"))
+ {
+ PortletPreferences prefs = request.getPreferences();
+ PreferencesHelper.requestParamsToPreferences(request);
+ prefs.store();
+ response.setPortletMode(PortletMode.VIEW);
+ }
+ }
+ }
+ super.processAction(request, response);
+ }
+
+ private void drain(InputStream r, OutputStream w) throws IOException
+ {
+ byte[] bytes = new byte[4096];
+ try
+ {
+ int length = r.read(bytes);
+ while (length != -1)
+ {
+ if (length != 0)
+ {
+ w.write(bytes, 0, length);
+ }
+ length = r.read(bytes);
+ }
+ }
+ finally
+ {
+ bytes = null;
+ }
+ }
+ private String[] getColNames()
+ {
+ return colNames;
+ }
+
+ public String[] getResultSetTitleList(RenderRequest request, String[] columnNames)
+ {
+ String[] columnsNames = request.getPreferences().getValues(COLUMNS_TITLE, columnNames);
+ return columnsNames;
+ }
+
+ private void fillColumnDropDown(Connection con, RenderRequest request)
+ {
+ String tableName;
+ try
+ {
+ if (!StringUtils.isEmpty(request.getParameter(TABLE_NAME)))
+ {
+ tableName = request.getParameter(TABLE_NAME);
+ }
+ else
+ {
+ tableName = request.getPreferences().getValue(TABLE_NAME, "");
+ }
+ Statement stmt = con.createStatement();
+ ResultSet set = stmt.executeQuery("select * from " + tableName);
+ ResultSetMetaData meta = set.getMetaData();
+ int ColumnCount = meta.getColumnCount();
+ List colums = new ArrayList();
+ for (int index = 1; index <= ColumnCount; index++)
+ {
+ colums.add(meta.getColumnName(index));
+ }
+ this.colNames = new String[colums.size()];
+ colums.toArray((String[]) this.colNames);
+ }
+ catch (Exception e)
+ {
+ // TODO: handle exception
+ }
+ }
+
+ public List getTitleList(PortletRequest request)
+ {
+ String titles = null;
+ titles = request.getPreferences().getValue(COLUMNS_TITLE, titles);
+ return Arrays.asList(titles.split(","));
+ }
+
+ public String[] getColumNames(PortletRequest request)
+ {
+ String tempColumn = "";
+ tempColumn = request.getPreferences().getValue(COLUMNS, tempColumn);
+ if(StringUtils.isEmpty(tempColumn))
+ {
+ return BLANK_STRING_ARRAY;
+ }
+ return tempColumn.split(",");
+ }
+
+ public String[] getSortColums(PortletRequest request)
+ {
+ String tempColumn = "";
+ tempColumn = request.getPreferences().getValue(Order_BY_COLUMNS, tempColumn);
+ if(StringUtils.isEmpty(tempColumn))
+ {
+ return BLANK_STRING_ARRAY;
+ }
+ return tempColumn.split(",");
+ }
+
+
+
+ public String getQueryString(PortletRequest request)
+ {
+ StringBuffer query = new StringBuffer();
+ String table = request.getPreferences().getValue(TABLE_NAME, "");
+ String condtions = request.getPreferences().getValue(CONDITIONS, "");
+ String orderBy = request.getPreferences().getValue(Order_BY_COLUMNS, "");
+ String columns = request.getPreferences().getValue(COLUMNS, "");
+ if (!StringUtils.isEmpty(columns))
+ {
+ query.append("select ").append(columns).append(" from ").append(table);
+ }
+ else
+ {
+ query.append("select * from ").append(table);
+ }
+ if (!StringUtils.isEmpty(condtions))
+ {
+ query.append(" ").append(condtions);
+ }
+ if (!StringUtils.isEmpty(orderBy))
+ {
+ query.append(" ORDER BY ").append(orderBy);
+ }
+
+ return replacePlaceHolder(query.toString(),request);
+ }
+ private String replacePlaceHolder(String buffer, PortletRequest request){
+ String userName="";
+ if(request.getUserPrincipal()!=null)
+ {
+ userName = request.getUserPrincipal().getName();
+ }else{
+ userName = "guest";
+ }
+ buffer = buffer.replace("$USER", "'" + userName + "'");
+ return buffer;
+ }
+
+ private HSSFWorkbook generateExcel(List beanList, String[] colNames, String[] colDescs, Method[] readMethods)
+ {
+ date_output = new SimpleDateFormat(DATE_OUTPUT_PATTERN);
+ HSSFWorkbook workbook = new HSSFWorkbook();
+ HSSFSheet sheet = workbook.createSheet("export");
+ addColumnHeaders(sheet, colDescs);
+ addColumnValues(sheet, beanList, colNames, readMethods);
+ return workbook;
+ }
+
+ private void addColumnHeaders(HSSFSheet sheet, String[] colDescs)
+ {
+ HSSFRow rowHeader = sheet.createRow(0);
+ for (int i = 0; i < colDescs.length; i++)
+ {
+ addColumnValue(rowHeader, colDescs[i], i);
+ }
+ }
+
+ private void addColumnValues(HSSFSheet sheet, List beanList, String[] colNames, Method[] readMethods)
+ {
+ int rowIndex = 0;
+ Iterator beanListIter = beanList.iterator();
+ List tempList = null;
+ while (beanListIter.hasNext())
+ {
+ Object bean = beanListIter.next();
+ if (bean != null)
+ {
+ HSSFRow row = sheet.createRow(rowIndex + 1);
+ if (bean instanceof ArrayList)
+ {
+ tempList = (List) bean;
+ for (int i = 0; i < tempList.size(); i++)
+ {
+ String colVal = columnValueToString(tempList.get(i));
+ addColumnValue(row, colVal, i);
+ }
+ }
+ else
+ {
+ for (int i = 0; i < colNames.length; i++)
+ {
+ String colName = colNames[i];
+ Method colReadMethod = readMethods[i];
+ String colVal = "";
+ if (colReadMethod != null)
+ {
+ try
+ {
+ Object colValObj = colReadMethod.invoke(bean, new Object[] { colName });
+ colVal = columnValueToString(colValObj);
+ }
+ catch (Exception ex)
+ {
+ colVal = "";
+ }
+ }
+ addColumnValue(row, colVal, i);
+ }
+ }
+ rowIndex++;
+ }
+ }
+ }
+
+ private void addColumnValue(HSSFRow rowHeader, String value, int index)
+ {
+ HSSFCell cell = rowHeader.createCell((short) index);
+ cell.setEncoding(HSSFCell.ENCODING_UTF_16);
+ if (value == null)
+ value = "";
+ cell.setCellValue(value);
+ }
+
+ protected String columnValueToString(Object colValObj)
+ {
+ String colVal = null;
+ if (colValObj == null)
+ colVal = "";
+ else
+ {
+ if (colValObj instanceof Date)
+ {
+ colVal = date_output.format((Date) colValObj);
+ }
+ else
+ {
+ colVal = colValObj.toString();
+ }
+ }
+ return colVal;
+ }
+
+ private String cleanUserFolder(String userName)
+ {
+ String folderName = "";
+ synchronized (this)
+ {
+ folderName = getUserFolder(userName, false);
+ File dir = new File(folderName);
+ if (dir.exists())
+ dir.delete();
+ dir = new File(folderName);
+ dir.mkdir();
+ }
+ return folderName;
+ }
+
+ private String getUserFolder(String userName, boolean fullPath)
+ {
+ if (pathSeprator == null || pathSeprator.equals(""))
+ pathSeprator = "/";
+ if (fullPath)
+ {
+ return userName + pathSeprator;
+ }
+ else
+ {
+ return pageRoot + pathSeprator + userName;
+ }
+ }
+
+ private List<String> getTables(PortletRequest request, Connection conn)
+ {
+ List<String> list = new ArrayList<String>();
+ ResultSet rs = null;
+ PreparedStatement stmt = null;
+ try
+ {
+ String databaseName = conn.getMetaData().getDatabaseProductName();
+ databaseName = databaseName.toLowerCase();
+ 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;
+ }
+ else
+ {
+ stmt = conn.prepareStatement(query);
+ rs = stmt.executeQuery();
+ while (rs.next())
+ {
+ list.add(rs.getString(1));
+ }
+ }
+
+ }
+ catch (SQLException e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ try
+ {
+ if (stmt != null)
+ stmt.close();
+ if (rs != null)
+ rs.close();
+ }
+ catch (Exception e2)
+ {}
+ }
+ return list;
+ }
+
+ 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("sqlserver"))
+ {
+ dataBaseQuery = "Select name from sys.objects where type='U'";
+ }
+ //else if (databaseName.equals("apache derby"))
+ return dataBaseQuery;
+ }
+}
\ No newline at end of file
Propchange: portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/DatabaseBrowserPortlet.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/StatusMessage.java
URL: http://svn.apache.org/viewvc/portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/StatusMessage.java?rev=763970&view=auto
==============================================================================
--- portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/StatusMessage.java (added)
+++ portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/StatusMessage.java Fri Apr 10 16:16:18 2009
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.portals.applications.dbBrowser;
+
+import java.io.Serializable;
+
+/**
+ * StatusMessage
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
+ * @version $Id: StatusMessage.java 516448 2007-03-09 16:25:47Z ate $
+ */
+public class StatusMessage implements Serializable
+{
+ private static final long serialVersionUID = 1;
+ private String text;
+ private String type;
+
+ public static final String INFO = "portlet-msg-info";
+ public static final String ERROR = "portlet-msg-error";
+ public static final String ALERT = "portlet-msg-alert";
+ public static final String SUCCESS = "portlet-msg-success";
+
+ public StatusMessage(String text, String type)
+ {
+ this.text = new String(text);
+ this.type = type;
+ }
+
+ public StatusMessage(String text)
+ {
+ this.text = new String(text);
+ this.type = INFO;
+ }
+
+
+
+ /**
+ * @return Returns the text.
+ */
+ public String getText()
+ {
+ return text;
+ }
+ /**
+ * @param text The text to set.
+ */
+ public void setText(String text)
+ {
+ this.text = text;
+ }
+ /**
+ * @return Returns the type.
+ */
+ public String getType()
+ {
+ return type;
+ }
+ /**
+ * @param type The type to set.
+ */
+ public void setType(String type)
+ {
+ this.type = type;
+ }
+}
\ No newline at end of file
Propchange: portals/applications/databaseBrowser/trunk/dbBrowser-jar/src/main/java/org/apache/portals/applications/dbBrowser/StatusMessage.java
------------------------------------------------------------------------------
svn:mime-type = text/plain