001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999-2004 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: ApplyDatasourceAction.java 9680 2006-10-06 12:08:33Z danesa $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.webapp.jonasadmin.service.db;
025:
026: import java.io.IOException;
027:
028: import javax.management.ObjectName;
029: import javax.servlet.ServletException;
030: import javax.servlet.http.HttpServletRequest;
031: import javax.servlet.http.HttpServletResponse;
032:
033: import org.apache.struts.action.ActionForm;
034: import org.apache.struts.action.ActionForward;
035: import org.apache.struts.action.ActionMapping;
036: import org.objectweb.jonas.jmx.J2eeObjectName;
037: import org.objectweb.jonas.jmx.JonasManagementRepr;
038: import org.objectweb.jonas.jmx.JonasObjectName;
039: import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
040:
041: /**
042: * @author Michel-Ange ANTON
043: * @author Adriana Danes
044: */
045:
046: public class ApplyDatasourceAction extends JonasBaseAction {
047:
048: // --------------------------------------------------------- Public Methods
049:
050: public ActionForward executeAction(ActionMapping p_Mapping,
051: ActionForm p_Form, HttpServletRequest p_Request,
052: HttpServletResponse p_Response) throws IOException,
053: ServletException {
054:
055: // Form used
056: DatasourceForm oForm = (DatasourceForm) p_Form;
057: try {
058: String domainName = m_WhereAreYou.getCurrentDomainName();
059: String serverName = m_WhereAreYou
060: .getCurrentJonasServerName();
061: populate(oForm, domainName, serverName);
062: if (oForm.getAction().equals("save") == true) {
063: save(oForm, domainName, serverName);
064: }
065: } catch (Throwable t) {
066: addGlobalError(t);
067: saveErrors(p_Request, m_Errors);
068: return (p_Mapping.findForward("Global Error"));
069: }
070: // Forward to the jsp and add the parameter 'name' with the good value.
071: return new ActionForward(p_Mapping.findForward(
072: "ActionEditDatasource").getPath()
073: + "?name=" + oForm.getDatasourceName());
074: }
075:
076: // --------------------------------------------------------- Protected Methods
077:
078: protected void populate(DatasourceForm p_Form, String domainName,
079: String serverName) throws Exception {
080: // Object name used
081: ObjectName oObjectName = J2eeObjectName.getJDBCDataSource(
082: domainName, serverName, p_Form.getDatasourceName());
083: // Populate
084: setIntegerAttribute(oObjectName, "jdbcConnMaxAge", p_Form
085: .getJdbcConnMaxAge());
086: setIntegerAttribute(oObjectName, "jdbcMaxOpenTime", p_Form
087: .getJdbcMaxOpenTime());
088: setIntegerAttribute(oObjectName, "jdbcMaxConnPool", p_Form
089: .getJdbcMaxConnPool());
090: setIntegerAttribute(oObjectName, "jdbcMinConnPool", p_Form
091: .getJdbcMinConnPool());
092: setIntegerAttribute(oObjectName, "jdbcMaxWaitTime", p_Form
093: .getJdbcMaxWaitTime());
094: setIntegerAttribute(oObjectName, "jdbcMaxWaiters", p_Form
095: .getJdbcMaxWaiters());
096: setIntegerAttribute(oObjectName, "jdbcSamplingPeriod", p_Form
097: .getJdbcSamplingPeriod());
098: setIntegerAttribute(oObjectName, "jdbcPstmtMax", p_Form
099: .getJdbcPstmtMax());
100: setIntegerAttribute(oObjectName, "jdbcConnCheckLevel", p_Form
101: .getJdbcConnCheckLevel());
102: String testStmt = p_Form.getJdbcTestStatement();
103: String[] values = { testStmt };
104: String[] signatures = { "java.lang.String" };
105: String op = "setJdbcTestStatement";
106: String result = (String) JonasManagementRepr.invoke(
107: oObjectName, op, values, signatures, serverName);
108: if (!result.equals(testStmt)) {
109: throw new Exception(result);
110: }
111: }
112:
113: protected void save(DatasourceForm p_Form, String domainName,
114: String serverName) throws Exception {
115: // Save
116: JonasManagementRepr.invoke(J2eeObjectName.getJDBCDataSource(
117: domainName, serverName, p_Form.getDatasourceName()),
118: "saveConfig", null, null, serverName);
119: }
120:
121: }
|