Take advantage StringUtils where appropriate.

git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@462617 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
A. Abram White 2006-10-10 22:39:15 +00:00
parent 08d69d15a7
commit f27898f280
44 changed files with 136 additions and 141 deletions

View File

@ -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

View File

@ -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) {

View File

@ -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)

View File

@ -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().

View File

@ -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");

View File

@ -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;
}

View File

@ -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));

View File

@ -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));

View File

@ -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);

View File

@ -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);
}
/**

View File

@ -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);

View File

@ -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());

View File

@ -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);
}
/**

View File

@ -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 &&

View File

@ -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();

View File

@ -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());

View File

@ -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);

View File

@ -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();

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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)

View File

@ -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) {

View File

@ -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);
}

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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('.');

View File

@ -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";

View File

@ -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;

View File

@ -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)));
}

View File

@ -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)));
}

View File

@ -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

View File

@ -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);

View File

@ -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;

View File

@ -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));

View File

@ -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));

View File

@ -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);

View File

@ -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();

View File

@ -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);

View File

@ -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);

View File

@ -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) {}
}
}

View File

@ -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;

View File

@ -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

View File

@ -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);
}

View File

@ -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);