Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D166495B7 for ; Wed, 30 Nov 2011 21:34:55 +0000 (UTC) Received: (qmail 30041 invoked by uid 500); 30 Nov 2011 21:34:55 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 29980 invoked by uid 500); 30 Nov 2011 21:34:55 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 29973 invoked by uid 99); 30 Nov 2011 21:34:55 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 30 Nov 2011 21:34:55 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 30 Nov 2011 21:34:51 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id F175523889FD for ; Wed, 30 Nov 2011 21:34:29 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1208807 - /commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DatabaseConfiguration.java Date: Wed, 30 Nov 2011 21:34:29 -0000 To: commits@commons.apache.org From: oheger@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111130213429.F175523889FD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: oheger Date: Wed Nov 30 21:34:29 2011 New Revision: 1208807 URL: http://svn.apache.org/viewvc?rev=1208807&view=rev Log: Java 1.5 compatibility: Javadocs, raw types, StringBuilder, etc. Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DatabaseConfiguration.java Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DatabaseConfiguration.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DatabaseConfiguration.java?rev=1208807&r1=1208806&r2=1208807&view=diff ============================================================================== --- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DatabaseConfiguration.java (original) +++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DatabaseConfiguration.java Wed Nov 30 21:34:29 2011 @@ -26,6 +26,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; + import javax.sql.DataSource; import org.apache.commons.logging.LogFactory; @@ -73,16 +74,16 @@ import org.apache.commons.logging.LogFac * String value2 = conf.getString("key2"); * * The configuration can be instructed to perform commits after database updates. - * This is achieved by setting the commits parameter of the + * This is achieved by setting the {@code commits} parameter of the * constructors to true. If commits should not be performed (which is the * default behavior), it should be ensured that the connections returned by the - * DataSource are in auto-commit mode. + * {@code DataSource} are in auto-commit mode. * *

Note: Like JDBC itself, protection against SQL injection is left to the user.

* @since 1.0 * * @author Emmanuel Bourg - * @version $Revision$, $Date$ + * @version $Id$ */ public class DatabaseConfiguration extends AbstractConfiguration { @@ -125,10 +126,10 @@ public class DatabaseConfiguration exten } /** - * Creates a new instance of DatabaseConfiguration that operates on + * Creates a new instance of {@code DatabaseConfiguration} that operates on * a database table containing multiple configurations. * - * @param datasource the DataSource to connect to the database + * @param datasource the {@code DataSource} to connect to the database * @param table the name of the table containing the configurations * @param nameColumn the column containing the name of the configuration * @param keyColumn the column containing the keys of the configuration @@ -166,10 +167,10 @@ public class DatabaseConfiguration exten } /** - * Creates a new instance of DatabaseConfiguration that + * Creates a new instance of {@code DatabaseConfiguration} that * operates on a database table containing a single configuration only. * - * @param datasource the DataSource to connect to the database + * @param datasource the {@code DataSource} to connect to the database * @param table the name of the table containing the configurations * @param keyColumn the column containing the keys of the configuration * @param valueColumn the column containing the values of the configuration @@ -196,9 +197,9 @@ public class DatabaseConfiguration exten /** * Returns the value of the specified property. If this causes a database * error, an error event will be generated of type - * EVENT_READ_PROPERTY with the causing exception. The - * event's propertyName is set to the passed in property key, - * the propertyValue is undefined. + * {@code EVENT_READ_PROPERTY} with the causing exception. The + * event's {@code propertyName} is set to the passed in property key, + * the {@code propertyValue} is undefined. * * @param key the key of the desired property * @return the value of this property @@ -208,7 +209,7 @@ public class DatabaseConfiguration exten Object result = null; // build the query - StringBuffer query = new StringBuffer("SELECT * FROM "); + StringBuilder query = new StringBuilder("SELECT * FROM "); query.append(table).append(" WHERE "); query.append(keyColumn).append("=?"); if (nameColumn != null) @@ -233,7 +234,7 @@ public class DatabaseConfiguration exten ResultSet rs = pstmt.executeQuery(); - List results = new ArrayList(); + List results = new ArrayList(); while (rs.next()) { Object value = rs.getObject(valueColumn); @@ -243,8 +244,8 @@ public class DatabaseConfiguration exten } else { - // Split value if it containts the list delimiter - Iterator it = PropertyConverter.toIterator(value, getListDelimiter()); + // Split value if it contains the list delimiter + Iterator it = PropertyConverter.toIterator(value, getListDelimiter()); while (it.hasNext()) { results.add(it.next()); @@ -271,18 +272,19 @@ public class DatabaseConfiguration exten /** * Adds a property to this configuration. If this causes a database error, - * an error event will be generated of type EVENT_ADD_PROPERTY - * with the causing exception. The event's propertyName is - * set to the passed in property key, the propertyValue + * an error event will be generated of type {@code EVENT_ADD_PROPERTY} + * with the causing exception. The event's {@code propertyName} is + * set to the passed in property key, the {@code propertyValue} * points to the passed in value. * * @param key the property key * @param obj the value of the property to add */ + @Override protected void addPropertyDirect(String key, Object obj) { // build the query - StringBuffer query = new StringBuffer("INSERT INTO " + table); + StringBuilder query = new StringBuilder("INSERT INTO " + table); if (nameColumn != null) { query.append(" (" + nameColumn + ", " + keyColumn + ", " + valueColumn + ") VALUES (?, ?, ?)"); @@ -327,14 +329,15 @@ public class DatabaseConfiguration exten * Adds a property to this configuration. This implementation will * temporarily disable list delimiter parsing, so that even if the value * contains the list delimiter, only a single record will be written into - * the managed table. The implementation of getProperty() + * the managed table. The implementation of {@code getProperty()} * will take care about delimiters. So list delimiters are fully supported - * by DatabaseConfiguration, but internally treated a bit + * by {@code DatabaseConfiguration}, but internally treated a bit * differently. * * @param key the key of the new property * @param value the value to be added */ + @Override public void addProperty(String key, Object value) { boolean parsingFlag = isDelimiterParsingDisabled(); @@ -355,9 +358,9 @@ public class DatabaseConfiguration exten /** * Checks if this configuration is empty. If this causes a database error, - * an error event will be generated of type EVENT_READ_PROPERTY - * with the causing exception. Both the event's propertyName - * and propertyValue will be undefined. + * an error event will be generated of type {@code EVENT_READ_PROPERTY} + * with the causing exception. Both the event's {@code propertyName} + * and {@code propertyValue} will be undefined. * * @return a flag whether this configuration is empty. */ @@ -366,7 +369,7 @@ public class DatabaseConfiguration exten boolean empty = true; // build the query - StringBuffer query = new StringBuffer("SELECT count(*) FROM " + table); + StringBuilder query = new StringBuilder("SELECT count(*) FROM " + table); if (nameColumn != null) { query.append(" WHERE " + nameColumn + "=?"); @@ -409,9 +412,9 @@ public class DatabaseConfiguration exten /** * Checks whether this configuration contains the specified key. If this * causes a database error, an error event will be generated of type - * EVENT_READ_PROPERTY with the causing exception. The - * event's propertyName will be set to the passed in key, the - * propertyValue will be undefined. + * {@code EVENT_READ_PROPERTY} with the causing exception. The + * event's {@code propertyName} will be set to the passed in key, the + * {@code propertyValue} will be undefined. * * @param key the key to be checked * @return a flag whether this key is defined @@ -421,7 +424,7 @@ public class DatabaseConfiguration exten boolean found = false; // build the query - StringBuffer query = new StringBuffer("SELECT * FROM " + table + " WHERE " + keyColumn + "=?"); + StringBuilder query = new StringBuilder("SELECT * FROM " + table + " WHERE " + keyColumn + "=?"); if (nameColumn != null) { query.append(" AND " + nameColumn + "=?"); @@ -462,16 +465,17 @@ public class DatabaseConfiguration exten /** * Removes the specified value from this configuration. If this causes a * database error, an error event will be generated of type - * EVENT_CLEAR_PROPERTY with the causing exception. The - * event's propertyName will be set to the passed in key, the - * propertyValue will be undefined. + * {@code EVENT_CLEAR_PROPERTY} with the causing exception. The + * event's {@code propertyName} will be set to the passed in key, the + * {@code propertyValue} will be undefined. * * @param key the key of the property to be removed */ + @Override protected void clearPropertyDirect(String key) { // build the query - StringBuffer query = new StringBuffer("DELETE FROM " + table + " WHERE " + keyColumn + "=?"); + StringBuilder query = new StringBuilder("DELETE FROM " + table + " WHERE " + keyColumn + "=?"); if (nameColumn != null) { query.append(" AND " + nameColumn + "=?"); @@ -509,15 +513,16 @@ public class DatabaseConfiguration exten /** * Removes all entries from this configuration. If this causes a database * error, an error event will be generated of type - * EVENT_CLEAR with the causing exception. Both the - * event's propertyName and the propertyValue + * {@code EVENT_CLEAR} with the causing exception. Both the + * event's {@code propertyName} and the {@code propertyValue} * will be undefined. */ + @Override public void clear() { fireEvent(EVENT_CLEAR, null, null, true); // build the query - StringBuffer query = new StringBuffer("DELETE FROM " + table); + StringBuilder query = new StringBuilder("DELETE FROM " + table); if (nameColumn != null) { query.append(" WHERE " + nameColumn + "=?"); @@ -556,18 +561,18 @@ public class DatabaseConfiguration exten * Returns an iterator with the names of all properties contained in this * configuration. If this causes a database * error, an error event will be generated of type - * EVENT_READ_PROPERTY with the causing exception. Both the - * event's propertyName and the propertyValue + * {@code EVENT_READ_PROPERTY} with the causing exception. Both the + * event's {@code propertyName} and the {@code propertyValue} * will be undefined. * @return an iterator with the contained keys (an empty iterator in case * of an error) */ - public Iterator getKeys() + public Iterator getKeys() { - Collection keys = new ArrayList(); + Collection keys = new ArrayList(); // build the query - StringBuffer query = new StringBuffer("SELECT DISTINCT " + keyColumn + " FROM " + table); + StringBuilder query = new StringBuilder("SELECT DISTINCT " + keyColumn + " FROM " + table); if (nameColumn != null) { query.append(" WHERE " + nameColumn + "=?"); @@ -608,7 +613,7 @@ public class DatabaseConfiguration exten } /** - * Returns the used DataSource object. + * Returns the used {@code DataSource} object. * * @return the data source * @since 1.4 @@ -619,23 +624,24 @@ public class DatabaseConfiguration exten } /** - * Returns a Connection object. This method is called when + * Returns a {@code Connection} object. This method is called when * ever the database is to be accessed. This implementation returns a - * connection from the current DataSource. + * connection from the current {@code DataSource}. * - * @return the Connection object to be used + * @return the {@code Connection} object to be used * @throws SQLException if an error occurs * @since 1.4 * @deprecated Use a custom data source to change the connection used by the * class. To be removed in Commons Configuration 2.0 */ + @Deprecated protected Connection getConnection() throws SQLException { return getDatasource().getConnection(); } /** - * Close a Connection and, Statement. + * Close a {@code Connection} and, {@code Statement}. * Avoid closing if null and hide any SQLExceptions that occur. * * @param conn The database connection to close