You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2013/07/13 21:23:04 UTC
svn commit: r1502841 - in /commons/proper/configuration/trunk/src:
main/java/org/apache/commons/configuration/DatabaseConfiguration.java
test/java/org/apache/commons/configuration/TestDatabaseConfiguration.java
Author: oheger
Date: Sat Jul 13 19:23:04 2013
New Revision: 1502841
URL: http://svn.apache.org/r1502841
Log:
Integrated ListDelimiterHandler with DatabaseConfiguration.
Modified:
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DatabaseConfiguration.java
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestDatabaseConfiguration.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=1502841&r1=1502840&r2=1502841&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 Sat Jul 13 19:23:04 2013
@@ -318,31 +318,26 @@ public class DatabaseConfiguration exten
@Override
protected Object performOperation() throws SQLException
{
- ResultSet rs = openResultSet(String.format(
- SQL_GET_PROPERTY, table, keyColumn), true, key);
+ ResultSet rs =
+ openResultSet(String.format(SQL_GET_PROPERTY,
+ table, keyColumn), true, key);
List<Object> results = new ArrayList<Object>();
while (rs.next())
{
Object value = extractPropertyValue(rs);
- if (isDelimiterParsingDisabled())
- {
- results.add(value);
- }
- else
+ // Split value if it contains the list delimiter
+ Iterator<?> it = getListDelimiterHandler().parse(value);
+ while (it.hasNext())
{
- // Split value if it contains the list delimiter
- Iterator<?> it = PropertyConverter.toIterator(value, getListDelimiter());
- while (it.hasNext())
- {
- results.add(it.next());
- }
+ results.add(it.next());
}
}
if (!results.isEmpty())
{
- return (results.size() > 1) ? results : results.get(0);
+ return (results.size() > 1) ? results : results
+ .get(0);
}
else
{
@@ -401,11 +396,11 @@ 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
+ * Adds a property to this configuration. This implementation
+ * temporarily disables list delimiter parsing, so that even if the value
+ * contains the list delimiter, only a single record is written into
* the managed table. The implementation of {@code getProperty()}
- * will take care about delimiters. So list delimiters are fully supported
+ * takes care about delimiters. So list delimiters are fully supported
* by {@code DatabaseConfiguration}, but internally treated a bit
* differently.
*
@@ -415,19 +410,16 @@ public class DatabaseConfiguration exten
@Override
protected void addPropertyInternal(String key, Object value)
{
- boolean parsingFlag = isDelimiterParsingDisabled();
+ ListDelimiterHandler oldHandler = getListDelimiterHandler();
try
{
- if (value instanceof String)
- {
- // temporarily disable delimiter parsing
- setDelimiterParsingDisabled(true);
- }
+ // temporarily disable delimiter parsing
+ setListDelimiterHandler(DisabledListDelimiterHandler.INSTANCE);
super.addPropertyInternal(key, value);
}
finally
{
- setDelimiterParsingDisabled(parsingFlag);
+ setListDelimiterHandler(oldHandler);
}
}
Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestDatabaseConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestDatabaseConfiguration.java?rev=1502841&r1=1502840&r2=1502841&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestDatabaseConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestDatabaseConfiguration.java Sat Jul 13 19:23:04 2013
@@ -452,8 +452,7 @@ public class TestDatabaseConfiguration
public void testGetListWithDelimiter() throws ConfigurationException
{
DatabaseConfiguration config = setUpConfig();
- config.setListDelimiter(';');
- config.setDelimiterParsingDisabled(false);
+ config.setListDelimiterHandler(new DefaultListDelimiterHandler(';'));
List<Object> values = config.getList("keyMulti");
assertEquals("Wrong number of list elements", 3, values.size());
assertEquals("Wrong list element 0", "a", values.get(0));
@@ -481,8 +480,7 @@ public class TestDatabaseConfiguration
public void testAddWithDelimiter() throws ConfigurationException
{
DatabaseConfiguration config = setUpConfig();
- config.setListDelimiter(';');
- config.setDelimiterParsingDisabled(false);
+ config.setListDelimiterHandler(new DefaultListDelimiterHandler(';'));
config.addProperty("keyList", "1;2;3");
String[] values = config.getStringArray("keyList");
assertEquals("Wrong number of property values", 3, values.length);
@@ -496,8 +494,7 @@ public class TestDatabaseConfiguration
public void testSetPropertyWithDelimiter() throws ConfigurationException
{
DatabaseConfiguration config = helper.setUpMultiConfig();
- config.setListDelimiter(';');
- config.setDelimiterParsingDisabled(false);
+ config.setListDelimiterHandler(new DefaultListDelimiterHandler(';'));
config.setProperty("keyList", "1;2;3");
String[] values = config.getStringArray("keyList");
assertEquals("Wrong number of property values", 3, values.length);