You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by to...@apache.org on 2004/01/29 00:27:32 UTC
cvs commit: db-ojb/src/java/org/apache/ojb/broker/ant RepositoryVerifierHandler.java VerifyMappingsTask.java DBUtility.java
tomdz 2004/01/28 15:27:32
Modified: src/java/org/apache/ojb/broker/ant
RepositoryVerifierHandler.java
VerifyMappingsTask.java DBUtility.java
Log:
Changed verification ant task so that uses the classpath tag instead of the verifyClassPath attribute.
Revision Changes Path
1.12 +12 -16 db-ojb/src/java/org/apache/ojb/broker/ant/RepositoryVerifierHandler.java
Index: RepositoryVerifierHandler.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/ant/RepositoryVerifierHandler.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- RepositoryVerifierHandler.java 2 Jan 2003 21:27:19 -0000 1.11
+++ RepositoryVerifierHandler.java 28 Jan 2004 23:27:32 -0000 1.12
@@ -253,9 +253,9 @@
try
{
- m_currentClass = Class.forName(classname, true, m_callingTask.getClassLoader());
+ m_currentClass = m_callingTask.loadClass(classname);
}
- catch (Exception ex)
+ catch (ClassNotFoundException ex)
{
//logger.error(ex);
throw new MetadataException("Can't load class-descriptor class '" + classname + "'.");
@@ -283,9 +283,9 @@
try
{
- Class classExtent = Class.forName(classname, true, m_callingTask.getClassLoader());
+ Class classExtent = m_callingTask.loadClass(classname);
}
- catch (Exception ex)
+ catch (ClassNotFoundException ex)
{
//logger.error(ex);
throw new MetadataException("Can't load extent-class class '" + classname + "'.");
@@ -341,9 +341,9 @@
try
{
//Confirm that class 'class-ref' can be loaded.
- Class refClass = Class.forName(classRef, true, m_callingTask.getClassLoader());
+ Class refClass = m_callingTask.loadClass(classRef);
}
- catch (Exception ex)
+ catch (ClassNotFoundException ex)
{
//logger.error(ex);
throw new MetadataException("Can't find class-ref '" + classRef + "' in reference-descriptor '" + name + "'.");
@@ -370,9 +370,9 @@
try
{
//Confirm that class 'class-ref' can be loaded.
- Class oCollectionClass = Class.forName(collectionClass, true, m_callingTask.getClassLoader());
+ Class oCollectionClass = m_callingTask.loadClass(collectionClass);
}
- catch (Exception ex)
+ catch (ClassNotFoundException ex)
{
//logger.error(ex);
throw new MetadataException("Can't find collection-class '" + collectionClass + "' in collection-descriptor '" + name + "'.");
@@ -386,9 +386,9 @@
try
{
//Confirm that class 'class-ref' can be loaded.
- Class oElementClassRef = Class.forName(elementClassRef, true, m_callingTask.getClassLoader());
+ Class oElementClassRef = m_callingTask.loadClass(elementClassRef);
}
- catch (Exception ex)
+ catch (ClassNotFoundException ex)
{
//logger.error(ex);
throw new MetadataException("Can't find element-class-ref '" + elementClassRef + "' in collection-descriptor '" + name + "'.");
@@ -635,11 +635,7 @@
try
{
- retval = new DBUtility(driver, url, userName, password, m_callingTask.getClassLoader());
- }
- catch(MalformedURLException murle)
- {
- throw murle;
+ retval = new DBUtility(url, userName, password, m_callingTask.loadClass(driver));
}
catch(ClassNotFoundException cnfe)
{
1.6 +447 -483 db-ojb/src/java/org/apache/ojb/broker/ant/VerifyMappingsTask.java
Index: VerifyMappingsTask.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/ant/VerifyMappingsTask.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- VerifyMappingsTask.java 8 Jul 2003 20:32:05 -0000 1.5
+++ VerifyMappingsTask.java 28 Jan 2004 23:27:32 -0000 1.6
@@ -1,111 +1,360 @@
package org.apache.ojb.broker.ant;
-/* ====================================================================
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 2001 The Apache Software Foundation. All rights
- * reserved.
- *
+/*
+ * ==================================================================== The
+ * Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights reserved.
+ *
* Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Apache" and "Apache Software Foundation" and
- * "Apache ObjectRelationalBridge" must not be used to endorse or promote products
- * derived from this software without prior written permission. For
- * written permission, please contact apache@apache.org.
- *
- * 5. Products derived from this software may not be called "Apache",
- * "Apache ObjectRelationalBridge", nor may "Apache" appear in their name, without
- * prior written permission of the Apache Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The end-user documentation included with the redistribution, if any,
+ * must include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if and
+ * wherever such third-party acknowledgments normally appear.
+ * 4. The names "Apache" and "Apache Software Foundation" and "Apache
+ * ObjectRelationalBridge" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ * 5. Products derived from this software may not be called "Apache", "Apache
+ * ObjectRelationalBridge", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation. For more information on the
+ * Apache Software Foundation, please see <http://www.apache.org/> .
*/
-
import java.io.FileInputStream;
import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLClassLoader;
import java.util.Properties;
-import java.util.StringTokenizer;
-
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
-
import org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldPrivilegedImpl;
+import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
+import org.apache.tools.ant.types.Path;
+import org.apache.tools.ant.types.Reference;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
/**
- * An Ant task that will read the OJB repository xml file and confirm the
+ * An Ant task that will read the OJB repository xml file and confirm the
* following:
*
- * a)Mapped classes exist.
- * b)Mapped class fields exist
- * c)Mapped database tables exist.
- * d)Mapped database columns exist.
- * e)Mapped database columns jdbc type matches
- * the <code><field-descriptor/></code>
- "jdbc-type" attribute.
+ * a)Mapped classes exist. b)Mapped class fields exist c)Mapped database tables
+ * exist. d)Mapped database columns exist. e)Mapped database columns jdbc type
+ * matches the <code><field-descriptor/></code> "jdbc-type" attribute.
+ *
+ * Obviously you should have built your classes, written your OJB
+ * repository.xml file and built your database schema before running this task.
*
- * Obviously you should have built your classes, written your OJB repository.xml
- * file and built your database schema before running this task.
- *
* @author <a href="mailto:daren@softwarearena.com">Daren Drummond</a>
* @version $Id$
*/
-public class VerifyMappingsTask extends Task
+public class VerifyMappingsTask extends Task
{
+ private int m_errorCount = 0;
+ private int m_warningCount = 0;
+ private String m_repositoryPath = null;
+ private String m_PropertiesFile = null;
+ private String m_jdbcDriver = null;
+ private String m_url = null;
+ private String m_logon = null;
+ private String m_password = null;
+ private boolean m_ignoreCase = false;
+ private boolean m_UseStrictTypeChecking = true;
+ private Class m_persistenceClass = null;
+ private boolean m_useXMLValidation = true;
+ private boolean m_failOnError = true;
+
+ private Path _classpath;
- public void execute () throws BuildException
+ public void setRepositoryFile(String path)
+ {
+ m_repositoryPath = path;
+ }
+
+ /**
+ * Gets the path to the OJB repository file. (Includes the file name)
+ *
+ * @return The path and file name of the OJB repository file
+ */
+ public String getRepositoryFile()
+ {
+ return m_repositoryPath;
+ }
+
+ /**
+ * Sets the fully qualified path and file name of the OJB properties file.
+ *
+ * @param path The path and file name of the OJB properties file
+ */
+ public void setPropertiesFile(String path)
+ {
+ m_PropertiesFile = path;
+ }
+
+ /**
+ * Gets the value set by setPropertiesFile(String path)
+ *
+ * @return The path and file name of the OJB properties file
+ */
+ public String getPropertiesFile()
+ {
+ return m_PropertiesFile;
+ }
+
+ /**
+ * Sets the fully qualified class name of the jdbc driver to use.
+ *
+ * @param jdbcClass Fully qualified class name of the jdbc driver
+ */
+ public void setJdbcDriver(String jdbcClass)
+ {
+ m_jdbcDriver = jdbcClass;
+ }
+
+ /**
+ * Gets the value set by setJdbcDriver(String jdbcClass)
+ *
+ * @return Fully qualified class name of the jdbc driver
+ */
+ public String getJdbcDriver()
+ {
+ return m_jdbcDriver;
+ }
+
+ /**
+ * Sets the url connection string for the jdbc driver.
+ *
+ * @param url The connection string for the jdbc driver
+ */
+ public void setUrl(String url)
+ {
+ m_url = url;
+ }
+
+ /**
+ * Gets the value set by setUrl(String url)
+ *
+ * @return The connection string for the jdbc driver
+ */
+ public String getUrl()
+ {
+ return m_url;
+ }
+
+ /**
+ * Sets the database logon account that the utility should use.
+ *
+ * @param logon The database logon account
+ */
+ public void setLogon(String logon)
+ {
+ m_logon = logon;
+ }
+
+ /**
+ * Gets the value set by setLogon(String logon)
+ *
+ * @return The database logon account
+ */
+ public String getLogon()
+ {
+ return m_logon;
+ }
+
+ /**
+ * Sets the password for the database logon account.
+ *
+ * @param password The password for the database logon account
+ */
+ public void setPassword(String password)
+ {
+ m_password = password;
+ }
+
+ /**
+ * Gets the value set by setPassword(String password)
+ *
+ * @return The password for the database logon account
+ */
+ public String getPassword()
+ {
+ return m_password;
+ }
+
+ /**
+ * Turns on W3C xml validation of the OJB repository.xml file (on by default).
+ *
+ * @param sValidationFlag Whether to validate the xml
+ */
+ public void setUseXMLValidation(String sValidationFlag)
+ {
+ m_useXMLValidation = Boolean.valueOf(sValidationFlag).booleanValue();
+ }
+
+ /**
+ * Determines whether the xml syntax is verified.
+ *
+ * @return A flag indicating if W3c xml validation will be used to
+ * verify the OJB repository.xml file
+ */
+ public boolean getUseXMLValidation()
+ {
+ return m_useXMLValidation;
+ }
+
+ /**
+ * Sets a flag indicating that this Ant task should throw a BuildException
+ * if it encounters any verification errors. In most cases, this will have
+ * the effect of stopping the build process.
+ *
+ * @param sFailFlag Whether to stop the task upon the first error
+ */
+ public void setFailOnError(String sFailFlag)
+ {
+ m_failOnError = Boolean.valueOf(sFailFlag).booleanValue();
+ }
+
+ /**
+ * Determines whether this task stops by throwing a BuildException when the first
+ * error is encountered.
+ *
+ * @return A flag indicating that the Ant task will throw a
+ * BuildException if it encounters any validation errors
+ */
+ public boolean getFailOnError()
+ {
+ return m_failOnError;
+ }
+
+ /**
+ * Sets the flag for ignoring the db column name case when looking for db
+ * columns.
+ *
+ * @param sIgnoreCaseFlag Whether the case of the db column name is ignored
+ */
+ public void setIgnoreFieldNameCase(String sIgnoreCaseFlag)
+ {
+ m_ignoreCase = Boolean.valueOf(sIgnoreCaseFlag).booleanValue();
+ }
+
+ /**
+ * Determines whether the task ignores the case of the db column name case
+ * when looking for db columns.
+ *
+ * @return Flag indicating if the field name case will be
+ * ignored when searching for table column names
+ */
+ public boolean getIgnoreFieldNameCase()
+ {
+ return m_ignoreCase;
+ }
+
+ /**
+ * Sets the flag for stict type checking of database column types. If this
+ * value is set to "true" then the task will log a warning if the table
+ * column jdbc type doesn't match the type specified in the OJB repository
+ * field descriptor.
+ *
+ * @param sTypeCheckingFlag Whether to use strict type checking
+ */
+ public void setUseStrictTypeChecking(String sTypeCheckingFlag)
+ {
+ m_UseStrictTypeChecking = Boolean.valueOf(sTypeCheckingFlag)
+ .booleanValue();
+ }
+
+ /**
+ * Gets the boolean equivalent of the value set by
+ * setUseStrictTypeChecking(String sTypeCheckingFlag)
+ *
+ * @return Flag indicating if strict type checking will be
+ * used when searching for database table columns
+ */
+ public boolean getUseStrictTypeChecking()
+ {
+ return m_UseStrictTypeChecking;
+ }
+
+ /**
+ * Set the classpath for loading the driver.
+ *
+ * @param classpath the classpath
+ */
+ public void setClasspath(Path classpath)
+ {
+ if (_classpath == null)
+ {
+ _classpath = classpath;
+ }
+ else
+ {
+ _classpath.append(classpath);
+ }
+ log("Verification classpath is "+ _classpath,
+ Project.MSG_VERBOSE);
+ }
+
+ /**
+ * Create the classpath for loading the driver.
+ *
+ * @return the classpath
+ */
+ public Path createClasspath()
{
- if(this.getRepositoryFile() == null)
- throw new BuildException("Could not find the repository file.");
+ if (_classpath == null)
+ {
+ _classpath = new Path(getProject());
+ }
+ return _classpath.createPath();
+ }
+ /**
+ * Set the classpath for loading the driver using the classpath reference.
+ *
+ * @param r reference to the classpath
+ */
+ public void setClasspathRef(Reference r)
+ {
+ createClasspath().setRefid(r);
+ log("Verification classpath is "+ _classpath,
+ Project.MSG_VERBOSE);
+ }
+
+ public void execute() throws BuildException
+ {
+ if (getRepositoryFile() == null)
+ {
+ throw new BuildException("Could not find the repository file.");
+ }
try
{
System.setProperty("OJB.properties", getPropertiesFile());
-
//Thread.currentThread().setContextClassLoader(getClassLoader());
-
logWarning("IgnoreFieldNameCase: " + String.valueOf(getIgnoreFieldNameCase()));
logWarning("UseStrictTypeChecking: " + String.valueOf(getUseStrictTypeChecking()));
logWarning("UseXMLValidation: " + String.valueOf(getUseXMLValidation()));
@@ -113,451 +362,166 @@
verifyRepository(getRepositoryFile());
logWarning(getSummaryString(getErrorCount(), getWarningCount()));
}
- catch(Exception e)
+ catch (Exception e)
{
- logWarning("There was an exception while verifying the repsitory: " + e.getMessage());
- if(getFailOnError())
+ logWarning("There was an exception while verifying the repsitory: " + e.getMessage());
+ if (getFailOnError())
{
- throw new BuildException("There was an exception while verifying the repsitory.", e);
+ throw new BuildException("There was an exception while verifying the repsitory.", e);
}
}
- if(getFailOnError() && getErrorCount() > 0)
+ if (getFailOnError() && (getErrorCount() > 0))
{
- throw new BuildException("Failed because 'failonerror' = true and there are " + String.valueOf(getErrorCount()) + " mapping error(s).");
+ throw new BuildException("Failed because 'failonerror' = true and there are " +
+ String.valueOf(getErrorCount()) + " mapping error(s).");
}
-
}
-
private String getSummaryString(int iBadCount, int iWarningCount)
{
- return "\n---------------------------------------------------\n Found " +
- String.valueOf(iBadCount) +
- " error(s) in the repository. \n Found " + String.valueOf(iWarningCount) +
- " warning(s) in the repository. \n---------------------------------------------------";
+ return "\n---------------------------------------------------\n Found " +
+ String.valueOf(iBadCount)+
+ " error(s) in the repository. \n Found "+
+ String.valueOf(iWarningCount)+
+ " warning(s) in the repository. \n---------------------------------------------------";
}
-
-
-
- private void verifyRepository(String repositoryFile)
- throws ParserConfigurationException, SAXException, IOException
- //throws MalformedURLException, ParserConfigurationException, SAXException, IOException
+
+ private void verifyRepository(String repositoryFile) throws ParserConfigurationException,
+ SAXException,
+ IOException
{
log("verifyRepository: Entered.");
- long start = System.currentTimeMillis();
- // get a xml reader instance:
- SAXParser p = SAXParserFactory.newInstance().newSAXParser();
- XMLReader reader = null;
- reader = p.getXMLReader();
- reader.setFeature("http://xml.org/sax/features/validation", getUseXMLValidation());
+ long start = System.currentTimeMillis();
+ SAXParser p = SAXParserFactory.newInstance().newSAXParser();
+ XMLReader reader = p.getXMLReader();
+
+ reader.setFeature("http://xml.org/sax/features/validation",
+ getUseXMLValidation());
- // create handler for verifying the repository structure
+ // create handler for verifying the repository structure
ContentHandler handler = new RepositoryVerifierHandler(this);
+
logInfo("Starting Parser...");
reader.setContentHandler(handler);
reader.parse(repositoryFile);
logInfo("Done Parsing.");
long stop = System.currentTimeMillis();
-
+
setErrorCount(((RepositoryVerifierHandler)handler).getErrorCount());
setWarningCount(((RepositoryVerifierHandler)handler).getWarningCount());
-
logWarning("loading XML took " + (stop - start) + " msecs");
-
}
-
+
/**
* Log a warning with the Ant out stream.
*
- * @param msg String, the message to log.
- *
+ * @param msg The message to log
*/
public void logWarning(String msg)
{
- log(msg, Project.MSG_WARN);
+ log(msg, Project.MSG_WARN);
}
-
+
/**
- * Log an Info message with the Ant out stream.
- * Info messages can be suppressed from the command line
- * by starting ant with the -quiet option.
- *
- * @param msg String, the message to log.
+ * Log an Info message with the Ant out stream. Info messages can be
+ * suppressed from the command line by starting ant with the -quiet option.
*
- */
+ * @param msg The message to log
+ */
public void logInfo(String msg)
{
- log(msg, Project.MSG_INFO);
- }
-
- private int m_errorCount = 0;
- protected int getErrorCount()
- {
- return m_errorCount;
- }
-
- protected void setErrorCount(int count)
- {
- m_errorCount = count;
- }
-
- private int m_warningCount = 0;
- protected int getWarningCount()
- {
- return m_warningCount;
- }
-
- protected void setWarningCount(int count)
- {
- m_warningCount = count;
- }
-
- private String m_repositoryPath = null;
- public void setRepositoryFile(String path)
- {
- m_repositoryPath = path;
- }
-
- /**
- * Gets the path to the OJB repository file. (Includes the file name)
- *
- * @return String the path and file name of the OJB repository file.
- */
- public String getRepositoryFile()
- {
- return m_repositoryPath;
- }
-
- private String m_PropertiesFile = null;
-
- /**
- * Sets the fully qualified path and file name of the OJB properties file.
- *
- * @param String the path and file name of the OJB properties file.
- */
- public void setPropertiesFile(String path)
- {
- m_PropertiesFile = path;
- }
-
- /**
- * Gets the value set by setPropertiesFile(String path)
- *
- * @return String the path and file name of the OJB properties file.
- */
- public String getPropertiesFile()
- {
- return m_PropertiesFile ;
- }
-
- private String m_jdbcDriver = null;
-
- /**
- * Sets the fully qualified class name of the jdbc driver to use.
- *
- * @param String fully qualified class name of the jdbc driver.
- */
- public void setJdbcDriver(String jdbcClass)
- {
- m_jdbcDriver = jdbcClass;
- }
-
- /**
- * Gets the value set by setJdbcDriver(String jdbcClass)
- *
- * @return String fully qualified class name of the jdbc driver.
- */
- public String getJdbcDriver()
- {
- return m_jdbcDriver ;
- }
-
- private String m_url = null;
-
- /**
- * Sets the url connection string for the jdbc driver.
- *
- * @param String the connection string for the jdbc driver.
- */
- public void setUrl(String url)
- {
- m_url = url;
- }
-
- /**
- * Gets the value set by setUrl(String url)
- *
- * @return String the connection string for the jdbc driver.
- */
- public String getUrl()
- {
- return m_url ;
- }
-
- private String m_logon = null;
-
- /**
- * Sets the database logon account that the utility should use.
- *
- * @param String the database logon account.
- */
- public void setLogon(String logon)
- {
- m_logon = logon;
- }
-
- /**
- * Gets the value set by setLogon(String logon)
- *
- * @return String the database logon account.
- */
- public String getLogon()
- {
- return m_logon;
- }
-
- private String m_password = null;
-
- /**
- * Sets the password for the database logon account.
- *
- * @param String the password for the database logon account.
- */
- public void setPassword(String password)
- {
- m_password = password;
- }
-
- /**
- * Gets the value set by setPassword(String password)
- *
- * @return String the password for the database logon account.
- */
- public String getPassword()
- {
- return m_password;
- }
-
- /**
- * Tests to see if the jdbc connection information was specified in the tag xml.
- *
- * @return boolean returns true if the jdbc connection information was supplied
- * in the tag xml.
- */
- public boolean hasConnectionInfo()
- {
- return ( m_jdbcDriver != null &&
- m_url != null &&
- m_logon != null &&
- m_password != null);
- }
-
- private boolean m_ignoreCase = false;
-
- /**
- * Sets the flag for ignoring the db column name case when looking for db columns.
- *
- * @param sIgnoreCaseFlag "true" or "false".
- */
- public void setIgnoreFieldNameCase(String sIgnoreCaseFlag)
- {
- m_ignoreCase = Boolean.valueOf(sIgnoreCaseFlag).booleanValue();
-
- }
-
- /**
- * Gets the boolean equivalent of the value set by setIgnoreFieldNameCase(String sIgnoreCaseFlag)
- *
- * @return boolean flag value indicating if field name case will be considered
- * when searching for table column names.
- */
- public boolean getIgnoreFieldNameCase()
- {
- return m_ignoreCase;
- }
-
- private boolean m_UseStrictTypeChecking = true;
-
- /**
- * Sets the flag for stict type checking of database column types. If this value is
- * set to "true" then the task will log a warning if the table column jdbc type doesn't
- * match the type specified in the OJB repository field descriptor.
- *
- * @param sTypeCheckingFlag "true" or "false".
- */
- public void setUseStrictTypeChecking(String sTypeCheckingFlag)
- {
- m_UseStrictTypeChecking = Boolean.valueOf(sTypeCheckingFlag).booleanValue();
-
- }
-
- /**
- * Gets the boolean equivalent of the value set by setUseStrictTypeChecking(String sTypeCheckingFlag)
- *
- * @return boolean flag value indicating if strict type checking will be used when
- * searching for database table columns.
- */
- public boolean getUseStrictTypeChecking()
- {
- return m_UseStrictTypeChecking;
- }
-
- private String m_classPath = null;
-
- /**
- * Sets the classpath for loading the classes specified by the
- * <code><class-descriptor></class-descriptor></code> tags in the
- * OJB repository.xml file.
- *
- * @param classpath String representation of the classpath to used to
- * initialize the classloader.
- */
- public void setVerifyClassPath(String classpath)
- {
- m_classPath = classpath;
-
- }
-
- /**
- * Returns the value set by setVerifyClassPath(String classpath)
- *
- * @return String String representation of the classpath to used to
- * initialize the classloader.
- */
- public String getVerifyClassPath()
- {
- return m_classPath;
- }
-
- private URLClassLoader m_classLoader = null;
-
- /**
- * Returns ClassLoader used to load the classes specified
- * by the <code><class-descriptor></class-descriptor></code> tags in
- * the OJB repository.xml file.
- *
- * @return URLClassLoader ClassLoader initialized with the classpath
- * specified by etVerifyClassPath(String classpath)
- */
- public URLClassLoader getClassLoader() throws MalformedURLException
- {
- if (m_classLoader == null)
- {
- logInfo("Initializing ClassLoader...");
- m_classLoader = URLClassLoader.newInstance(getURLArray(), null);
- Thread.currentThread().setContextClassLoader(m_classLoader);
- logInfo("Done Initializing ClassLoader.");
- }
- return m_classLoader;
-
- }
-
- private URL[] getURLArray() throws MalformedURLException
- {
- StringTokenizer tokens = new StringTokenizer(cleanClassPath(getVerifyClassPath()), System.getProperty("path.separator"));
- URL[] aURL = new URL[tokens.countTokens()];
- int i = 0;
-
- while(tokens.hasMoreTokens())
- {
- String sURL = tokens.nextToken();
- if(!sURL.endsWith(".jar") && !sURL.endsWith(".zip") && !sURL.endsWith("/")) sURL += "/";
- logInfo("Adding URL: file://" + sURL);
- aURL[i++] = new URL("file://" + sURL);
- }
- return aURL;
- }
-
- private String cleanClassPath(String path)
- {
- return path.replace('\\','/');
- }
-
- private Class m_persistenceClass = null;
-
- /**
- * Returns the Class object of the class specified in the OJB.properties file
- * for the "PersistentFieldClass" property.
- *
- * @return Class The Class object of the "PersistentFieldClass" class
- * specified in the OJB.properties file.
- */
- public Class getPersistentFieldClass()
- {
- if(m_persistenceClass == null)
- {
-
- Properties properties = new Properties();
- try
- {
- this.logWarning("Loading properties file: " + getPropertiesFile());
- properties.load(new FileInputStream(getPropertiesFile()));
- String className = properties.getProperty("PersistentFieldClass");
- m_persistenceClass = Class.forName(className, true, getClassLoader());
- }
- catch (Exception e)
- {
- this.logWarning("Could not load properties file '" + getPropertiesFile() + "'. Using PersistentFieldDefaultImpl.");
- e.printStackTrace();
- m_persistenceClass = PersistentFieldPrivilegedImpl.class;
- }
+ log(msg, Project.MSG_INFO);
+ }
+
+ protected int getErrorCount()
+ {
+ return m_errorCount;
+ }
+
+ protected void setErrorCount(int count)
+ {
+ m_errorCount = count;
+ }
+
+ protected int getWarningCount()
+ {
+ return m_warningCount;
+ }
+
+ protected void setWarningCount(int count)
+ {
+ m_warningCount = count;
+ }
+
+ /**
+ * Tests to see if the jdbc connection information was specified in the tag
+ * xml.
+ *
+ * @return <code>true</code> if the jdbc connection information was
+ * supplied in the tag xml
+ */
+ public boolean hasConnectionInfo()
+ {
+ return (m_jdbcDriver != null && m_url != null && m_logon != null && m_password != null);
+ }
+
+ Class loadClass(String className) throws ClassNotFoundException
+ {
+ if (_classpath != null)
+ {
+ log("Loading " + className + " using AntClassLoader with classpath " + _classpath,
+ Project.MSG_VERBOSE);
+
+ AntClassLoader loader = new AntClassLoader(getProject(), _classpath);
+
+ return loader.loadClass(className);
+ }
+ else
+ {
+ log("Loading " + className + " using system loader.",
+ Project.MSG_VERBOSE);
+ return Class.forName(className);
+ }
+ }
- logWarning("PersistentFieldClass: " + m_persistenceClass.toString());
- }
- return m_persistenceClass;
- }
-
- private boolean m_useXMLValidation = true;
-
- /**
- * Sets the flag to turn on W3C xml validation of the OJB repository.xml file
- *
- * @param sValidationFlag "true" or "false".
- */
- public void setUseXMLValidation(String sValidationFlag)
- {
- m_useXMLValidation = Boolean.valueOf(sValidationFlag).booleanValue();
-
- }
-
- /**
- * Returns the boolean equivalent of the flag set by
- * setUseXMLValidation(String sValidationFlag)
- *
- * @return boolean A flag indicating if W3c xml validation will be used to
- * verify the OJB repository.xml file.
- */
- public boolean getUseXMLValidation()
- {
- return m_useXMLValidation;
- }
-
- private boolean m_failOnError = true;
-
- /**
- * Sets a flag indicating that this Ant task should throw a BuildException
- * if it encounters any verification errors. In most cases, this will have
- * the effect of stopping the build process.
- *
- * @param sFailFlag "true" or "false".
- */
- public void setFailOnError(String sFailFlag)
- {
- m_failOnError = Boolean.valueOf(sFailFlag).booleanValue();
- }
-
- /**
- * Returns the boolean equivalent of the flag set by
- * setFailOnError(String sFailFlag)
- *
- * @return boolean A flag indicating that the Ant task will throw
- * a BuildException if it encounters any validation
- * errors.
- */
- public boolean getFailOnError()
- {
- return m_failOnError;
- }
+ /**
+ * Returns the Class object of the class specified in the OJB.properties
+ * file for the "PersistentFieldClass" property.
+ *
+ * @return Class The Class object of the "PersistentFieldClass" class
+ * specified in the OJB.properties file.
+ */
+ public Class getPersistentFieldClass()
+ {
+ if (m_persistenceClass == null)
+ {
+ Properties properties = new Properties();
+ try
+ {
+ this.logWarning("Loading properties file: " + getPropertiesFile());
+ properties.load(new FileInputStream(getPropertiesFile()));
+ }
+ catch (IOException e)
+ {
+ this.logWarning("Could not load properties file '" + getPropertiesFile()
+ + "'. Using PersistentFieldDefaultImpl.");
+ e.printStackTrace();
+ }
+ try
+ {
+ String className = properties.getProperty("PersistentFieldClass");
+
+ m_persistenceClass = loadClass(className);
+ }
+ catch (ClassNotFoundException e)
+ {
+ e.printStackTrace();
+ m_persistenceClass = PersistentFieldPrivilegedImpl.class;
+ }
+ logWarning("PersistentFieldClass: " + m_persistenceClass.toString());
+ }
+ return m_persistenceClass;
+ }
}
1.6 +7 -13 db-ojb/src/java/org/apache/ojb/broker/ant/DBUtility.java
Index: DBUtility.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/ant/DBUtility.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DBUtility.java 13 Mar 2003 19:49:32 -0000 1.5
+++ DBUtility.java 28 Jan 2004 23:27:32 -0000 1.6
@@ -54,7 +54,6 @@
* <http://www.apache.org/>.
*/
-import java.net.URLClassLoader;
import java.sql.*;
import java.util.Hashtable;
@@ -71,35 +70,32 @@
{
private Connection m_connection = null;
- private String m_jdbcDriver = null;
private String m_url = null;
private String m_user = null;
private String m_pwd = null;
- private URLClassLoader m_classLoader = null;
+ private Class m_driver = null;
private static String m_ORA_EXCEPTION_1000 = "ORA-01000";
private static String m_ORA_EXCEPTION_604 = "ORA-00604";
/**
* DBUtility connects to the database in this constructor.
*
- * @param jdbcDriver String representing the jdbc driver class. For example, "org.hsqldb.jdbcDriver".
* @param url String representing the jdbc connection url. For example, "jdbc:hsqldb:target/test/OJB".
* @param user The database user account to use for logging on.
* @param pwd The password for the user
- * @param classLoader The URLClassLoader that has access to the jdbcDriver resource.
+ * @param jdbcDriver The jdbc driver class
*
* @throws SQLException Throws SQLException if there are problems connecting to the database.
* @throws ClassNotFoundException Throws ClassNotFoundException if the jdbc driver class can not be found.
*/
- public DBUtility(String jdbcDriver, String url, String user, String pwd, URLClassLoader classLoader)
+ public DBUtility(String url, String user, String pwd, Class jdbcDriver)
throws SQLException,ClassNotFoundException
{
- m_jdbcDriver = jdbcDriver;
m_url = url;
m_user = user;
m_pwd = pwd;
- m_classLoader = classLoader;
- m_connection = connect(jdbcDriver, url, user, pwd, classLoader);
+ m_driver = jdbcDriver;
+ m_connection = connect(url, user, pwd);
}
public void release() throws SQLException
@@ -115,7 +111,7 @@
try
{
release();
- connect(m_jdbcDriver, m_url, m_user, m_pwd, m_classLoader);
+ connect(m_url, m_user, m_pwd);
}
catch(Exception e)
{
@@ -123,10 +119,8 @@
}
}
- private Connection connect(String jdbcDriver, String url, String user, String pwd, URLClassLoader classLoader)
- throws SQLException,ClassNotFoundException
+ private Connection connect(String url, String user, String pwd) throws SQLException,ClassNotFoundException
{
- Class.forName(jdbcDriver, true, classLoader);
m_connection = DriverManager.getConnection(url, user, pwd);
return m_connection;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org