From f27898f28082a42624d7dd5c7768523ef6b16f61 Mon Sep 17 00:00:00 2001 From: "A. Abram White" Date: Tue, 10 Oct 2006 22:39:15 +0000 Subject: [PATCH] Take advantage StringUtils where appropriate. git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@462617 13f79535-47bb-0310-9956-ffa450edef68 --- .../jdbc/ant/ReverseMappingToolTask.java | 7 +++--- .../jdbc/conf/JDBCConfigurationImpl.java | 5 ++-- .../jdbc/conf/MappingFactoryValue.java | 4 ++-- .../jdbc/kernel/JDBCBrokerFactory.java | 3 ++- .../openjpa/jdbc/kernel/SQLStoreQuery.java | 7 +++--- .../meta/PropertiesReverseCustomizer.java | 8 ++----- .../openjpa/jdbc/meta/QueryResultMapping.java | 3 ++- .../openjpa/jdbc/meta/ReverseMappingTool.java | 18 +++++--------- .../ClassNameDiscriminatorStrategy.java | 3 ++- .../apache/openjpa/jdbc/schema/Column.java | 5 ++-- .../jdbc/schema/DataSourceFactory.java | 3 ++- .../apache/openjpa/jdbc/schema/NameSet.java | 3 ++- .../apache/openjpa/jdbc/schema/Schema.java | 6 ++--- .../openjpa/jdbc/schema/SchemaGenerator.java | 24 ++++++------------- .../openjpa/jdbc/schema/SchemaTool.java | 3 ++- .../jdbc/schema/XMLSchemaSerializer.java | 5 ++-- .../apache/openjpa/jdbc/sql/DBDictionary.java | 19 +++++++-------- .../openjpa/jdbc/sql/DBDictionaryFactory.java | 3 ++- .../openjpa/jdbc/sql/HSQLDictionary.java | 3 ++- .../openjpa/jdbc/sql/MySQLDictionary.java | 3 ++- .../apache/openjpa/jdbc/sql/SelectImpl.java | 5 ++-- .../openjpa/jdbc/sql/SybaseDictionary.java | 3 ++- .../conf/OpenJPAConfigurationImpl.java | 5 ++-- .../apache/openjpa/conf/OpenJPAVersion.java | 4 +++- .../conf/RemoteCommitProviderValue.java | 12 ++++------ .../openjpa/kernel/MethodStoreQuery.java | 3 ++- .../org/apache/openjpa/kernel/QueryImpl.java | 9 +++---- .../apache/openjpa/kernel/ResultPacker.java | 3 ++- .../meta/AbstractCFMetaDataFactory.java | 9 +++---- .../openjpa/meta/AbstractMetaDataFactory.java | 3 ++- .../apache/openjpa/meta/FieldMetaData.java | 9 ++----- .../apache/openjpa/meta/QueryMetaData.java | 3 ++- .../openjpa/lib/conf/Configurations.java | 19 +++++++-------- .../apache/openjpa/lib/conf/DoubleValue.java | 4 +++- .../org/apache/openjpa/lib/conf/IntValue.java | 4 +++- .../openjpa/lib/conf/PluginListValue.java | 6 +++-- .../openjpa/lib/conf/ProductDerivations.java | 3 ++- .../openjpa/lib/log/LogOutputStream.java | 7 ++++-- .../openjpa/lib/meta/CFMetaDataParser.java | 13 +++++----- .../openjpa/lib/meta/ClassArgParser.java | 6 ++--- .../org/apache/openjpa/lib/util/Files.java | 3 ++- .../org/apache/openjpa/lib/util/Options.java | 4 ++-- .../persistence/EntityManagerImpl.java | 3 ++- .../openjpa/xmlstore/XMLFileHandler.java | 2 +- 44 files changed, 136 insertions(+), 141 deletions(-) diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/ant/ReverseMappingToolTask.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/ant/ReverseMappingToolTask.java index 144ed830e..44a264888 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/ant/ReverseMappingToolTask.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/ant/ReverseMappingToolTask.java @@ -19,7 +19,7 @@ import java.io.File; import java.io.FileInputStream; import java.util.Properties; -import org.apache.tools.ant.types.EnumeratedAttribute; +import org.apache.commons.lang.StringUtils; import org.apache.openjpa.jdbc.conf.JDBCConfiguration; import org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl; import org.apache.openjpa.jdbc.meta.PropertiesReverseCustomizer; @@ -30,6 +30,7 @@ import org.apache.openjpa.lib.conf.ConfigurationImpl; import org.apache.openjpa.lib.conf.Configurations; import org.apache.openjpa.lib.util.CodeFormat; import org.apache.openjpa.lib.util.Files; +import org.apache.tools.ant.types.EnumeratedAttribute; /** * Executes the {@link ReverseMappingTool} on the specified XML files. @@ -222,9 +223,9 @@ public class ReverseMappingToolTask protected void executeOn(String[] files) throws Exception { ClassLoader loader = getClassLoader(); - if (dirName != null && dirName.length() > 0) + if (!StringUtils.isEmpty(dirName)) flags.directory = Files.getFile(dirName, loader); - if (typeMap != null && typeMap.length() > 0) + if (!StringUtils.isEmpty(typeMap)) flags.typeMap = Configurations.parseProperties(typeMap); // load customizer properties diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfigurationImpl.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfigurationImpl.java index 8b9140d57..43c834e46 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfigurationImpl.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfigurationImpl.java @@ -19,6 +19,7 @@ import java.sql.Connection; import java.sql.ResultSet; import javax.sql.DataSource; +import org.apache.commons.lang.StringUtils; import org.apache.openjpa.conf.OpenJPAConfigurationImpl; import org.apache.openjpa.jdbc.kernel.EagerFetchModes; import org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory; @@ -535,7 +536,7 @@ public class JDBCConfigurationImpl if (dbdictionary == null) { String clsName = dbdictionaryPlugin.getClassName(); String props = dbdictionaryPlugin.getProperties(); - if (clsName != null && clsName.length() > 0) { + if (!StringUtils.isEmpty(clsName)) { dbdictionary = DBDictionaryFactory.newDBDictionary (this, clsName, props); } else { @@ -754,7 +755,7 @@ public class JDBCConfigurationImpl // the driver name is always required, so if not specified, // then no connection factory 2 String driver = getConnection2DriverName(); - if (driver != null && driver.length() > 0) + if (!StringUtils.isEmpty(driver)) ds = DataSourceFactory.newDataSource(this, true); } if (ds != null) { diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/MappingFactoryValue.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/MappingFactoryValue.java index 0033b1e8a..1055fcfd0 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/MappingFactoryValue.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/MappingFactoryValue.java @@ -88,7 +88,7 @@ public class MappingFactoryValue String metaProps = metaPlugin.getProperties(); // if no mapping factory set, check for default for this factory - if (clsName == null || clsName.length() == 0) { + if (StringUtils.isEmpty(clsName)) { String def; if (!StringUtils.isEmpty(mapping)) { def = unalias(metaPlugin.alias(metaClsName), @@ -96,7 +96,7 @@ public class MappingFactoryValue if (def != null) clsName = unalias(def); } - if (clsName == null) { + if (StringUtils.isEmpty(clsName)) { def = unalias(metaPlugin.alias(metaClsName), _metaFactoryDefaults, true); if (def != null) diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCBrokerFactory.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCBrokerFactory.java index a041884b6..0abb8a9c0 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCBrokerFactory.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCBrokerFactory.java @@ -20,6 +20,7 @@ import java.util.Collection; import java.util.Iterator; import java.util.Properties; +import org.apache.commons.lang.StringUtils; import org.apache.openjpa.jdbc.conf.JDBCConfiguration; import org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl; import org.apache.openjpa.jdbc.meta.MappingTool; @@ -138,7 +139,7 @@ public class JDBCBrokerFactory private void synchronizeMappings(ClassLoader loader) { JDBCConfiguration conf = (JDBCConfiguration) getConfiguration(); String action = conf.getSynchronizeMappings(); - if (action == null || action.length() == 0) + if (StringUtils.isEmpty(action)) return; Collection classes = conf.getMetaDataRepositoryInstance(). diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/SQLStoreQuery.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/SQLStoreQuery.java index 241b1accd..49d0f1ffc 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/SQLStoreQuery.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/SQLStoreQuery.java @@ -27,6 +27,7 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; +import org.apache.commons.lang.StringUtils; import org.apache.openjpa.jdbc.meta.ClassMapping; import org.apache.openjpa.jdbc.meta.MappingRepository; import org.apache.openjpa.jdbc.meta.QueryResultMapping; @@ -174,10 +175,8 @@ public class SQLStoreQuery } _meta = candidate; - String sql = ctx.getQueryString(); - if (sql != null) - sql = sql.trim(); - if (sql == null || sql.length() == 0) + String sql = StringUtils.trimToNull(ctx.getQueryString()); + if (sql == null) throw new UserException(_loc.get("no-sql")); _select = sql.length() > 6 && sql.substring(0, 6).equalsIgnoreCase("select"); diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/PropertiesReverseCustomizer.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/PropertiesReverseCustomizer.java index b8df85696..eb4588960 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/PropertiesReverseCustomizer.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/PropertiesReverseCustomizer.java @@ -19,6 +19,7 @@ import java.util.Properties; import java.util.Set; import java.util.TreeSet; +import org.apache.commons.lang.StringUtils; import org.apache.openjpa.jdbc.schema.Column; import org.apache.openjpa.jdbc.schema.ForeignKey; import org.apache.openjpa.jdbc.schema.Table; @@ -219,12 +220,7 @@ public class PropertiesReverseCustomizer * Return the property value for the given key, or null if none. */ protected String getProperty(String key) { - String val = _props.getProperty(key); - if (val != null) { - val = val.trim(); - if (val.length() == 0) - val = null; - } + String val = StringUtils.trimToNull(_props.getProperty(key)); _unaccessed.remove(key); return val; } diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/QueryResultMapping.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/QueryResultMapping.java index e0bed6671..bd0c4b1a4 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/QueryResultMapping.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/QueryResultMapping.java @@ -25,6 +25,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import org.apache.commons.lang.StringUtils; import org.apache.openjpa.jdbc.schema.Column; import org.apache.openjpa.jdbc.sql.Joins; import org.apache.openjpa.lib.meta.SourceTracker; @@ -284,7 +285,7 @@ public class QueryResultMapping * Map the given path to the given result id. */ public void addMapping(String path, Object id) { - if (path == null || path.length() == 0) + if (StringUtils.isEmpty(path)) throw new MetaDataException(_loc.get("null-path", QueryResultMapping.this, _candidate)); diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ReverseMappingTool.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ReverseMappingTool.java index b36db91ed..2581d1be6 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ReverseMappingTool.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ReverseMappingTool.java @@ -236,9 +236,7 @@ public class ReverseMappingTool * indicate no package. */ public void setPackageName(String packageName) { - if (packageName != null && packageName.length() == 0) - packageName = null; - _package = packageName; + _package = StringUtils.trimToNull(packageName); } /** @@ -1470,7 +1468,7 @@ public class ReverseMappingTool * package-private for testing. */ static String replaceInvalidCharacters(String str) { - if (str == null || str.length() == 0) + if (StringUtils.isEmpty(str)) return str; StringBuffer buf = new StringBuffer(str); @@ -1542,14 +1540,10 @@ public class ReverseMappingTool if (propNames[nameIdx] == null) continue; - typeSpec = _typeMap.getProperty(propNames[nameIdx]); - if (typeSpec != null) { - typeSpec = typeSpec.trim(); - if (typeSpec.length() == 0) - typeSpec = null; - else - typeName = propNames[nameIdx]; - } + typeSpec = StringUtils.trimToNull(_typeMap.getProperty + (propNames[nameIdx])); + if (typeSpec != null) + typeName = propNames[nameIdx]; } if (typeSpec != null) _log.info(_loc.get("reverse-type", typeName, typeSpec)); diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ClassNameDiscriminatorStrategy.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ClassNameDiscriminatorStrategy.java index fa13eb7ac..f21bb246c 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ClassNameDiscriminatorStrategy.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ClassNameDiscriminatorStrategy.java @@ -20,6 +20,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import org.apache.commons.lang.StringUtils; import org.apache.openjpa.jdbc.kernel.JDBCStore; import org.apache.openjpa.jdbc.meta.ClassMapping; import org.apache.openjpa.jdbc.schema.Column; @@ -88,7 +89,7 @@ public class ClassNameDiscriminatorStrategy String className; while (rs.next()) { className = dict.getString(rs, 1); - if (className == null || className.length() == 0) + if (StringUtils.isEmpty(className)) throw new ClassNotFoundException(_loc.get("no-class-name", disc.getClassMapping(), col).getMessage()); Class.forName(className, true, loader); diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Column.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Column.java index 14edac8b3..98e52078d 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Column.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Column.java @@ -23,6 +23,7 @@ import java.sql.Time; import java.sql.Timestamp; import java.sql.Types; +import org.apache.commons.lang.StringUtils; import org.apache.openjpa.jdbc.meta.JavaSQLTypes; import org.apache.openjpa.meta.JavaTypes; import serp.util.Numbers; @@ -461,9 +462,7 @@ public class Column * The name of the column this column joins to, if any. Used for mapping. */ public void setTarget(String target) { - if (target != null && target.length() == 0) - target = null; - _target = target; + _target = StringUtils.trimToNull(target); } /** diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/DataSourceFactory.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/DataSourceFactory.java index 1da585b1f..731399b26 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/DataSourceFactory.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/DataSourceFactory.java @@ -24,6 +24,7 @@ import java.util.Iterator; import java.util.List; import javax.sql.DataSource; +import org.apache.commons.lang.StringUtils; import org.apache.openjpa.jdbc.conf.JDBCConfiguration; import org.apache.openjpa.jdbc.sql.DBDictionary; import org.apache.openjpa.lib.conf.Configurations; @@ -62,7 +63,7 @@ public class DataSourceFactory { boolean factory2) { String driver = (factory2) ? conf.getConnection2DriverName() : conf.getConnectionDriverName(); - if (driver == null || driver.length() == 0) + if (StringUtils.isEmpty(driver)) throw new UserException(_loc.get("no-driver", driver)). setFatal(true); diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/NameSet.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/NameSet.java index a2bb7e3e2..4c76af11e 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/NameSet.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/NameSet.java @@ -18,6 +18,7 @@ package org.apache.openjpa.jdbc.schema; import java.util.HashSet; import java.util.Set; +import org.apache.commons.lang.StringUtils; import org.apache.openjpa.lib.util.Localizer; /** @@ -49,7 +50,7 @@ public class NameSet { * @param validate if true, null or empty names will not be accepted */ protected void addName(String name, boolean validate) { - if (name == null || name.length() == 0) { + if (StringUtils.isEmpty(name)) { if (validate) throw new IllegalArgumentException(_loc.get("bad-name", name) .getMessage()); diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Schema.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Schema.java index e05ccb822..ec519af1b 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Schema.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Schema.java @@ -18,6 +18,8 @@ package org.apache.openjpa.jdbc.schema; import java.util.Map; import java.util.TreeMap; +import org.apache.commons.lang.StringUtils; + /** * Represents a database schema. * @@ -87,9 +89,7 @@ public class Schema public void setName(String name) { if (getSchemaGroup() != null) throw new IllegalStateException(); - if (name != null && name.length() == 0) - name = null; - _name = name; + _name = StringUtils.trimToNull(name); } /** diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaGenerator.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaGenerator.java index 5fe4abb1e..45731e335 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaGenerator.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaGenerator.java @@ -486,9 +486,7 @@ public class SchemaGenerator { String tableSchema; for (int i = 0; cols != null && i < cols.length; i++) { tableName = cols[i].getTableName(); - tableSchema = cols[i].getSchemaName(); - if (tableSchema != null && tableSchema.length() == 0) - tableSchema = null; + tableSchema = StringUtils.trimToNull(cols[i].getSchemaName()); // ignore special tables if (!_openjpaTables && @@ -600,9 +598,7 @@ public class SchemaGenerator { String name; String colName; for (int i = 0; pks != null && i < pks.length; i++) { - schemaName = pks[i].getSchemaName(); - if (schemaName != null && schemaName.length() == 0) - schemaName = null; + schemaName = StringUtils.trimToNull(pks[i].getSchemaName()); schema = group.getSchema(schemaName); if (schema == null) continue; @@ -659,9 +655,7 @@ public class SchemaGenerator { String colName; String pkName; for (int i = 0; idxs != null && i < idxs.length; i++) { - schemaName = idxs[i].getSchemaName(); - if (schemaName != null && schemaName.length() == 0) - schemaName = null; + schemaName = StringUtils.trimToNull(idxs[i].getSchemaName()); schema = group.getSchema(schemaName); if (schema == null) continue; @@ -676,7 +670,7 @@ public class SchemaGenerator { // statistics don't have names; skip them name = idxs[i].getName(); - if (name == null || name.length() == 0 + if (StringUtils.isEmpty(name) || (pkName != null && name.equalsIgnoreCase(pkName)) || _dict.isSystemIndex(name, table)) continue; @@ -741,9 +735,7 @@ public class SchemaGenerator { boolean seqWas0 = false; // some drivers incorrectly start at 0 Collection invalids = null; for (int i = 0; fks != null && i < fks.length; i++) { - schemaName = fks[i].getSchemaName(); - if (schemaName != null && schemaName.length() == 0) - schemaName = null; + schemaName = StringUtils.trimToNull(fks[i].getSchemaName()); schema = group.getSchema(schemaName); if (schema == null) continue; @@ -767,7 +759,7 @@ public class SchemaGenerator { _log.trace(_loc.get("gen-fk", new Object[]{ name, table, fkColName, pkTableName, pkColName, seq + "" })); - if (pkSchemaName != null && pkSchemaName.length() > 0) + if (!StringUtils.isEmpty(pkSchemaName)) pkTableName = pkSchemaName + "." + pkTableName; pkTable = group.findTable(pkTableName); if (pkTable == null) @@ -832,9 +824,7 @@ public class SchemaGenerator { String sequenceSchema; for (int i = 0; seqs != null && i < seqs.length; i++) { sequenceName = seqs[i].getName(); - sequenceSchema = seqs[i].getSchemaName(); - if (sequenceSchema != null && sequenceSchema.length() == 0) - sequenceSchema = null; + sequenceSchema = StringUtils.trimToNull(seqs[i].getSchemaName()); // ignore special tables if (!_openjpaTables && diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java index 034695967..cb1bece76 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java @@ -31,6 +31,7 @@ import java.util.LinkedList; import java.util.Set; import javax.sql.DataSource; +import org.apache.commons.lang.StringUtils; import org.apache.openjpa.conf.OpenJPAConfiguration; import org.apache.openjpa.jdbc.conf.JDBCConfiguration; import org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl; @@ -1424,7 +1425,7 @@ public class SchemaTool { gen.setOpenJPATables(flags.openjpaTables); String schemas = conf.getSchemas(); - if (schemas == null || schemas.length() == 0) + if (StringUtils.isEmpty(schemas)) schemas = "all"; log.info(_loc.get("sch-reflect", schemas)); gen.generateSchemas(); diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/XMLSchemaSerializer.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/XMLSchemaSerializer.java index 6ee5a9c53..f8a761bdb 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/XMLSchemaSerializer.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/XMLSchemaSerializer.java @@ -24,10 +24,11 @@ import java.util.List; import java.util.Map; import java.util.TreeSet; -import org.xml.sax.SAXException; +import org.apache.commons.lang.StringUtils; import org.apache.openjpa.jdbc.conf.JDBCConfiguration; import org.apache.openjpa.lib.meta.XMLMetaDataSerializer; import org.apache.openjpa.lib.util.Localizer; +import org.xml.sax.SAXException; /** * Serializes {@link Schema}s to XML matching the document @@ -261,7 +262,7 @@ public class XMLSchemaSerializer throws SAXException { addAttribute("name", col.getName()); addAttribute("type", Schemas.getJDBCName(col.getType())); - if (col.getTypeName() != null && col.getTypeName().length() > 0 + if (!StringUtils.isEmpty(col.getTypeName()) && !col.getTypeName().equalsIgnoreCase (Schemas.getJDBCName(col.getType()))) addAttribute("type-name", col.getTypeName()); diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java index 16a880d00..adb36a003 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java @@ -56,6 +56,7 @@ import java.util.Map; import java.util.Set; import javax.sql.DataSource; +import org.apache.commons.lang.StringUtils; import org.apache.openjpa.jdbc.conf.JDBCConfiguration; import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration; import org.apache.openjpa.jdbc.kernel.JDBCStore; @@ -535,9 +536,7 @@ public class DBDictionary return (char) getInt(rs, column); String str = getString(rs, column); - if (str == null || str.length() == 0) - return 0; - return str.charAt(0); + return (StringUtils.isEmpty(str)) ? 0 : str.charAt(0); } /** @@ -642,7 +641,7 @@ public class DBDictionary public Locale getLocale(ResultSet rs, int column) throws SQLException { String str = getString(rs, column); - if (str == null || str.length() == 0) + if (StringUtils.isEmpty(str)) return null; String[] params = Strings.split(str, "_", 3); @@ -1488,7 +1487,7 @@ public class DBDictionary * from {@link Types}. */ public String getTypeName(Column col) { - if (col.getTypeName() != null && col.getTypeName().length() > 0) + if (!StringUtils.isEmpty(col.getTypeName())) return appendSize(col, col.getTypeName()); if (col.isAutoAssigned() && autoAssignTypeName != null) @@ -1623,7 +1622,7 @@ public class DBDictionary joinSyntax = SYNTAX_TRADITIONAL; else if ("database".equals(syntax)) joinSyntax = SYNTAX_DATABASE; - else if (syntax != null && syntax.length() > 0) + else if (!StringUtils.isEmpty(syntax)) throw new IllegalArgumentException(syntax); } @@ -3252,8 +3251,7 @@ public class DBDictionary == DatabaseMetaData.columnNoNulls); String def = colMeta.getString("COLUMN_DEF"); - if (def != null && def.length() > 0 - && !"null".equalsIgnoreCase(def)) + if (!StringUtils.isEmpty(def) && !"null".equalsIgnoreCase(def)) c.setDefaultString(def); return c; } @@ -3661,8 +3659,7 @@ public class DBDictionary // if user has unset sequence sql, null it out so we know sequences // aren't supported - if (nextSequenceQuery != null && nextSequenceQuery.length() == 0) - nextSequenceQuery = null; + nextSequenceQuery = StringUtils.trimToNull(nextSequenceQuery); } ////////////////////////////////////// @@ -3679,7 +3676,7 @@ public class DBDictionary throws SQLException { if (!connected) connectedConfiguration(conn); - if (initializationSQL != null && initializationSQL.length() > 0) { + if (!StringUtils.isEmpty(initializationSQL)) { PreparedStatement stmnt = null; try { stmnt = conn.prepareStatement(initializationSQL); diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionaryFactory.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionaryFactory.java index 99e00ac8d..fe8fba121 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionaryFactory.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionaryFactory.java @@ -20,6 +20,7 @@ import java.sql.DatabaseMetaData; import java.sql.SQLException; import javax.sql.DataSource; +import org.apache.commons.lang.StringUtils; import org.apache.openjpa.jdbc.conf.JDBCConfiguration; import org.apache.openjpa.lib.conf.Configurations; import org.apache.openjpa.lib.log.Log; @@ -158,7 +159,7 @@ public class DBDictionaryFactory { * Guess the dictionary class name to use based on the product string. */ private static String dictionaryClassForString(String prod) { - if (prod == null || prod.length() == 0) + if (StringUtils.isEmpty(prod)) return null; prod = prod.toLowerCase(); diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/HSQLDictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/HSQLDictionary.java index e5589e72a..8bca34a37 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/HSQLDictionary.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/HSQLDictionary.java @@ -23,6 +23,7 @@ import java.sql.SQLException; import java.sql.Types; import java.util.Arrays; +import org.apache.commons.lang.StringUtils; import org.hsqldb.Trace; import org.apache.openjpa.jdbc.kernel.exps.FilterValue; import org.apache.openjpa.jdbc.schema.Column; @@ -147,7 +148,7 @@ public class HSQLDictionary String pkStr; if (pk != null) { pkStr = getPrimaryKeyConstraintSQL(pk); - if (pkStr != null && pkStr.length() > 0) + if (!StringUtils.isEmpty(pkStr)) buf.append(", ").append(pkStr); } diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java index aea4fba2a..82d799401 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MySQLDictionary.java @@ -20,6 +20,7 @@ import java.sql.SQLException; import java.sql.Types; import java.util.Arrays; +import org.apache.commons.lang.StringUtils; import org.apache.openjpa.jdbc.kernel.JDBCStore; import org.apache.openjpa.jdbc.schema.Column; import org.apache.openjpa.jdbc.schema.ForeignKey; @@ -95,7 +96,7 @@ public class MySQLDictionary public String[] getCreateTableSQL(Table table) { String[] sql = super.getCreateTableSQL(table); - if (tableType != null && tableType.length() > 0) + if (!StringUtils.isEmpty(tableType)) sql[0] = sql[0] + " TYPE = " + tableType; return sql; } diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java index 749ad74fc..1c58426ed 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SelectImpl.java @@ -36,6 +36,7 @@ import java.util.Stack; import java.util.TreeMap; import org.apache.commons.collections.iterators.EmptyIterator; +import org.apache.commons.lang.StringUtils; import org.apache.openjpa.jdbc.conf.JDBCConfiguration; import org.apache.openjpa.jdbc.kernel.EagerFetchModes; import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration; @@ -1264,7 +1265,7 @@ public class SelectImpl */ private void where(String sql, PathJoins pj) { // no need to use joins... - if (sql == null || sql.length() == 0) + if (StringUtils.isEmpty(sql)) return; if (_where == null) @@ -1310,7 +1311,7 @@ public class SelectImpl */ private void having(String sql, PathJoins pj) { // no need to use joins... - if (sql == null || sql.length() == 0) + if (StringUtils.isEmpty(sql)) return; if (_having == null) diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SybaseDictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SybaseDictionary.java index 673cf0555..09ae9fcfa 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SybaseDictionary.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SybaseDictionary.java @@ -23,6 +23,7 @@ import java.sql.SQLException; import java.sql.Types; import java.util.Arrays; +import org.apache.commons.lang.StringUtils; import org.apache.openjpa.jdbc.schema.Column; import org.apache.openjpa.jdbc.schema.ForeignKey; import org.apache.openjpa.jdbc.schema.PrimaryKey; @@ -242,7 +243,7 @@ public class SybaseDictionary // warn about jdbc compliant flag String url = conf.getConnectionURL(); - if (url != null && url.length() > 0 + if (!StringUtils.isEmpty(url) && url.toLowerCase().indexOf("jdbc:sybase:tds") != -1 && url.toLowerCase().indexOf("be_as_jdbc_compliant_as_possible=") == -1) { diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java b/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java index 2db8ce88e..281df7408 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java @@ -22,6 +22,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import org.apache.commons.lang.StringUtils; import org.apache.openjpa.datacache.ConcurrentDataCache; import org.apache.openjpa.datacache.ConcurrentQueryCache; import org.apache.openjpa.datacache.DataCacheManager; @@ -937,9 +938,9 @@ public class OpenJPAConfigurationImpl * Lookup the connection factory at the given name. */ private Object lookupConnectionFactory(String name) { - if (name == null || name.trim().length() == 0) + name = StringUtils.trimToNull(name); + if (name == null) return null; - return Configurations.lookup(name); } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAVersion.java b/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAVersion.java index b5b9a2131..f58c280fc 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAVersion.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAVersion.java @@ -21,6 +21,8 @@ import java.util.Date; import java.util.Properties; import java.util.StringTokenizer; +import org.apache.commons.lang.StringUtils; + /** * This class contains version information for OpenJPA. It uses * Ant's filter tokens to convert the template into a java @@ -42,7 +44,7 @@ public class OpenJPAVersion { static { Package pack = OpenJPAVersion.class.getPackage(); String vers = pack == null ? null : pack.getImplementationVersion(); - if (vers == null || vers.length() == 0) + if (StringUtils.isEmpty(vers)) vers = "0.0.0"; VERSION_NUMBER = vers; diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/conf/RemoteCommitProviderValue.java b/openjpa-kernel/src/main/java/org/apache/openjpa/conf/RemoteCommitProviderValue.java index 4f6ffdfff..95bf5733b 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/conf/RemoteCommitProviderValue.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/conf/RemoteCommitProviderValue.java @@ -15,6 +15,7 @@ */ package org.apache.openjpa.conf; +import org.apache.commons.lang.StringUtils; import org.apache.openjpa.event.RemoteCommitEventManager; import org.apache.openjpa.event.RemoteCommitProvider; import org.apache.openjpa.lib.conf.Configuration; @@ -128,12 +129,9 @@ public class RemoteCommitProviderValue return; _opts = Configurations.parseProperties(getProperties()); - String transmit = _opts.removeProperty("transmitPersistedObjectIds", - "TransmitPersistedObjectIds", null); - if (transmit != null) { - transmit = transmit.trim(); - if (transmit.length() > 0) - _transmitPersIds = Boolean.valueOf (transmit); - } + String transmit = StringUtils.trimToNull(_opts.removeProperty + ("transmitPersistedObjectIds", "TransmitPersistedObjectIds", null)); + if (transmit != null) + _transmitPersIds = Boolean.valueOf (transmit); } } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/MethodStoreQuery.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/MethodStoreQuery.java index efff61628..794314bce 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/MethodStoreQuery.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/MethodStoreQuery.java @@ -27,6 +27,7 @@ import java.util.List; import java.util.Map; import org.apache.commons.collections.map.LinkedMap; +import org.apache.commons.lang.StringUtils; import org.apache.openjpa.lib.rop.ListResultObjectProvider; import org.apache.openjpa.lib.rop.RangeResultObjectProvider; import org.apache.openjpa.lib.rop.ResultObjectProvider; @@ -217,7 +218,7 @@ public class MethodStoreQuery return; String methName = q.getContext().getQueryString(); - if (methName == null || methName.length() == 0) + if (StringUtils.isEmpty(methName)) throw new UserException(_loc.get("no-method")); int dotIdx = methName.lastIndexOf('.'); diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryImpl.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryImpl.java index 78a8d8c83..644976fb2 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryImpl.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryImpl.java @@ -26,6 +26,7 @@ import java.util.ListIterator; import java.util.Map; import org.apache.commons.collections.map.LinkedMap; +import org.apache.commons.lang.StringUtils; import org.apache.openjpa.conf.OpenJPAConfiguration; import org.apache.openjpa.enhance.PersistenceCapable; import org.apache.openjpa.kernel.exps.AggregateListener; @@ -540,11 +541,7 @@ public class QueryImpl try { assertOpen(); assertNotReadOnly(); - if (params != null) - params = params.trim(); - if (params != null && params.length() == 0) - params = null; - _params = params; + _params = StringUtils.trimToNull(params); invalidateCompilation(); } finally { unlock(); @@ -1110,7 +1107,7 @@ public class QueryImpl */ private void logExecution(int op, Map params) { String s = _query; - if (s == null || s.length() == 0) + if (StringUtils.isEmpty(s)) s = toString(); String msg = "executing-query"; diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ResultPacker.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ResultPacker.java index 5ffb30f04..ed9bcd22b 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ResultPacker.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ResultPacker.java @@ -30,6 +30,7 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; +import org.apache.commons.lang.StringUtils; import org.apache.openjpa.lib.util.Localizer; import org.apache.openjpa.util.OpenJPAException; import org.apache.openjpa.util.UserException; @@ -257,7 +258,7 @@ public class ResultPacker { */ private static Member findSet(String alias, Class type, Field[] fields, Method[] methods) { - if (alias == null || alias.length() == 0) + if (StringUtils.isEmpty(alias)) return null; if (type == Object.class) type = null; diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractCFMetaDataFactory.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractCFMetaDataFactory.java index fc47e3fed..de572f5b7 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractCFMetaDataFactory.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractCFMetaDataFactory.java @@ -31,6 +31,7 @@ import java.util.Set; import java.util.zip.ZipFile; import java.util.zip.ZipInputStream; +import org.apache.commons.lang.StringUtils; import org.apache.openjpa.lib.meta.ClassArgParser; import org.apache.openjpa.lib.meta.ClasspathMetaDataIterator; import org.apache.openjpa.lib.meta.FileMetaDataIterator; @@ -80,7 +81,7 @@ public abstract class AbstractCFMetaDataFactory * directories supplied by user via auto-configuration. */ public void setFiles(String files) { - if (files == null || files.length() == 0) + if (StringUtils.isEmpty(files)) this.files = null; else { String[] strs = Strings.split(files, ";", 0); @@ -107,7 +108,7 @@ public abstract class AbstractCFMetaDataFactory * supplied by user via auto-configuration. */ public void setURLs(String urls) { - if (urls == null || urls.length() == 0) + if (StringUtils.isEmpty(urls)) this.urls = null; else { String[] strs = Strings.split(urls, ";", 0); @@ -134,7 +135,7 @@ public abstract class AbstractCFMetaDataFactory */ public void setResources(String rsrcs) { // keep list mutable so subclasses can add implicit locations - this.rsrcs = (rsrcs == null || rsrcs.length() == 0) ? null + this.rsrcs = (StringUtils.isEmpty(rsrcs)) ? null : new ArrayList(Arrays.asList(Strings.split(rsrcs, ";", 0))); } @@ -152,7 +153,7 @@ public abstract class AbstractCFMetaDataFactory */ public void setClasspathScan(String cpath) { // keep list mutable so subclasses can add implicit locations - this.cpath = (cpath == null || cpath.length() == 0) ? null + this.cpath = (StringUtils.isEmpty(cpath)) ? null : new ArrayList(Arrays.asList(Strings.split(cpath, ";", 0))); } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractMetaDataFactory.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractMetaDataFactory.java index 687462ddc..548d5474b 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractMetaDataFactory.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractMetaDataFactory.java @@ -22,6 +22,7 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; +import org.apache.commons.lang.StringUtils; import org.apache.openjpa.conf.OpenJPAConfiguration; import org.apache.openjpa.lib.log.Log; import org.apache.openjpa.lib.meta.ClassArgParser; @@ -55,7 +56,7 @@ public abstract class AbstractMetaDataFactory * auto-configuration. */ public void setTypes(String types) { - this.types = (types == null || types.length() == 0) ? null + this.types = (StringUtils.isEmpty(types)) ? null : new HashSet(Arrays.asList(Strings.split(types, ";", 0))); } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java index 99add4318..73cfd67cd 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java @@ -1036,12 +1036,7 @@ public class FieldMetaData * the field's elements. */ public void setOrderDeclaration(String dec) { - if (dec != null) { - dec = dec.trim(); - if (dec.length() == 0) - dec = null; - } - _orderDec = dec; + _orderDec = StringUtils.trimToNull(dec); _orders = null; } @@ -1398,7 +1393,7 @@ public class FieldMetaData * @return the method for invocation */ private Method findMethod(String method) { - if (method == null || method.length() == 0) + if (StringUtils.isEmpty(method)) return null; // get class name and get package name divide on the last '.', so the diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/QueryMetaData.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/QueryMetaData.java index 280311e0b..af9148737 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/QueryMetaData.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/QueryMetaData.java @@ -19,6 +19,7 @@ import java.io.File; import java.util.LinkedList; import java.util.List; +import org.apache.commons.lang.StringUtils; import org.apache.openjpa.kernel.Query; import org.apache.openjpa.lib.meta.SourceTracker; import org.apache.openjpa.lib.xml.Commentable; @@ -185,7 +186,7 @@ public class QueryMetaData public void setInto(Query query) { if (_candidate != null) query.setCandidateType(_candidate, true); - if (_query != null && _query.length() > 0) + if (!StringUtils.isEmpty(_query)) query.setQuery(_query); if (_res != null) query.setResultType(_res); diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configurations.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configurations.java index 3c765b41b..c7de67e13 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configurations.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configurations.java @@ -30,6 +30,7 @@ import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; +import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.exception.NestableRuntimeException; import org.apache.openjpa.lib.log.Log; import org.apache.openjpa.lib.util.JavaVersions; @@ -71,7 +72,7 @@ public class Configurations { private static String getPluginComponent(String plugin, boolean clsName) { if (plugin != null) plugin = plugin.trim(); - if (plugin == null || plugin.length() == 0) + if (StringUtils.isEmpty(plugin)) return null; int openParen = -1; @@ -96,9 +97,9 @@ public class Configurations { * Combine the given class name and properties into a plugin string. */ public static String getPlugin(String clsName, String props) { - if (clsName == null || clsName.length() == 0) + if (StringUtils.isEmpty(clsName)) return props; - if (props == null || props.length() == 0) + if (StringUtils.isEmpty(props)) return clsName; return clsName + "(" + props + ")"; } @@ -129,7 +130,7 @@ public class Configurations { */ static Object newInstance(String clsName, Value val, Configuration conf, ClassLoader loader, boolean fatal) { - if (clsName == null || clsName.length() == 0) + if (StringUtils.isEmpty(clsName)) return null; if (loader == null && conf != null) loader = conf.getClass().getClassLoader(); @@ -173,7 +174,7 @@ public class Configurations { public static void populateConfiguration(Configuration conf, Options opts) { String props = opts.removeProperty("properties", "p", null); ConfigurationProvider provider; - if (props != null && props.length() > 0) { + if (!StringUtils.isEmpty(props)) { String path = props; String anchor = null; int idx = path.lastIndexOf('#'); @@ -279,7 +280,7 @@ public class Configurations { return; Properties props = null; - if (properties != null && properties.length() > 0) + if (!StringUtils.isEmpty(properties)) props = parseProperties(properties); configureInstance(obj, conf, props, configurationName); } @@ -388,11 +389,9 @@ public class Configurations { */ public static Options parseProperties(String properties) { Options opts = new Options(); + properties = StringUtils.trimToNull(properties); if (properties == null) return opts; - properties = properties.trim(); - if (properties.length() == 0) - return opts; try { String[] props = Strings.split(properties, ",", 0); @@ -453,7 +452,7 @@ public class Configurations { * Looks up the given name in JNDI. If the name is null, null is returned. */ public static Object lookup(String name) { - if (name == null || name.length() == 0) + if (StringUtils.isEmpty(name)) return null; Context ctx = null; diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/DoubleValue.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/DoubleValue.java index 1698c8d26..6e8d0efb1 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/DoubleValue.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/DoubleValue.java @@ -15,6 +15,8 @@ */ package org.apache.openjpa.lib.conf; +import org.apache.commons.lang.StringUtils; + /** * A double {@link Value}. * @@ -54,7 +56,7 @@ public class DoubleValue extends Value { } protected void setInternalString(String val) { - if (val == null || val.length() == 0) + if (StringUtils.isEmpty(val)) set(0D); else set(Double.parseDouble(val)); diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/IntValue.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/IntValue.java index db3f0631b..1fedbcfa5 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/IntValue.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/IntValue.java @@ -15,6 +15,8 @@ */ package org.apache.openjpa.lib.conf; +import org.apache.commons.lang.StringUtils; + /** * An int {@link Value}. * @@ -54,7 +56,7 @@ public class IntValue extends Value { } protected void setInternalString(String val) { - if (val == null || val.length() == 0) + if (StringUtils.isEmpty(val)) set(0); else set(Integer.parseInt(val)); diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/PluginListValue.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/PluginListValue.java index 0c3866ac3..88700386f 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/PluginListValue.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/PluginListValue.java @@ -19,6 +19,8 @@ import java.lang.reflect.Array; import java.util.ArrayList; import java.util.List; +import org.apache.commons.lang.StringUtils; + /** * A list of plugins. Defaults and aliases on plugin lists apply only * to individual class names. @@ -117,9 +119,9 @@ public class PluginListValue extends ObjectValue { * properties string. */ public void setString(String str) { - if (str == null || str.length() == 0) + if (StringUtils.isEmpty(str)) str = getDefault(); - if (str == null || str.length() == 0) { + if (StringUtils.isEmpty(str)) { _names = EMPTY; _props = EMPTY; set(null, true); diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivations.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivations.java index 7dcf19916..20e3a4d1e 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivations.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivations.java @@ -22,6 +22,7 @@ import java.util.Comparator; import java.util.List; import java.util.MissingResourceException; +import org.apache.commons.lang.StringUtils; import org.apache.openjpa.lib.util.Localizer; import org.apache.openjpa.lib.util.Services; @@ -148,7 +149,7 @@ public class ProductDerivations { */ public static ConfigurationProvider load(String resource, String anchor, ClassLoader loader) { - if (resource == null || resource.length() == 0) + if (StringUtils.isEmpty(resource)) return null; if (loader == null) loader = Thread.currentThread().getContextClassLoader(); diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/LogOutputStream.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/LogOutputStream.java index b9eeae7f7..4e7292a77 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/LogOutputStream.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/LogOutputStream.java @@ -48,9 +48,12 @@ public class LogOutputStream extends ByteArrayOutputStream { public void flush() throws IOException { super.flush(); + byte[] bytes = toByteArray(); + if (bytes.length == 0) + return; - String msg = new String(toByteArray()); - if (msg != null && msg.length() > 0 && msg.indexOf(_sep) != -1) { + String msg = new String(bytes); + if (msg.indexOf(_sep) != -1) { // break up the message based on the line separator; this // may be because the flushed buffer contains mutliple lines for (StringTokenizer tok = new StringTokenizer(msg, _sep); diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/CFMetaDataParser.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/CFMetaDataParser.java index 2d2258905..6a1ec4c2a 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/CFMetaDataParser.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/CFMetaDataParser.java @@ -15,9 +15,10 @@ */ package org.apache.openjpa.lib.meta; +import org.apache.commons.lang.StringUtils; +import org.apache.openjpa.lib.util.Localizer; import org.xml.sax.Attributes; import org.xml.sax.SAXException; -import org.apache.openjpa.lib.util.Localizer; import serp.util.Strings; /** @@ -173,8 +174,7 @@ public class CFMetaDataParser extends XMLMetaDataParser { throws SAXException { if (getClassAttributeName() != null) { _class = attrs.getValue(getClassAttributeName()); - if (_package != null && _package.length() > 0 - && _class.indexOf('.') == -1) + if (!StringUtils.isEmpty(_package) && _class.indexOf('.') == -1) _class = _package + "." + _class; } return true; @@ -188,8 +188,7 @@ public class CFMetaDataParser extends XMLMetaDataParser { _class = null; else { _class = currentText(); - if (_package != null && _package.length() > 0 - && _class.indexOf('.') == -1) + if (!StringUtils.isEmpty(_package) && _class.indexOf('.') == -1) _class = _package + "." + _class; } } @@ -289,13 +288,13 @@ public class CFMetaDataParser extends XMLMetaDataParser { */ public static Class classForName(String name, String pkg, boolean resolve, ClassLoader loader) { - if (name == null || name.length() == 0) + if (StringUtils.isEmpty(name)) return null; if (loader == null) loader = Thread.currentThread().getContextClassLoader(); boolean fullName = name.indexOf('.') != -1; - boolean noPackage = pkg == null || pkg.length() == 0; + boolean noPackage = StringUtils.isEmpty(pkg); try { if (fullName || noPackage) return Strings.toClass(name, resolve, loader); diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/ClassArgParser.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/ClassArgParser.java index 8ca36b2c6..e38a69732 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/ClassArgParser.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/ClassArgParser.java @@ -31,6 +31,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.exception.NestableRuntimeException; import org.apache.openjpa.lib.util.Files; import org.apache.openjpa.lib.util.Localizer; @@ -354,10 +355,7 @@ public class ClassArgParser { return clsName; } finally { if (in != null) - try { - in.close(); - } catch (IOException ioe) { - } + try { in.close(); } catch (IOException ioe) {} } } diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Files.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Files.java index ad4b8c501..2e3f5e23b 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Files.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Files.java @@ -28,6 +28,7 @@ import java.io.Writer; import java.net.URL; import java.net.URLDecoder; +import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.exception.NestableRuntimeException; import serp.util.Strings; @@ -134,7 +135,7 @@ public class Files { public static File getPackageFile(File base, String pkg, boolean mkdirs) { if (base == null) base = new File(System.getProperty("user.dir")); - if (pkg == null || pkg.length() == 0) { + if (StringUtils.isEmpty(pkg)) { if (mkdirs && !base.exists()) base.mkdirs(); return base; diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Options.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Options.java index 8f6fbcc39..000101c55 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Options.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Options.java @@ -103,7 +103,7 @@ public class Options extends TypedProperties { if (i == args.length || args[i].startsWith("-")) { key = trimQuote(key); if (key != null) { - if (value != null && value.length() > 0) + if (!StringUtils.isEmpty(value)) setProperty(key, trimQuote(value)); else setProperty(key, "true"); @@ -291,7 +291,7 @@ public class Options extends TypedProperties { */ private static boolean matchOptionToMember(String key, Object[] match) throws Exception { - if (key == null || key.length() == 0) + if (StringUtils.isEmpty(key)) return false; // unfortunately we can't use bean properties for setters; any diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java index ebff6a8e0..6a9da83cc 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java @@ -29,6 +29,7 @@ import javax.resource.cci.Interaction; import javax.resource.cci.LocalTransaction; import javax.resource.cci.ResultSetInfo; +import org.apache.commons.lang.StringUtils; import org.apache.openjpa.conf.OpenJPAConfiguration; import org.apache.openjpa.ee.ManagedRuntime; import org.apache.openjpa.kernel.Broker; @@ -729,7 +730,7 @@ public class EntityManagerImpl * Validate that the user provided SQL. */ private static void validateSQL(String query) { - if (query == null || query.trim().length() == 0) + if (StringUtils.trimToNull(query) == null) throw new ArgumentException(_loc.get("no-sql"), null, null, false); } diff --git a/openjpa-xmlstore/src/main/java/org/apache/openjpa/xmlstore/XMLFileHandler.java b/openjpa-xmlstore/src/main/java/org/apache/openjpa/xmlstore/XMLFileHandler.java index d13e6be50..e836e5398 100644 --- a/openjpa-xmlstore/src/main/java/org/apache/openjpa/xmlstore/XMLFileHandler.java +++ b/openjpa-xmlstore/src/main/java/org/apache/openjpa/xmlstore/XMLFileHandler.java @@ -520,7 +520,7 @@ public class XMLFileHandler { case JavaTypes.OBJECT: case JavaTypes.OID: - // convert the characters into bytes, and run them through an + // convert the chars into bytes, and run them through an // ObjectInputStream in order to get the serialized object byte[] bytes = Base16Encoder.decode(str); ByteArrayInputStream bais = new ByteArrayInputStream(bytes);