[Rapforums-developer] src/source/edu/fullcoll/uportal/channels/rap/forum/tools SQLTask.java,NONE,1.1
Status: Beta
Brought to you by:
brippe
From: <br...@us...> - 2003-09-25 23:04:27
|
Update of /cvsroot/rapforums/src/source/edu/fullcoll/uportal/channels/rap/forum/tools In directory sc8-pr-cvs1:/tmp/cvs-serv19426 Added Files: SQLTask.java Log Message: no message --- NEW FILE: SQLTask.java --- /** * Copyright (C) 2003, Fullerton College. All Rights Reserved. * (http://www.fullcoll.edu) * * This software is distributed under the IBM Public Licence. Please see * the license infomation for more details at http://www.opensource.org/licenses/ibmpl.php. * EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED * ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER * EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. * Each Recipient is solely responsible for determining the appropriateness of using * and distributing the Program and assumes all risks associated with its exercise * of rights under this Agreement, including but not limited to the risks and costs * of program errors, compliance with applicable laws, damage to or loss of data, * programs or equipment, and unavailability or interruption of operations. * * This software is OSI Certified Open Source Software. * OSI Certified is a certification mark of the Open Source Initiative */ package edu.fullcoll.uportal.channels.rap.forum.tools; import java.sql.Connection; import java.sql.Statement; import java.sql.DatabaseMetaData; import java.io.File; import java.util.List; import java.util.Iterator; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Task; import org.jasig.portal.RDBMServices; import org.jdom.input.SAXBuilder; import org.jdom.Document; import org.jdom.Element; /** * This class is a custom Ant Task that reads an xml file and sets the * default values for the forum tables and creates the paging stored procedures. * * @author Brad Rippe (br...@fu...) * @version 0.8.2 $Revision %G% */ public class SQLTask extends Task { // The method executing the task public void execute() throws BuildException { Connection con = null; Statement stmt = null; try { System.out.println("Reading "+scriptXML+"..."); SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(new File(scriptXML)); rdbmService = new RDBMServices(); con = rdbmService.getConnection(); if(con != null) { DatabaseMetaData dbMD = con.getMetaData(); System.out.println("Connecting to "+dbMD.getDatabaseProductName()+" "+dbMD.getDatabaseProductVersion()); System.out.println(dbMD.getURL()); stmt = con.createStatement(); Element root = doc.getRootElement(); Element alterTables = root.getChild("alterTables"); List alters = alterTables.getChildren("alter"); Iterator i = alters.iterator(); System.out.println("Executing table default values..."); while(i.hasNext()) { Element element = (Element) i.next(); stmt.executeUpdate(element.getText()); } Element storedProcedureElement = root.getChild("storedProcedures"); List sProcedures = storedProcedureElement.getChildren("storedProcedure"); Iterator j = sProcedures.iterator(); System.out.println("Creating forums paging stored procedures..."); while(j.hasNext()) { Element element = (Element) j.next(); stmt.executeUpdate(element.getText()); } rdbmService.releaseConnection(con); } else { System.out.println("Connection is null"); } } catch (Exception e) { e.printStackTrace(); } finally { try { stmt.close(); } catch (Exception e) {} } } public void setScriptXML(String scriptXML) { this.scriptXML = scriptXML; } private RDBMServices rdbmService; private String scriptXML = null; } |