You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jl...@apache.org on 2006/04/13 13:36:26 UTC

svn commit: r393787 [8/22] - in /geronimo/trunk/applications: ./ console/ console/console-core/ console/console-core/src/ console/console-core/src/java/ console/console-core/src/java/org/ console/console-core/src/java/org/apache/ console/console-core/s...

Added: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/databasemanager/wizard/ImportStatus.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/databasemanager/wizard/ImportStatus.java?rev=393787&view=auto
==============================================================================
--- geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/databasemanager/wizard/ImportStatus.java (added)
+++ geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/databasemanager/wizard/ImportStatus.java Thu Apr 13 04:34:08 2006
@@ -0,0 +1,204 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed 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.geronimo.console.databasemanager.wizard;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.geronimo.converter.DatabaseConversionStatus;
+import org.apache.geronimo.converter.AbstractDatabasePool;
+import org.apache.geronimo.converter.JDBCPool;
+import org.apache.geronimo.converter.XADatabasePool;
+
+/**
+ * Tracks the progress of a database pool import operation.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ImportStatus implements Serializable {
+    private DatabaseConversionStatus original;
+    private int currentPool = -1;
+    private PoolProgress[] pools;
+
+    public ImportStatus(DatabaseConversionStatus original) {
+        this.original = original;
+        List list = new ArrayList();
+        for (int i = 0; i < original.getNoTXPools().length; i++) {
+            JDBCPool pool = original.getNoTXPools()[i];
+            list.add(new PoolProgress(pool, PoolProgress.TYPE_NOTX));
+        }
+        for (int i = 0; i < original.getJdbcPools().length; i++) {
+            JDBCPool pool = original.getJdbcPools()[i];
+            list.add(new PoolProgress(pool, PoolProgress.TYPE_LOCAL));
+        }
+        for (int i = 0; i < original.getXaPools().length; i++) {
+            XADatabasePool pool = original.getXaPools()[i];
+            final PoolProgress progress = new PoolProgress(pool, PoolProgress.TYPE_XA);
+            if(pool.getXaDataSourceClass().indexOf("apache.derby") < 0) {
+                progress.setSkipped(true);
+            }
+            list.add(progress);
+        }
+        pools = (PoolProgress[]) list.toArray(new PoolProgress[list.size()]);
+    }
+
+    public boolean isFinished() {
+        for (int i = 0; i < pools.length; i++) {
+            PoolProgress pool = pools[i];
+            if(!pool.isFinished() && !pool.isSkipped()) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    public void setCurrentPoolIndex(int currentPool) {
+        this.currentPool = currentPool;
+        getCurrentPool().setStarted(true);
+    }
+
+    public DatabaseConversionStatus getOriginal() {
+        return original;
+    }
+
+    public int getCurrentPoolIndex() {
+        return currentPool;
+    }
+
+    public PoolProgress getCurrentPool() {
+        return currentPool > -1 ? pools[currentPool] : null;
+    }
+
+    public PoolProgress[] getPools() {
+        return pools;
+    }
+
+    public int getPendingCount() {
+        int count = 0;
+        for (int i = 0; i < pools.length; i++) {
+            PoolProgress pool = pools[i];
+            if(!pool.isSkipped() && !pool.isStarted()) {
+                ++count;
+            }
+        }
+        return count;
+    }
+
+    public int getStartedCount() {
+        int count = 0;
+        for (int i = 0; i < pools.length; i++) {
+            PoolProgress pool = pools[i];
+            if(pool.isStarted() && !pool.isFinished() && !pool.isSkipped()) {
+                ++count;
+            }
+        }
+        return count;
+    }
+
+    public int getFinishedCount() {
+        int count = 0;
+        for (int i = 0; i < pools.length; i++) {
+            PoolProgress pool = pools[i];
+            if(!pool.isSkipped() && pool.isFinished()) {
+                ++count;
+            }
+        }
+        return count;
+    }
+
+    public int getSkippedCount() {
+        int count = 0;
+        for (int i = 0; i < pools.length; i++) {
+            PoolProgress pool = pools[i];
+            if(pool.isSkipped()) {
+                ++count;
+            }
+        }
+        return count;
+    }
+
+    public final static class PoolProgress implements Serializable {
+        public final static String TYPE_NOTX = "NoTX";
+        public final static String TYPE_LOCAL = "JDBC";
+        public final static String TYPE_XA = "XA";
+
+        private AbstractDatabasePool pool;
+        private boolean started;
+        private boolean finished;
+        private boolean skipped;
+        private String type;
+        private String name; // Once in Geronimo
+        private String configurationName; // Once in Geronimo
+
+        public PoolProgress(AbstractDatabasePool pool, String type) {
+            this.pool = pool;
+            this.type = type;
+        }
+
+        public AbstractDatabasePool getPool() {
+            return pool;
+        }
+
+        public boolean isStarted() {
+            return started;
+        }
+
+        public void setStarted(boolean started) {
+            this.started = started;
+        }
+
+        public boolean isFinished() {
+            return finished;
+        }
+
+        public void setFinished(boolean finished) {
+            this.finished = finished;
+        }
+
+        public boolean isSkipped() {
+            return skipped;
+        }
+
+        public void setSkipped(boolean skipped) {
+            this.skipped = skipped;
+        }
+
+        public String getType() {
+            return type;
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        public void setName(String name) {
+            this.name = name;
+        }
+
+        public String getConfigurationName() {
+            return configurationName;
+        }
+
+        public void setConfigurationName(String configurationName) {
+            this.configurationName = configurationName;
+        }
+
+        public String getStatus() {
+            return isSkipped() ? "Ignored" : isFinished() ? "Deployed as "+name : isStarted() ? "Started" : "Pending";
+        }
+    }
+}

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/databasemanager/wizard/ImportStatus.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/databasemanager/wizard/ImportStatus.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/databasemanager/wizard/ImportStatus.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/derbylogmanager/DerbyLogHelper.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/derbylogmanager/DerbyLogHelper.java?rev=393787&view=auto
==============================================================================
--- geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/derbylogmanager/DerbyLogHelper.java (added)
+++ geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/derbylogmanager/DerbyLogHelper.java Thu Apr 13 04:34:08 2006
@@ -0,0 +1,77 @@
+/**
+ *
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.geronimo.console.derbylogmanager;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Stack;
+
+import org.apache.geronimo.console.util.KernelHelper;
+
+public class DerbyLogHelper extends KernelHelper {
+    private static ArrayList logs = new ArrayList();
+
+    private static boolean cached = false;
+
+    private static int lineCount = 0;
+
+    private static final String DERBY_SYSTEM_HOME = "derby.system.home";
+
+    private static final String LOG_FILENAME = "derby.log";
+
+    public static Collection getLogs() throws IOException {
+        if (!cached) {
+            refresh();
+        }
+        return logs;
+    }
+
+    public static void refresh() throws IOException {
+        cached = false;
+        logs.clear();
+        BufferedReader in = new BufferedReader(getFileReader());
+        lineCount = 0;
+        Stack holder = new Stack();
+        for (String line = in.readLine(); line != null; line = in.readLine()) {
+            holder.push(line);
+            lineCount++;
+        }
+        logs.addAll(holder);
+        cached = true;
+    }
+
+    public static int getLineCount() {
+        return lineCount;
+    }
+
+    private static InputStreamReader getFileReader() throws IOException {
+        String pathToFile = getSystemHome() + File.separator + LOG_FILENAME;
+        return new FileReader(new File(pathToFile));
+    }
+
+    public static String getSystemHome() {
+        return System.getProperty(DERBY_SYSTEM_HOME);
+    }
+
+
+}

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/derbylogmanager/DerbyLogHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/derbylogmanager/DerbyLogHelper.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/derbylogmanager/DerbyLogHelper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/derbylogmanager/DerbyLogViewerPortlet.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/derbylogmanager/DerbyLogViewerPortlet.java?rev=393787&view=auto
==============================================================================
--- geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/derbylogmanager/DerbyLogViewerPortlet.java (added)
+++ geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/derbylogmanager/DerbyLogViewerPortlet.java Thu Apr 13 04:34:08 2006
@@ -0,0 +1,110 @@
+/**
+ *
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.geronimo.console.derbylogmanager;
+
+import org.apache.geronimo.console.BasePortlet;
+import org.apache.geronimo.console.util.PortletManager;
+import org.apache.geronimo.derby.DerbyLog;
+
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletContext;
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.PortletSession;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.WindowState;
+import java.io.IOException;
+import java.io.Serializable;
+
+public class DerbyLogViewerPortlet extends BasePortlet {
+    private final static String CRITERIA_KEY = "org.apache.geronimo.console.derby.log.CRITERIA";
+
+    protected PortletRequestDispatcher normalView;
+
+    protected PortletRequestDispatcher helpView;
+
+    public void destroy() {
+        super.destroy();
+        normalView = null;
+        helpView = null;
+    }
+
+    protected void doHelp(RenderRequest renderRequest,
+                          RenderResponse renderResponse) throws PortletException, IOException {
+        helpView.include(renderRequest, renderResponse);
+    }
+
+    protected void doView(RenderRequest renderRequest,
+                          RenderResponse renderResponse) throws PortletException, IOException {
+        if (WindowState.MINIMIZED.equals(renderRequest.getWindowState())) {
+            return;
+        }
+        String action = renderRequest.getParameter("action");
+
+        DerbyLog log = (DerbyLog) PortletManager.getManagedBeans(renderRequest, DerbyLog.class)[0];//todo: what if it's not there?
+        Criteria criteria;
+        if ("refresh".equals(action)) {
+            criteria = (Criteria) renderRequest.getPortletSession(true).getAttribute(CRITERIA_KEY, PortletSession.PORTLET_SCOPE);
+        } else {
+            String startPos = renderRequest.getParameter("startPos");
+            String endPos = renderRequest.getParameter("endPos");
+            String maxRows = renderRequest.getParameter("maxRows");
+            String searchString = renderRequest.getParameter("searchString");
+            if(maxRows == null || maxRows.equals("")) {
+                maxRows = "10";
+            }
+            criteria = new Criteria();
+            criteria.max = new Integer(maxRows);
+            criteria.start = startPos == null || startPos.equals("") ? null : new Integer(startPos);
+            criteria.stop = endPos == null || endPos.equals("") ? null : new Integer(endPos);
+            criteria.text = searchString == null || searchString.equals("") ? null : searchString;
+            renderRequest.getPortletSession(true).setAttribute(CRITERIA_KEY, criteria, PortletSession.PORTLET_SCOPE);
+        }
+
+        DerbyLog.SearchResults results = log.searchLog(criteria.start, criteria.stop,
+                         criteria.max, criteria.text);
+        renderRequest.setAttribute("searchResults", results.getResults());
+        renderRequest.setAttribute("lineCount", new Integer(results.getLineCount()));
+        renderRequest.setAttribute("startPos", criteria.start);
+        renderRequest.setAttribute("endPos", criteria.stop);
+        renderRequest.setAttribute("searchString", criteria.text);
+        renderRequest.setAttribute("maxRows", criteria.max);
+        if(results.isCapped()) {
+            renderRequest.setAttribute("capped", Boolean.TRUE);
+        }
+
+        normalView.include(renderRequest, renderResponse);
+    }
+
+    private static class Criteria implements Serializable {
+        Integer max;
+        Integer start;
+        Integer stop;
+        String text;
+    }
+
+    public void init(PortletConfig portletConfig) throws PortletException {
+        PortletContext pc = portletConfig.getPortletContext();
+        normalView = pc
+                .getRequestDispatcher("/WEB-INF/view/derbylogmanager/view.jsp");
+        helpView = pc
+                .getRequestDispatcher("/WEB-INF/view/derbylogmanager/help.jsp");
+        super.init(portletConfig);
+    }
+}

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/derbylogmanager/DerbyLogViewerPortlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/derbylogmanager/DerbyLogViewerPortlet.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/derbylogmanager/DerbyLogViewerPortlet.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/infomanager/JavaSystemInfoPortlet.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/infomanager/JavaSystemInfoPortlet.java?rev=393787&view=auto
==============================================================================
--- geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/infomanager/JavaSystemInfoPortlet.java (added)
+++ geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/infomanager/JavaSystemInfoPortlet.java Thu Apr 13 04:34:08 2006
@@ -0,0 +1,146 @@
+/**
+ *
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.geronimo.console.infomanager;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+import java.util.Map;
+import java.util.TreeMap;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.WindowState;
+
+import org.apache.geronimo.console.BasePortlet;
+import org.apache.geronimo.console.util.PortletManager;
+
+public class JavaSystemInfoPortlet extends BasePortlet {
+
+    private static final String NORMALVIEW_JSP = "/WEB-INF/view/infomanager/javaSysNormal.jsp";
+
+    private static final String MAXIMIZEDVIEW_JSP = "/WEB-INF/view/infomanager/javaSysMaximized.jsp";
+
+    private static final String HELPVIEW_JSP = "/WEB-INF/view/infomanager/javaSysHelp.jsp";
+
+    private PortletRequestDispatcher normalView;
+
+    private PortletRequestDispatcher maximizedView;
+
+    private PortletRequestDispatcher helpView;
+
+    public void processAction(ActionRequest actionRequest,
+            ActionResponse actionResponse) throws PortletException, IOException {
+    }
+
+    protected void doView(RenderRequest renderRequest,
+            RenderResponse renderResponse) throws IOException, PortletException {
+        if (WindowState.MINIMIZED.equals(renderRequest.getWindowState())) {
+            return;
+        }
+
+        ShrinkingMap javaSysProps = new ShrinkingMap(PortletManager.getCurrentJVM(renderRequest).getSystemProperties());
+
+        renderRequest.setAttribute("javaSysProps", javaSysProps);
+
+        String sep = (String) javaSysProps.get("path.separator");
+
+        String test = (String) javaSysProps.get("sun.boot.class.path");
+        if (test != null) {
+            javaSysProps.put("sun.boot.class.path", split(test, sep));
+        }
+        test = (String) javaSysProps.get("sun.boot.library.path");
+        if (test != null) {
+            javaSysProps.put("sun.boot.library.path", split(test, sep));
+        }
+        test = (String) javaSysProps.get("java.library.path");
+        if (test != null) {
+            javaSysProps.put("java.library.path", split(test, sep));
+        }
+        test = (String) javaSysProps.get("java.class.path");
+        if (test != null) {
+            javaSysProps.put("java.class.path", split(test, sep));
+        }
+        test = (String) javaSysProps.get("java.endorsed.dirs");
+        if (test != null) {
+            javaSysProps.put("java.endorsed.dirs", split(test, sep));
+        }
+        test = (String) javaSysProps.get("java.ext.dirs");
+        if (test != null) {
+            javaSysProps.put("java.ext.dirs", split(test, sep));
+        }
+        test = (String) javaSysProps.get("common.loader");
+        if (test != null) {
+            javaSysProps.put("common.loader", test.replace(',',' '));
+        }
+
+        // Remove a few properties for security reasons
+        javaSysProps.remove("javax.net.ssl.keyStore");
+        javaSysProps.remove("javax.net.ssl.keyStorePassword");
+        javaSysProps.remove("javax.net.ssl.trustStore");
+        javaSysProps.remove("javax.net.ssl.trustStorePassword");
+
+        javaSysProps.setShrinking(true);
+
+        if (WindowState.NORMAL.equals(renderRequest.getWindowState())) {
+            normalView.include(renderRequest, renderResponse);
+        } else {
+            maximizedView.include(renderRequest, renderResponse);
+        }
+    }
+
+    private List split(String path, String sep) {
+        StringTokenizer st = new StringTokenizer(path, sep);
+
+        List l = new ArrayList();
+
+        while (st.hasMoreTokens()) {
+            l.add(st.nextToken());
+        }
+        return l;
+    }
+
+    protected void doHelp(RenderRequest renderRequest,
+            RenderResponse renderResponse) throws PortletException, IOException {
+        helpView.include(renderRequest, renderResponse);
+    }
+
+    public void init(PortletConfig portletConfig) throws PortletException {
+        super.init(portletConfig);
+        normalView = portletConfig.getPortletContext().getRequestDispatcher(
+                NORMALVIEW_JSP);
+        maximizedView = portletConfig.getPortletContext().getRequestDispatcher(
+                MAXIMIZEDVIEW_JSP);
+        helpView = portletConfig.getPortletContext().getRequestDispatcher(
+                HELPVIEW_JSP);
+    }
+
+    public void destroy() {
+        normalView = null;
+        maximizedView = null;
+        helpView = null;
+        super.destroy();
+    }
+
+}
\ No newline at end of file

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/infomanager/JavaSystemInfoPortlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/infomanager/JavaSystemInfoPortlet.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/infomanager/JavaSystemInfoPortlet.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/infomanager/ServerInfoPortlet.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/infomanager/ServerInfoPortlet.java?rev=393787&view=auto
==============================================================================
--- geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/infomanager/ServerInfoPortlet.java (added)
+++ geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/infomanager/ServerInfoPortlet.java Thu Apr 13 04:34:08 2006
@@ -0,0 +1,110 @@
+/**
+ *
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.geronimo.console.infomanager;
+
+import java.io.IOException;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.WindowState;
+
+import org.apache.geronimo.console.BasePortlet;
+import org.apache.geronimo.console.util.PortletManager;
+import org.apache.geronimo.management.geronimo.JVM;
+
+/**
+ * Calculates various information about the server to display in the server
+ * info portlet view (on of several JSPs depending on the portlet state).
+ *
+ * @version $Rev$ $Date$
+ */
+public class ServerInfoPortlet extends BasePortlet {
+    private static final String NORMALVIEW_JSP = "/WEB-INF/view/infomanager/svrInfoNormal.jsp";
+
+    private static final String MAXIMIZEDVIEW_JSP = "/WEB-INF/view/infomanager/svrInfoMaximized.jsp";
+
+    private static final String HELPVIEW_JSP = "/WEB-INF/view/infomanager/svrInfoHelp.jsp";
+
+    private PortletRequestDispatcher normalView;
+
+    private PortletRequestDispatcher maximizedView;
+
+    private PortletRequestDispatcher helpView;
+
+    public void processAction(ActionRequest actionRequest,
+            ActionResponse actionResponse) throws PortletException, IOException {
+    }
+
+    protected void doView(RenderRequest renderRequest,
+            RenderResponse renderResponse) throws IOException, PortletException {
+        if (WindowState.MINIMIZED.equals(renderRequest.getWindowState())) {
+            return;
+        }
+
+        Map svrProps = new HashMap();
+        Map jvmProps = new HashMap();
+
+        JVM jvm = PortletManager.getCurrentJVM(renderRequest);
+
+        Date bootDate = jvm.getKernelBootTime();
+        svrProps.put("Kernel Boot Time", bootDate);
+        renderRequest.setAttribute("svrProps", svrProps);
+
+        jvmProps.put("Java Version", jvm.getJavaVersion());
+        jvmProps.put("Java Vendor", jvm.getJavaVendor());
+        jvmProps.put("Node", jvm.getNode());
+        jvmProps.put("Available Processors", new Integer(jvm.getAvailableProcessors()));
+        renderRequest.setAttribute("jvmProps", jvmProps);
+
+        if (WindowState.NORMAL.equals(renderRequest.getWindowState())) {
+            normalView.include(renderRequest, renderResponse);
+        } else {
+            maximizedView.include(renderRequest, renderResponse);
+        }
+    }
+
+    protected void doHelp(RenderRequest renderRequest,
+            RenderResponse renderResponse) throws PortletException, IOException {
+        helpView.include(renderRequest, renderResponse);
+    }
+
+    public void init(PortletConfig portletConfig) throws PortletException {
+        super.init(portletConfig);
+        normalView = portletConfig.getPortletContext().getRequestDispatcher(
+                NORMALVIEW_JSP);
+        maximizedView = portletConfig.getPortletContext().getRequestDispatcher(
+                MAXIMIZEDVIEW_JSP);
+        helpView = portletConfig.getPortletContext().getRequestDispatcher(
+                HELPVIEW_JSP);
+    }
+
+    public void destroy() {
+        normalView = null;
+        maximizedView = null;
+        helpView = null;
+        super.destroy();
+    }
+}

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/infomanager/ServerInfoPortlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/infomanager/ServerInfoPortlet.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/infomanager/ServerInfoPortlet.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/infomanager/ShrinkingMap.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/infomanager/ShrinkingMap.java?rev=393787&view=auto
==============================================================================
--- geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/infomanager/ShrinkingMap.java (added)
+++ geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/infomanager/ShrinkingMap.java Thu Apr 13 04:34:08 2006
@@ -0,0 +1,58 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed 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.geronimo.console.infomanager;
+
+import java.util.TreeMap;
+import java.util.Map;
+
+/**
+ * A Map that can remove items as they are accessed, which makes it
+ * easier to show a list of the remaining items.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ShrinkingMap extends TreeMap {
+    private boolean shrinking = false;
+
+    public ShrinkingMap() {
+    }
+
+    public ShrinkingMap(Map defaults) {
+        super(defaults);
+    }
+
+    public boolean isShrinking() {
+        return shrinking;
+    }
+
+    public void setShrinking(boolean shrinking) {
+        this.shrinking = shrinking;
+    }
+
+    public synchronized Object get(Object key) {
+        if(shrinking) {
+            return super.remove(key);
+        } else {
+            return super.get(key);
+        }
+    }
+
+    public Map getRemainingItems() {
+        shrinking = false;
+        return this;
+    }
+}

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/infomanager/ShrinkingMap.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/infomanager/ShrinkingMap.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/infomanager/ShrinkingMap.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/DBViewerHelper.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/DBViewerHelper.java?rev=393787&view=auto
==============================================================================
--- geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/DBViewerHelper.java (added)
+++ geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/DBViewerHelper.java Thu Apr 13 04:34:08 2006
@@ -0,0 +1,134 @@
+/**
+ *
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.geronimo.console.internaldb;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.Vector;
+
+public class DBViewerHelper {
+
+    private static final String SYS_TBL_PREFIX = "SYS.";
+
+    private static final int COUNT_COL = 1;
+
+    /**
+     * List the databases given the derby home directory.
+     *
+     * @param derbySysHome
+     * @return
+     */
+    public Collection getDerbyDatabases(String derbySysHome) {
+        Vector databases = new Vector();
+        File f = new File(derbySysHome);
+        // Check if this is a directory
+        if (f.isDirectory()) {
+            // Check for folders only
+            File[] files = f.listFiles();
+            for (int i = 0; i < files.length; i++) {
+                if (files[i].isDirectory()) {
+                    databases.add(files[i].getName());
+                }
+            }
+        }
+
+        return databases;
+    }
+
+    /**
+     * @param derbySysHome
+     * @param dbName
+     * @return
+     */
+    public boolean isDBValid(String derbySysHome, String dbName) {
+        if ((derbySysHome == null) || (derbySysHome.trim().length() == 0)) {
+            return false;
+        }
+        if ((dbName == null) || (dbName.trim().length() == 0)) {
+            return false;
+        }
+
+        Collection databases = getDerbyDatabases(derbySysHome);
+        return databases.contains(dbName);
+    }
+
+    /**
+     * @param dbName
+     * @param tblName
+     * @return
+     */
+    public boolean isTblValid(String dbName, String tblName) {
+        if ((dbName == null) || (dbName.trim().length() == 0)) {
+            return false;
+        }
+        if ((tblName == null) || (tblName.trim().length() == 0)) {
+            return false;
+        }
+        return true;
+
+        // Removed this code because it doesn't seem necessary and causes a
+        // weird ClassCastException when rs.next() is called.
+        /*
+         else {
+         if (tblName.toUpperCase().startsWith(SYS_TBL_PREFIX)) {
+         tblName = tblName.substring(SYS_TBL_PREFIX.length());
+         }
+         }
+
+         Connection conn = null;
+         PreparedStatement ps = null;
+         ResultSet rs = null;
+         try {
+         conn = DerbyConnectionUtil.getDerbyConnection(dbName);
+         ps = conn.prepareStatement("SELECT count(*) FROM SYS.SYSTABLES"
+         + " WHERE tablename=?");
+         ps.setString(1, tblName.toUpperCase());
+         rs = ps.executeQuery();
+         if (rs.next()) {
+         int count = rs.getInt(COUNT_COL);
+         if (count == 1) {
+         return true;
+         }
+         }
+         } catch (Throwable e) {
+         e.printStackTrace();
+         System.out.println("ERROR: " + e.getMessage());
+         // Assume table is not valid
+         return false;
+         } finally {
+         // close DB connection
+         try {
+         if (rs != null) {
+         rs.close();
+         }
+         if (ps != null) {
+         ps.close();
+         }
+         if (conn != null) {
+         conn.close();
+         }
+         } catch (SQLException e) {
+         // problem closing DB connection
+         }
+         }
+
+         return false;
+         */
+    }
+
+}

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/DBViewerHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/DBViewerHelper.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/DBViewerHelper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/DBViewerPortlet.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/DBViewerPortlet.java?rev=393787&view=auto
==============================================================================
--- geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/DBViewerPortlet.java (added)
+++ geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/DBViewerPortlet.java Thu Apr 13 04:34:08 2006
@@ -0,0 +1,180 @@
+/**
+ *
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.geronimo.console.internaldb;
+
+import java.io.IOException;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.WindowState;
+
+import org.apache.geronimo.console.BasePortlet;
+
+public class DBViewerPortlet extends BasePortlet {
+
+    private static final int RDBMS_DERBY = 1;
+
+    private static final int RDBMS_MSSQL = 2;
+
+    private static final String MAXIMIZEDVIEW_JSP = "/WEB-INF/view/internaldb/dbViewerMaximized.jsp";
+
+    private static final String HELPVIEW_JSP = "/WEB-INF/view/internaldb/dbViewerHelp.jsp";
+
+    private static final String LISTDATABASES_JSP = "/WEB-INF/view/internaldb/listDatabases.jsp";
+
+    private static final String LISTTABLES_JSP = "/WEB-INF/view/internaldb/listTables.jsp";
+
+    private static final String VIEWTABLECONTENTS_JSP = "/WEB-INF/view/internaldb/viewTableContents.jsp";
+
+    private static final String LISTDB_ACTION = "listDatabases";
+
+    private static final String LISTTBLS_ACTION = "listTables";
+
+    private static final String VIEWTBLCONTENTS_ACTION = "viewTableContents";
+
+    private static final String DERBY_HOME = System
+            .getProperty("derby.system.home");
+
+    private static DBViewerHelper helper = new DBViewerHelper();
+
+    private PortletRequestDispatcher maximizedView;
+
+    private PortletRequestDispatcher helpView;
+
+    private PortletRequestDispatcher listDatabasesView;
+
+    private PortletRequestDispatcher listTablesView;
+
+    private PortletRequestDispatcher viewTableContentsView;
+
+    public void processAction(ActionRequest actionRequest,
+            ActionResponse actionResponse) throws PortletException, IOException {
+        // getting parameters here because it fails on doView()
+        String action = actionRequest.getParameter("action");
+        String db = actionRequest.getParameter("db");
+        String tbl = actionRequest.getParameter("tbl");
+        String viewTables = actionRequest.getParameter("viewTables");
+        String rdbms = actionRequest.getParameter("rdbms");
+        // pass them to the render request
+        if (action != null) {
+            actionResponse.setRenderParameter("action", action);
+        }
+        if (db != null) {
+            actionResponse.setRenderParameter("db", db);
+        }
+        if (tbl != null) {
+            actionResponse.setRenderParameter("tbl", tbl);
+        }
+        if (viewTables != null) {
+            actionResponse.setRenderParameter("viewTables", viewTables);
+        }
+        if (rdbms != null) {
+            actionResponse.setRenderParameter("rdbms", rdbms);
+        }
+    }
+
+    protected void doView(RenderRequest renderRequest,
+            RenderResponse renderResponse) throws IOException, PortletException {
+        if (WindowState.MINIMIZED.equals(renderRequest.getWindowState())) {
+            return;
+        }
+        String action = renderRequest.getParameter("action");
+        String db = renderRequest.getParameter("db");
+        String tbl = renderRequest.getParameter("tbl");
+        String viewTables = renderRequest.getParameter("viewTables");
+        String rdbms = renderRequest.getParameter("rdbms");
+        int rdbmsParam = (rdbms == null ? RDBMS_DERBY : Integer.parseInt(rdbms));
+
+        if (WindowState.NORMAL.equals(renderRequest.getWindowState())) {
+            if (rdbmsParam == RDBMS_DERBY) {
+                // Check is database & table is valid
+                if (LISTTBLS_ACTION.equals(action)
+                        || VIEWTBLCONTENTS_ACTION.equals(action)) {
+                    if (!helper.isDBValid(DERBY_HOME, db)) {
+                        // DB not valid
+                        System.out.println("ERROR: db not valid: " + db);
+                        action = "";
+                    }
+                }
+                if (VIEWTBLCONTENTS_ACTION.equals(action)) {
+                    if (!helper.isTblValid(db, tbl)) {
+                        // Table not valid
+                        System.out.println("ERROR: table not valid: " + tbl);
+                        action = "";
+                    }
+                }
+            }
+
+            renderRequest.setAttribute("rdbms", rdbms);
+            if (LISTTBLS_ACTION.equals(action)) {
+                renderRequest.setAttribute("db", db);
+                renderRequest.setAttribute("viewTables", viewTables);
+                renderRequest.setAttribute("ds", DerbyConnectionUtil
+                        .getDataSource(db));
+                listTablesView.include(renderRequest, renderResponse);
+            } else if (VIEWTBLCONTENTS_ACTION.equals(action)) {
+                renderRequest.setAttribute("db", db);
+                renderRequest.setAttribute("tbl", tbl);
+                renderRequest.setAttribute("viewTables", viewTables);
+                renderRequest.setAttribute("ds", DerbyConnectionUtil
+                        .getDataSource(db));
+                viewTableContentsView.include(renderRequest, renderResponse);
+            } else {
+                renderRequest.setAttribute("databases", helper
+                        .getDerbyDatabases(DERBY_HOME));
+                listDatabasesView.include(renderRequest, renderResponse);
+            }
+        } else {
+            maximizedView.include(renderRequest, renderResponse);
+        }
+    }
+
+    protected void doHelp(RenderRequest renderRequest,
+            RenderResponse renderResponse) throws PortletException, IOException {
+        helpView.include(renderRequest, renderResponse);
+    }
+
+    public void init(PortletConfig portletConfig) throws PortletException {
+        super.init(portletConfig);
+        maximizedView = portletConfig.getPortletContext().getRequestDispatcher(
+                MAXIMIZEDVIEW_JSP);
+        helpView = portletConfig.getPortletContext().getRequestDispatcher(
+                HELPVIEW_JSP);
+        listDatabasesView = portletConfig.getPortletContext()
+                .getRequestDispatcher(LISTDATABASES_JSP);
+        listTablesView = portletConfig.getPortletContext()
+                .getRequestDispatcher(LISTTABLES_JSP);
+        viewTableContentsView = portletConfig.getPortletContext()
+                .getRequestDispatcher(VIEWTABLECONTENTS_JSP);
+    }
+
+    public void destroy() {
+        maximizedView = null;
+        helpView = null;
+        listDatabasesView = null;
+        listTablesView = null;
+        viewTableContentsView = null;
+        super.destroy();
+    }
+
+}
\ No newline at end of file

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/DBViewerPortlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/DBViewerPortlet.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/DBViewerPortlet.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/DerbyConnectionUtil.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/DerbyConnectionUtil.java?rev=393787&view=auto
==============================================================================
--- geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/DerbyConnectionUtil.java (added)
+++ geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/DerbyConnectionUtil.java Thu Apr 13 04:34:08 2006
@@ -0,0 +1,137 @@
+/**
+ *
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.geronimo.console.internaldb;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+import javax.management.ObjectName;
+import javax.sql.DataSource;
+
+import org.apache.geronimo.console.GeronimoVersion;
+import org.apache.geronimo.kernel.KernelRegistry;
+import org.apache.geronimo.kernel.jmx.JMXUtil;
+
+/**
+ * A static class to handle retreiving connections. This class is built to
+ * handle lookups to the SystemDatabase as a special case. If a connection is
+ * requested for the SystemDatabase this class gets a DataSource from an admin
+ * object registered in the geronimo kernel otherwise the DataSource is looked
+ * up via JNDI.
+ */
+public class DerbyConnectionUtil {
+
+    public static final String CREATE_DB_PROP = ";create=true";
+
+    public static final String SHUTDOWN_DB_PROP = ";shutdown=true";
+
+    private static final int RDBMS_DERBY = 1;
+
+    private static final int RDBMS_MSSQL = 2;
+
+    private static final String SYSTEM_DB = "SYSTEMDATABASE";
+
+    private static final String DERBY_DRIVER = "org.apache.derby.jdbc.EmbeddedDriver";
+
+    private static final String PROTOCOL = "jdbc:derby:";
+
+    private static final String EMPTY_PROPS = "";
+
+    private static final ObjectName SYSTEM_DATASOURCE_NAME = JMXUtil
+            .getObjectName("geronimo.server:J2EEApplication=null,J2EEServer=geronimo,JCAResource=geronimo/system-database/"+GeronimoVersion.GERONIMO_VERSION+"/car,j2eeType=JCAManagedConnectionFactory,name=SystemDatasource");
+
+    /**
+     * Get database connection.
+     *
+     * @param dbName
+     * @return
+     * @throws SQLException
+     */
+    private static Connection getConnection(String dbName, String properties,
+            String protocol, String driver) throws SQLException {
+        try {
+            Class.forName(driver).newInstance();
+        } catch (Exception e) {
+            // Problem loading driver class
+            return null;
+        }
+        // If we are looking for the SystemDatabase get it from the kernel
+        // because it is not binded to our JNDI Context.
+        if (SYSTEM_DB.equalsIgnoreCase(dbName)) {
+            return getSystemDBConnection();
+        } else {
+            return DriverManager.getConnection(protocol + dbName + properties);
+        }
+    }
+
+    /**
+     * Get a connection to derby.
+     *
+     * @param dbName
+     *            the name of the database to connect to.
+     * @param properties
+     *            the properties to pass to the connection string.
+     * @return
+     */
+    public static Connection getDerbyConnection(String dbName, String properties)
+            throws SQLException {
+        return getConnection(dbName, properties, PROTOCOL, DERBY_DRIVER);
+    }
+
+    public static Connection getDerbyConnection(String dbName)
+            throws SQLException {
+        return getDerbyConnection(dbName, EMPTY_PROPS);
+    }
+
+    /**
+     * Get a connection to the SystemDatabase.
+     *
+     * @return
+     * @throws SQLException
+     */
+    public static Connection getSystemDBConnection() throws SQLException {
+        DataSource ds = null;
+        try {
+            ds = getDataSource(SYSTEM_DB);
+            return ds.getConnection();
+        } catch (Exception e) {
+            throw new SQLException(e.getMessage());
+        }
+    }
+
+    /**
+     * Get the datasource if dbName is == SYSTEM_DB, otherwise returns null.
+     *
+     * @param dbName
+     * @return
+     */
+    public static DataSource getDataSource(String dbName) {
+        try {
+            if (SYSTEM_DB.equalsIgnoreCase(dbName)) {
+                return (DataSource) KernelRegistry.getSingleKernel().invoke(
+                        SYSTEM_DATASOURCE_NAME, "$getResource");
+            } else {
+                return null;
+            }
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+}

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/DerbyConnectionUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/DerbyConnectionUtil.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/DerbyConnectionUtil.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/InternalDBHelper.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/InternalDBHelper.java?rev=393787&view=auto
==============================================================================
--- geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/InternalDBHelper.java (added)
+++ geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/InternalDBHelper.java Thu Apr 13 04:34:08 2006
@@ -0,0 +1,228 @@
+/**
+ *
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.geronimo.console.internaldb;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.util.Hashtable;
+import java.util.Map;
+
+public class InternalDBHelper {
+
+    private static final int RDBMS_DERBY = 1;
+
+    private static final int RDBMS_MSSQL = 2;
+
+    private static final String JNDI_DERBY = "java:comp/env/SystemDatasource";
+
+    private static final Map derbyDBInfo = new Hashtable();
+
+    /**
+     * Returns the database metadata as a map.
+     *
+     * @return
+     */
+    public Map getDBInfo() {
+        derbyDBInfo.clear();
+        Connection conn = null;
+        try {
+            conn = DerbyConnectionUtil.getSystemDBConnection();
+            DatabaseMetaData dbMD = (DatabaseMetaData) conn.getMetaData();
+
+            // DB
+            derbyDBInfo.put("URL", removeNull(dbMD.getURL()));
+            derbyDBInfo.put("Username", removeNull(dbMD.getUserName()));
+            derbyDBInfo.put("Read Only", removeNull(String.valueOf(dbMD
+                    .isReadOnly())));
+            derbyDBInfo.put("DB Product Name", removeNull(dbMD
+                    .getDatabaseProductName()));
+            derbyDBInfo.put("DB Product Version", removeNull(dbMD
+                    .getDatabaseProductVersion()));
+            derbyDBInfo.put("DB Major Version", removeNull(String.valueOf(dbMD
+                    .getDatabaseMajorVersion())));
+            derbyDBInfo.put("DB Minor Version", removeNull(String.valueOf(dbMD
+                    .getDatabaseMinorVersion())));
+
+            // Driver
+            derbyDBInfo.put("Driver Name", removeNull(dbMD.getDriverName()));
+            derbyDBInfo.put("Driver Version", removeNull(dbMD
+                    .getDriverVersion()));
+            derbyDBInfo.put("Driver Major Version", removeNull(String
+                    .valueOf(dbMD.getDriverMajorVersion())));
+            derbyDBInfo.put("Driver Minor Version", removeNull(String
+                    .valueOf(dbMD.getDriverMinorVersion())));
+
+            // JDBC
+            derbyDBInfo.put("JDBC Major Version", removeNull(String
+                    .valueOf(dbMD.getJDBCMajorVersion())));
+            derbyDBInfo.put("JDBC Minor Version", removeNull(String
+                    .valueOf(dbMD.getJDBCMinorVersion())));
+
+            // Functions
+            derbyDBInfo.put("Numeric Functions", removeNull(dbMD
+                    .getNumericFunctions()));
+            derbyDBInfo.put("String Functions", removeNull(dbMD
+                    .getStringFunctions()));
+            derbyDBInfo.put("System Functions", removeNull(dbMD
+                    .getSystemFunctions()));
+            derbyDBInfo.put("Time Date Functions", removeNull(dbMD
+                    .getTimeDateFunctions()));
+
+            // Etc
+            derbyDBInfo.put("Supported SQL Keywords", removeNull(dbMD
+                    .getSQLKeywords().replace(',', ' ')));
+            derbyDBInfo.put("Supported Types", removeNull(getColumnData(dbMD
+                    .getTypeInfo(), "TYPE_NAME")));
+            derbyDBInfo.put("Table Types", removeNull(getColumnData(dbMD
+                    .getTableTypes(), "TABLE_TYPE")));
+            derbyDBInfo.put("Schemas", removeNull(getColumnData(dbMD
+                    .getSchemas(), "TABLE_SCHEM")));
+            String tx = null;
+
+            switch (dbMD.getDefaultTransactionIsolation()) {
+            case Connection.TRANSACTION_NONE:
+                tx = "not supported";
+                break;
+            case Connection.TRANSACTION_READ_COMMITTED:
+                tx = "dirty reads are prevented; non-repeatable reads and phantom reads can occur";
+                break;
+            case Connection.TRANSACTION_READ_UNCOMMITTED:
+                tx = "dirty reads, non-repeatable reads and phantom reads can occur";
+                break;
+            case Connection.TRANSACTION_REPEATABLE_READ:
+                tx = "dirty reads and non-repeatable reads are prevented; phantom reads can occur";
+                break;
+            case Connection.TRANSACTION_SERIALIZABLE:
+                tx = "dirty reads, non-repeatable reads and phantom reads are prevented";
+                break;
+            default:
+                tx = "";
+                break;
+            }
+
+            derbyDBInfo.put("Default Transaction Isolation", removeNull(tx));
+            String holdability = null;
+
+            switch (dbMD.getResultSetHoldability()) {
+            case ResultSet.HOLD_CURSORS_OVER_COMMIT:
+                holdability = "hold cursors over commit";
+                break;
+            case ResultSet.CLOSE_CURSORS_AT_COMMIT:
+                holdability = "close cursors at commit";
+                break;
+            default:
+                holdability = "";
+                break;
+            }
+            derbyDBInfo.put("Result Set Holdability", removeNull(holdability));
+            String sqlStateType = null;
+
+            switch (dbMD.getSQLStateType()) {
+            case DatabaseMetaData.sqlStateXOpen:
+                sqlStateType = "X/Open SQL CLI";
+                break;
+            case DatabaseMetaData.sqlStateSQL99:
+                sqlStateType = "SQL99";
+                break;
+            default:
+                sqlStateType = "";
+                break;
+            }
+            derbyDBInfo.put("SQL State Type", removeNull(sqlStateType));
+        } catch (SQLException e) {
+            printSQLError((SQLException) e);
+        } finally {
+            // close DB connection
+            try {
+                if (conn != null) {
+                    conn.close();
+                }
+            } catch (SQLException e) {
+                // problem closing DB connection
+            }
+        }
+
+        return derbyDBInfo;
+    }
+
+    private String removeNull(String s) {
+        return ((s == null) ? "" : s);
+    }
+
+    /**
+     * Get a specific column data as a string separated by ','.
+     *
+     * @param rs
+     * @param colName
+     * @return
+     */
+    private String getColumnData(ResultSet rs, String colName) {
+        StringBuffer result = new StringBuffer();
+        try {
+            ResultSetMetaData rsmd = rs.getMetaData();
+
+            // 1) Get column number
+            int selectedCol = -1;
+            int numberOfColumns = rsmd.getColumnCount();
+            for (int i = 1; i <= numberOfColumns; i++) {
+                String columnName = rsmd.getColumnName(i);
+                if (columnName.equals(colName)) {
+                    selectedCol = i;
+                    break;
+                }
+            }
+
+            // 2) Get data
+            boolean firstData = true;
+            while (rs.next()) {
+                for (int i = 1; i <= numberOfColumns; i++) {
+                    if (i == selectedCol) {
+                        if (firstData) {
+                            firstData = false;
+                        } else {
+                            result.append(',');
+                        }
+                        String columnValue = rs.getString(i);
+                        result.append(columnValue);
+                    }
+                }
+            }
+        } catch (SQLException e) {
+            printSQLError((SQLException) e);
+        }
+
+        return result.toString();
+    }
+
+    /**
+     * Print the SQL exception including chained exceptions
+     * if there is one.
+     *
+     * @param e
+     */
+    private void printSQLError(SQLException e) {
+        while (e != null) {
+            System.out.println(e.toString());
+            e = e.getNextException();
+        }
+    }
+
+}
\ No newline at end of file

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/InternalDBHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/InternalDBHelper.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/InternalDBHelper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/InternalDBPortlet.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/InternalDBPortlet.java?rev=393787&view=auto
==============================================================================
--- geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/InternalDBPortlet.java (added)
+++ geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/InternalDBPortlet.java Thu Apr 13 04:34:08 2006
@@ -0,0 +1,105 @@
+/**
+ *
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.geronimo.console.internaldb;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.WindowState;
+
+import org.apache.geronimo.console.BasePortlet;
+
+public class InternalDBPortlet extends BasePortlet {
+
+    private static final String NORMALVIEW_JSP = "/WEB-INF/view/internaldb/internalDBNormal.jsp";
+
+    private static final String MAXIMIZEDVIEW_JSP = "/WEB-INF/view/internaldb/internalDBMaximized.jsp";
+
+    private static final String HELPVIEW_JSP = "/WEB-INF/view/internaldb/internalDBHelp.jsp";
+
+    private static InternalDBHelper helper = new InternalDBHelper();
+
+    private static Map javaSysInfo = new HashMap();
+
+    private PortletRequestDispatcher normalView;
+
+    private PortletRequestDispatcher maximizedView;
+
+    private PortletRequestDispatcher helpView;
+
+    public void processAction(ActionRequest actionRequest,
+            ActionResponse actionResponse) throws PortletException, IOException {
+        // Getting parameters here because it fails on doView()
+        String rdbms = actionRequest.getParameter("rdbms");
+        if (rdbms != null) {
+            actionResponse.setRenderParameter("rdbms", rdbms);
+        }
+    }
+
+    protected void doView(RenderRequest renderRequest,
+            RenderResponse renderResponse) throws IOException, PortletException {
+        if (WindowState.MINIMIZED.equals(renderRequest.getWindowState())) {
+            return;
+        }
+
+        String rdbmsParam = renderRequest.getParameter("rdbms");
+        int rdbms = 1;
+        if ((rdbmsParam != null) && (rdbmsParam.length() > 0)) {
+            rdbms = Integer.parseInt(rdbmsParam);
+        }
+        Map internalDB = helper.getDBInfo();
+        renderRequest.setAttribute("internalDB", internalDB);
+
+        if (WindowState.NORMAL.equals(renderRequest.getWindowState())) {
+            normalView.include(renderRequest, renderResponse);
+        } else {
+            maximizedView.include(renderRequest, renderResponse);
+        }
+    }
+
+    protected void doHelp(RenderRequest renderRequest,
+            RenderResponse renderResponse) throws PortletException, IOException {
+        helpView.include(renderRequest, renderResponse);
+    }
+
+    public void init(PortletConfig portletConfig) throws PortletException {
+        super.init(portletConfig);
+        normalView = portletConfig.getPortletContext().getRequestDispatcher(
+                NORMALVIEW_JSP);
+        maximizedView = portletConfig.getPortletContext().getRequestDispatcher(
+                MAXIMIZEDVIEW_JSP);
+        helpView = portletConfig.getPortletContext().getRequestDispatcher(
+                HELPVIEW_JSP);
+    }
+
+    public void destroy() {
+        normalView = null;
+        maximizedView = null;
+        helpView = null;
+        super.destroy();
+    }
+
+}
\ No newline at end of file

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/InternalDBPortlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/InternalDBPortlet.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/InternalDBPortlet.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/RunSQLHelper.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/RunSQLHelper.java?rev=393787&view=auto
==============================================================================
--- geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/RunSQLHelper.java (added)
+++ geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/RunSQLHelper.java Thu Apr 13 04:34:08 2006
@@ -0,0 +1,218 @@
+/**
+ *
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.geronimo.console.internaldb;
+
+import java.io.File;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+public class RunSQLHelper {
+
+    public static final String SQL_SUCCESS_MSG = "SQL command/s successful";
+
+    public static final String SQL_EMPTY_MSG = "SQL Command/s can't be empty";
+
+    private static final String DB_CREATED_MSG = "Database created";
+
+    private static final String DB_DELETED_MSG = "Database deleted";
+
+    private static final String DERBY_BACKUP_FOLDER = "derby.backup";
+
+    private static final String PARENT_FOLDER = "..";
+
+    private static final String BAK_EXTENSION = ".bak";
+
+    private static final String BAK_PREFIX = "BAK_";
+
+    public String createDB(String dbName) {
+        String result = DB_CREATED_MSG + ": " + dbName;
+
+        Connection conn = null;
+        try {
+            conn = DerbyConnectionUtil.getDerbyConnection(dbName,
+                    DerbyConnectionUtil.CREATE_DB_PROP);
+        } catch (Throwable e) {
+            if (e instanceof SQLException) {
+                result = getSQLError((SQLException) e);
+            } else {
+                result = e.getMessage();
+            }
+        } finally {
+            // close DB connection
+            try {
+                if (conn != null) {
+                    conn.close();
+                }
+            } catch (SQLException e) {
+                result = "Problem closing DB connection";
+            }
+        }
+
+        return result;
+    }
+
+    public String backupDB(String derbyHome, String dbName) {
+        return "";
+    }
+
+    public String restoreDB(String derbyHome, String dbName) {
+        return "";
+    }
+
+    public String deleteDB(String derbyHome, String dbName) {
+        String result = DB_DELETED_MSG + ": " + dbName;
+
+        // shutdown database before deleting it
+        if (!shutdownDB(dbName)) {
+            result = "Database not deleted: " + dbName
+                    + " Couldn't shutdown db: " + dbName;
+            return result;
+        }
+
+        try {
+            // create backup folder if not created
+            File derbyBackupFolder = new File(derbyHome + File.separatorChar
+                    + PARENT_FOLDER + File.separatorChar + DERBY_BACKUP_FOLDER);
+            if (!derbyBackupFolder.exists()) {
+                if (!derbyBackupFolder.mkdirs()) {
+                    result = "Database not deleted: " + dbName
+                            + " Derby backup folder not created: "
+                            + derbyBackupFolder;
+                    return result;
+                }
+            }
+
+            File oldDBFolder = new File(derbyHome + File.separatorChar + dbName);
+            if (oldDBFolder.exists()) {
+                // Need to add a prefix because File.createTempFile's first
+                // argument must be a String at least three characters long.
+                File tmpFile = File.createTempFile(BAK_PREFIX + dbName,
+                        BAK_EXTENSION, derbyBackupFolder);
+                File newDBFolder = new File(tmpFile.getAbsolutePath());
+                /*
+                 * Delete temp file and create a temp folder using the temp
+                 * filename
+                 */
+                if (tmpFile.delete()) {
+                    if (newDBFolder.mkdirs()) {
+                        if (!oldDBFolder.renameTo(new File(newDBFolder,
+                                oldDBFolder.getName()))) {
+                            result = "Database not deleted: " + dbName
+                                    + " DB folder not renamed";
+                            return result;
+                        }
+                    }
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return result;
+    }
+
+    public String runSQL(String dbName, String sql) {
+        String result = SQL_SUCCESS_MSG;
+
+        if ((sql == null) || (sql.trim().length() == 0)) {
+            result = SQL_EMPTY_MSG;
+            return result;
+        }
+
+        Connection conn = null;
+        Statement s = null;
+        try {
+
+            conn = DerbyConnectionUtil.getDerbyConnection(dbName);
+            conn.setAutoCommit(false);
+
+            s = conn.createStatement();
+            String[] sqlCmds = sql.split(";");
+            for (int i = 0; i < sqlCmds.length; i++) {
+                if (sqlCmds[i].trim().length() > 0) {
+                    // debug printout (remove later)
+                    System.out.println("SQL" + i + ": <" + sqlCmds[i].trim()
+                            + ">");
+                    s.execute(sqlCmds[i]);
+                }
+            }
+            conn.commit();
+        } catch (Throwable e) {
+            if (e instanceof SQLException) {
+                result = getSQLError((SQLException) e);
+            } else {
+                result = e.getMessage();
+            }
+        } finally {
+            // close DB connection
+            try {
+                if (s != null) {
+                    s.close();
+                }
+                if (conn != null) {
+                    conn.close();
+                }
+            } catch (SQLException e) {
+                if (SQL_SUCCESS_MSG.equals(result)) {
+                    result = "Problem closing DB connection: " + e.getMessage();
+                }
+            }
+        }
+
+        return result;
+    }
+
+    private boolean shutdownDB(String dbName) {
+        boolean ok = true;
+
+        boolean gotSQLExc = false;
+        try {
+            DerbyConnectionUtil.getDerbyConnection(dbName,
+                    DerbyConnectionUtil.SHUTDOWN_DB_PROP);
+        } catch (SQLException se) {
+            gotSQLExc = true;
+        }
+
+        if (!gotSQLExc) {
+            ok = false;
+        }
+
+        return ok;
+    }
+
+    private String getSQLError(SQLException e) {
+        StringBuffer errorMsg = new StringBuffer();
+        while (e != null) {
+            //errorMsg.append(e.toString());
+            errorMsg.append(e.getMessage());
+            errorMsg.append(" * ");
+            e = e.getNextException();
+        }
+
+        return errorMsg.toString();
+    }
+
+    public static void main(String[] args) {
+        new RunSQLHelper().runSQL("derbyDB4",
+                "create table derbyTbl1(num int, addr varchar(40));"
+                        + "create table derbyTbl2(num int, addr varchar(40));"
+                        + "create table derbyTbl3(num int, addr varchar(40));"
+                        + "insert into derb");
+    }
+}

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/RunSQLHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/RunSQLHelper.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/RunSQLHelper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/RunSQLPortlet.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/RunSQLPortlet.java?rev=393787&view=auto
==============================================================================
--- geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/RunSQLPortlet.java (added)
+++ geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/RunSQLPortlet.java Thu Apr 13 04:34:08 2006
@@ -0,0 +1,169 @@
+/**
+ *
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.geronimo.console.internaldb;
+
+import java.io.IOException;
+import java.util.Collection;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.WindowState;
+
+import org.apache.geronimo.console.BasePortlet;
+
+public class RunSQLPortlet extends BasePortlet {
+
+    private static final String NORMALVIEW_JSP = "/WEB-INF/view/internaldb/runSQLNormal.jsp";
+
+    private static final String MAXIMIZEDVIEW_JSP = "/WEB-INF/view/internaldb/runSQLMaximized.jsp";
+
+    private static final String HELPVIEW_JSP = "/WEB-INF/view/internaldb/runSQLHelp.jsp";
+
+    private static final String CREATEDB_ACTION = "Create";
+
+    private static final String DELETEDB_ACTION = "Delete";
+
+    private static final String RUNSQL_ACTION = "Run SQL";
+
+    private static final String BACKUPDB_ACTION = "Backup";
+
+    private static final String RESTOREDB_ACTION = "Restore";
+
+    private static RunSQLHelper sqlHelper = new RunSQLHelper();
+
+    private static DBViewerHelper dbHelper = new DBViewerHelper();
+
+    private static String derbyHome = System.getProperty("derby.system.home");
+
+    private PortletRequestDispatcher normalView;
+
+    private PortletRequestDispatcher maximizedView;
+
+    private PortletRequestDispatcher helpView;
+
+    private Collection databases;
+
+    private String action;
+
+    private String createDB;
+
+    private String deleteDB;
+
+    private String useDB;
+
+    private String backupDB;
+
+    private String restoreDB;
+
+    private String sqlStmts;
+
+    private String actionResult;
+
+    public void processAction(ActionRequest actionRequest,
+            ActionResponse actionResponse) throws PortletException, IOException {
+        // Getting parameters here because it fails on doView()
+        action = actionRequest.getParameter("action");
+        createDB = actionRequest.getParameter("createDB");
+        deleteDB = actionRequest.getParameter("deleteDB");
+        useDB = actionRequest.getParameter("useDB");
+        backupDB = actionRequest.getParameter("backupDB");
+        restoreDB = actionRequest.getParameter("restoreDB");
+        sqlStmts = actionRequest.getParameter("sqlStmts");
+        actionResult = "";
+        if (CREATEDB_ACTION.equals(action)) {
+            actionResult = sqlHelper.createDB(createDB);
+        } else if (DELETEDB_ACTION.equals(action)) {
+            actionResult = sqlHelper.deleteDB(derbyHome, deleteDB);
+        } else if (RUNSQL_ACTION.equals(action)) {
+            actionResult = sqlHelper.runSQL(useDB, sqlStmts);
+        } else if (BACKUPDB_ACTION.equals(action)) {
+            actionResult = sqlHelper.backupDB(derbyHome, backupDB);
+        } else if (RESTOREDB_ACTION.equals(action)) {
+            actionResult = sqlHelper.restoreDB(derbyHome, restoreDB);
+        }
+    }
+
+    protected void doView(RenderRequest renderRequest,
+            RenderResponse renderResponse) throws IOException, PortletException {
+        if (WindowState.MINIMIZED.equals(renderRequest.getWindowState())) {
+            return;
+        }
+
+        String singleSelectStmt;
+        if (WindowState.NORMAL.equals(renderRequest.getWindowState())) {
+            databases = dbHelper.getDerbyDatabases(derbyHome);
+            renderRequest.setAttribute("databases", databases);
+            if (RUNSQL_ACTION.equals(action)) {
+                // check if it's a single Select statement
+                if ((sqlStmts != null) && (sqlStmts.trim().indexOf(';') == -1)
+                        && sqlStmts.trim().toUpperCase().startsWith("SELECT")
+                        && RunSQLHelper.SQL_SUCCESS_MSG.equals(actionResult)) {
+                    singleSelectStmt = sqlStmts.trim();
+                    // set action result to blank so it won't display
+                    actionResult = "";
+                } else {
+                    singleSelectStmt = "";
+                }
+                renderRequest.setAttribute("useDB", useDB);
+                renderRequest
+                        .setAttribute("singleSelectStmt", singleSelectStmt);
+                renderRequest.setAttribute("ds", DerbyConnectionUtil
+                        .getDataSource(useDB));
+            }
+            if ((action != null) && (action.trim().length() > 0)) {
+                renderRequest.setAttribute("actionResult", actionResult);
+                //set action to null so that subsequent renders of portlet
+                // won't display
+                //action result if there is no action to process
+                action = null;
+            }
+            normalView.include(renderRequest, renderResponse);
+        } else {
+            maximizedView.include(renderRequest, renderResponse);
+        }
+    }
+
+    protected void doHelp(RenderRequest renderRequest,
+            RenderResponse renderResponse) throws PortletException, IOException {
+        helpView.include(renderRequest, renderResponse);
+    }
+
+    public void init(PortletConfig portletConfig) throws PortletException {
+        super.init(portletConfig);
+        normalView = portletConfig.getPortletContext().getRequestDispatcher(
+                NORMALVIEW_JSP);
+        maximizedView = portletConfig.getPortletContext().getRequestDispatcher(
+                MAXIMIZEDVIEW_JSP);
+        helpView = portletConfig.getPortletContext().getRequestDispatcher(
+                HELPVIEW_JSP);
+        databases = dbHelper.getDerbyDatabases(derbyHome);
+    }
+
+    public void destroy() {
+        normalView = null;
+        maximizedView = null;
+        helpView = null;
+        super.destroy();
+    }
+
+}

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/RunSQLPortlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/RunSQLPortlet.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/internaldb/RunSQLPortlet.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain