You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by nd...@apache.org on 2006/11/03 05:44:11 UTC
svn commit: r470669 - in
/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java:
java/sql/ org/apache/harmony/sql/internal/common/
Author: ndbeyer
Date: Thu Nov 2 20:44:10 2006
New Revision: 470669
URL: http://svn.apache.org/viewvc?view=rev&rev=470669
Log:
Cleanup code -
* Add missing annotations
* Delete ClassUtils; move the only used method to DriverManager
Removed:
incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/common/
Modified:
incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/CallableStatement.java
incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Date.java
incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/DriverManager.java
incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/PreparedStatement.java
incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/ResultSet.java
incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Time.java
incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Timestamp.java
Modified: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/CallableStatement.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/CallableStatement.java?view=diff&rev=470669&r1=470668&r2=470669
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/CallableStatement.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/CallableStatement.java Thu Nov 2 20:44:10 2006
@@ -109,6 +109,7 @@
* @deprecated Use getBigDecimal(int parameterIndex) or getBigDecimal(String
* parameterName)
*/
+ @Deprecated
public BigDecimal getBigDecimal(int parameterIndex, int scale)
throws SQLException;
Modified: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Date.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Date.java?view=diff&rev=470669&r1=470668&r2=470669
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Date.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Date.java Thu Nov 2 20:44:10 2006
@@ -50,6 +50,8 @@
* @param theDay
* the day in the month. Must be in the range 1 to 31.
*/
+ @SuppressWarnings("deprecation")
+ @Deprecated
public Date(int theYear, int theMonth, int theDay) {
super(theYear, theMonth, theDay);
}
@@ -76,6 +78,9 @@
* @throws IllegalArgumentException
* if this method is called
*/
+ @SuppressWarnings("deprecation")
+ @Deprecated
+ @Override
public int getHours() {
throw new IllegalArgumentException();
}
@@ -87,6 +92,9 @@
* @throws IllegalArgumentException
* if this method is called
*/
+ @SuppressWarnings("deprecation")
+ @Deprecated
+ @Override
public int getMinutes() {
throw new IllegalArgumentException();
}
@@ -98,6 +106,9 @@
* @throws IllegalArgumentException
* if this method is called
*/
+ @SuppressWarnings("deprecation")
+ @Deprecated
+ @Override
public int getSeconds() {
throw new IllegalArgumentException();
}
@@ -110,6 +121,9 @@
* @throws IllegalArgumentException
* if this method is called
*/
+ @SuppressWarnings("deprecation")
+ @Deprecated
+ @Override
public void setHours(int theHours) {
throw new IllegalArgumentException();
}
@@ -122,6 +136,9 @@
* @throws IllegalArgumentException
* if this method is called
*/
+ @SuppressWarnings("deprecation")
+ @Deprecated
+ @Override
public void setMinutes(int theMinutes) {
throw new IllegalArgumentException();
}
@@ -134,6 +151,9 @@
* @throws IllegalArgumentException
* if this method is called
*/
+ @SuppressWarnings("deprecation")
+ @Deprecated
+ @Override
public void setSeconds(int theSeconds) {
throw new IllegalArgumentException();
}
@@ -146,6 +166,7 @@
* @param theTime
* the time in milliseconds since the Epoch
*/
+ @Override
public void setTime(long theTime) {
/*
* Store the Date based on the supplied time after removing any time
@@ -159,6 +180,7 @@
*
* @return a string representation of the Date in SQL format - "yyyy-mm-dd".
*/
+ @Override
public String toString() {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); //$NON-NLS-1$
return dateFormat.format(this);
Modified: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/DriverManager.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/DriverManager.java?view=diff&rev=470669&r1=470668&r2=470669
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/DriverManager.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/DriverManager.java Thu Nov 2 20:44:10 2006
@@ -25,7 +25,6 @@
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Vector;
-import org.apache.harmony.sql.internal.common.ClassUtils;
import org.apache.harmony.sql.internal.nls.Messages;
import org.apache.harmony.kernel.vm.VM;
@@ -41,9 +40,9 @@
* Facilities for logging. The Print Stream is deprecated but is maintained
* here for compatibility.
*/
- private static PrintStream thePrintStream = null;
+ private static PrintStream thePrintStream;
- private static PrintWriter thePrintWriter = null;
+ private static PrintWriter thePrintWriter;
// Login timeout value - by default set to 0 -> "wait forever"
private static int loginTimeout = 0;
@@ -52,10 +51,10 @@
* Set to hold Registered Drivers - initial capacity 10 drivers (will expand
* automatically if necessary.
*/
- private static Set<Driver> theDriverSet = new HashSet<Driver>(10);
+ private static final Set<Driver> theDriverSet = new HashSet<Driver>(10);
// Permission for setting log
- private static SQLPermission logPermission = new SQLPermission("setLog"); //$NON-NLS-1$
+ private static final SQLPermission logPermission = new SQLPermission("setLog"); //$NON-NLS-1$
/*
* Load drivers on initialization
@@ -118,7 +117,7 @@
}
ClassLoader callerClassLoader = VM.callerClassLoader();
- if (!ClassUtils.isClassFromClassLoader(driver, callerClassLoader)) {
+ if (!DriverManager.isClassFromClassLoader(driver, callerClassLoader)) {
// sql.1=DriverManager: calling class not authorized to deregister JDBC driver
throw new SecurityException(Messages.getString("sql.1")); //$NON-NLS-1$
} // end if
@@ -175,9 +174,7 @@
* open a connection to the supplied URL - return the first
* connection which is returned
*/
- Iterator theIterator = theDriverSet.iterator();
- while (theIterator.hasNext()) {
- Driver theDriver = (Driver) theIterator.next();
+ for (Driver theDriver : theDriverSet) {
Connection theConnection = theDriver.connect(url, info);
if (theConnection != null) {
return theConnection;
@@ -186,7 +183,7 @@
}
// If we get here, none of the drivers are able to resolve the URL
// sql.6=No suitable driver
- throw new SQLException(Messages.getString("sql.6"), sqlState); //$NON-NLS-1$ //$NON-NLS-2$
+ throw new SQLException(Messages.getString("sql.6"), sqlState); //$NON-NLS-1$
}
/**
@@ -239,7 +236,7 @@
while (theIterator.hasNext()) {
Driver theDriver = theIterator.next();
if (theDriver.acceptsURL(url)
- && ClassUtils.isClassFromClassLoader(theDriver,
+ && DriverManager.isClassFromClassLoader(theDriver,
callerClassLoader)) {
return theDriver;
}
@@ -273,7 +270,7 @@
Iterator<Driver> theIterator = theDriverSet.iterator();
while (theIterator.hasNext()) {
Driver theDriver = theIterator.next();
- if (ClassUtils.isClassFromClassLoader(theDriver,
+ if (DriverManager.isClassFromClassLoader(theDriver,
callerClassLoader)) {
theVector.add(theDriver);
}
@@ -296,6 +293,7 @@
* the JDBC Drivers.
* @return the PrintStream used for logging activity
*/
+ @Deprecated
public static PrintStream getLogStream() {
return thePrintStream;
}
@@ -371,6 +369,7 @@
* @param out
* the PrintStream to use for logging.
*/
+ @Deprecated
public static void setLogStream(PrintStream out) {
checkLogSecurity();
thePrintStream = out;
@@ -398,5 +397,36 @@
// Throws a SecurityException if setting the log is not permitted
securityManager.checkPermission(logPermission);
}
+ }
+
+ /**
+ * Finds if a supplied Object belongs to the given ClassLoader.
+ *
+ * @param theObject
+ * the object to check
+ * @param theClassLoader
+ * the ClassLoader
+ * @return true if the Object does belong to the ClassLoader, false
+ * otherwise
+ */
+ private static boolean isClassFromClassLoader(Object theObject,
+ ClassLoader theClassLoader) {
+
+ if ((theObject == null) || (theClassLoader == null)) {
+ return false;
+ }
+
+ Class<?> objectClass = theObject.getClass();
+
+ try {
+ Class<?> checkClass = Class.forName(objectClass.getName(), true,
+ theClassLoader);
+ if (checkClass == objectClass) {
+ return true;
+ }
+ } catch (Throwable t) {
+ // Empty
+ }
+ return false;
}
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/PreparedStatement.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/PreparedStatement.java?view=diff&rev=470669&r1=470668&r2=470669
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/PreparedStatement.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/PreparedStatement.java Thu Nov 2 20:44:10 2006
@@ -612,6 +612,7 @@
* @throws SQLException
* if a database error happens
*/
+ @Deprecated
public void setUnicodeStream(int parameterIndex,
InputStream theInputStream, int length) throws SQLException;
Modified: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/ResultSet.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/ResultSet.java?view=diff&rev=470669&r1=470668&r2=470669
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/ResultSet.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/ResultSet.java Thu Nov 2 20:44:10 2006
@@ -300,6 +300,7 @@
* @throws SQLException
* if a database error happens
*/
+ @Deprecated
public BigDecimal getBigDecimal(int columnIndex, int scale)
throws SQLException;
@@ -326,6 +327,7 @@
* @throws SQLException
* if a database error happens
*/
+ @Deprecated
public BigDecimal getBigDecimal(String columnName, int scale)
throws SQLException;
@@ -1013,6 +1015,7 @@
* @throws SQLException
* if a database error happens
*/
+ @Deprecated
public InputStream getUnicodeStream(int columnIndex) throws SQLException;
/**
@@ -1027,6 +1030,7 @@
* @throws SQLException
* if a database error happens
*/
+ @Deprecated
public InputStream getUnicodeStream(String columnName) throws SQLException;
/**
Modified: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Time.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Time.java?view=diff&rev=470669&r1=470668&r2=470669
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Time.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Time.java Thu Nov 2 20:44:10 2006
@@ -47,6 +47,8 @@
* @param theSecond
* a value from 0 - 59
*/
+ @SuppressWarnings("deprecation")
+ @Deprecated
public Time(int theHour, int theMinute, int theSecond) {
super(70, 0, 1, theHour, theMinute, theSecond);
}
@@ -69,6 +71,9 @@
* @throws IllegalArgumentException
* if this method is called
*/
+ @SuppressWarnings("deprecation")
+ @Deprecated
+ @Override
public int getDate() {
throw new IllegalArgumentException();
}
@@ -80,6 +85,9 @@
* @throws IllegalArgumentException
* if this method is called
*/
+ @SuppressWarnings("deprecation")
+ @Deprecated
+ @Override
public int getDay() {
throw new IllegalArgumentException();
}
@@ -91,6 +99,9 @@
* @throws IllegalArgumentException
* if this method is called
*/
+ @SuppressWarnings("deprecation")
+ @Deprecated
+ @Override
public int getMonth() {
throw new IllegalArgumentException();
}
@@ -102,6 +113,9 @@
* @throws IllegalArgumentException
* if this method is called
*/
+ @SuppressWarnings("deprecation")
+ @Deprecated
+ @Override
public int getYear() {
throw new IllegalArgumentException();
}
@@ -112,6 +126,9 @@
* @throws IllegalArgumentException
* if this method is called
*/
+ @SuppressWarnings("deprecation")
+ @Deprecated
+ @Override
public void setDate(int i) {
throw new IllegalArgumentException();
}
@@ -122,6 +139,9 @@
* @throws IllegalArgumentException
* if this method is called
*/
+ @SuppressWarnings("deprecation")
+ @Deprecated
+ @Override
public void setMonth(int i) {
throw new IllegalArgumentException();
}
@@ -132,6 +152,9 @@
* @throws IllegalArgumentException
* if this method is called
*/
+ @SuppressWarnings("deprecation")
+ @Deprecated
+ @Override
public void setYear(int i) {
throw new IllegalArgumentException();
}
@@ -144,6 +167,7 @@
* Negative values are milliseconds before the Epoch. The Epoch
* is January 1 1970, 00:00:00.000
*/
+ @Override
public void setTime(long time) {
super.setTime(time);
}
@@ -154,6 +178,7 @@
* @return A String representing the Time value in JDBC escape format:
* HH:mm:ss
*/
+ @Override
public String toString() {
SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); //$NON-NLS-1$
return dateFormat.format(this);
@@ -179,7 +204,7 @@
}
int firstIndex = timeString.indexOf(':');
int secondIndex = timeString.indexOf(':', firstIndex + 1);
- // secondIndex == -1 means none or only one separater '-' has been found.
+ // secondIndex == -1 means none or only one separator '-' has been found.
// The string is separated into three parts by two separator characters,
// if the first or the third part is null string, we should throw
// IllegalArgumentException to follow RI
Modified: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Timestamp.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Timestamp.java?view=diff&rev=470669&r1=470668&r2=470669
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Timestamp.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Timestamp.java Thu Nov 2 20:44:10 2006
@@ -70,6 +70,8 @@
* @throws IllegalArgumentException
* if any of the parameters is out of range
*/
+ @SuppressWarnings("deprecation")
+ @Deprecated
public Timestamp(int theYear, int theMonth, int theDate, int theHour,
int theMinute, int theSecond, int theNano)
throws IllegalArgumentException {
@@ -173,6 +175,7 @@
* @throws ClassCastException
* if the supplied object is not a Timestamp object
*/
+ @Override
public int compareTo(Date theObject) throws ClassCastException {
return this.compareTo((Timestamp) theObject);
}
@@ -211,6 +214,7 @@
* object false if the object is not a Timestamp object or if the
* object is a Timestamp but represents a different instant in time
*/
+ @Override
public boolean equals(Object theObject) {
if (theObject instanceof Timestamp) {
return equals((Timestamp) theObject);
@@ -250,6 +254,7 @@
* containing the number of milliseconds since the Epoch (January 1 1970,
* 00:00:00.000 GMT)
*/
+ @Override
public long getTime() {
long theTime = super.getTime();
theTime = theTime + (nanos / 1000000);
@@ -272,6 +277,7 @@
* defined as the number of milliseconds since the Epoch (January 1 1970,
* 00:00:00.000 GMT)
*/
+ @Override
public void setTime(long theTime) {
/*
* Deal with the nanoseconds value. The supplied time is in milliseconds -
@@ -300,6 +306,7 @@
* @return A string representing the instant defined by the Timestamp, in
* JDBC Timestamp escape format
*/
+ @SuppressWarnings("deprecation")
@Override
public String toString() {
/*
@@ -360,9 +367,6 @@
return finalString;
}
- // sql.2=Timestamp format must be yyyy-mm-dd hh:mm:ss.fffffffff
- private static String valueOfExceptionMessage = Messages.getString("sql.2"); //$NON-NLS-1$
-
/**
* Creates a Timestamp object with a time value equal to the time specified
* by a supplied String holding the time in JDBC timestamp escape format,
@@ -393,11 +397,11 @@
try {
theDate = df.parse(s, pp);
} catch (Exception e) {
- throw new IllegalArgumentException(valueOfExceptionMessage);
+ throw new IllegalArgumentException(Messages.getString("sql.2")); //$NON-NLS-1$
}
if (theDate == null) {
- throw new IllegalArgumentException(valueOfExceptionMessage);
+ throw new IllegalArgumentException(Messages.getString("sql.2")); //$NON-NLS-1$
}
/*
@@ -421,7 +425,7 @@
* plus the "." in the remaining part of the string...
*/
if ((s.length() - position) < ".n".length()) { //$NON-NLS-1$
- throw new IllegalArgumentException(valueOfExceptionMessage);
+ throw new IllegalArgumentException(Messages.getString("sql.2")); //$NON-NLS-1$
}
/*
@@ -429,7 +433,7 @@
* the 9 digits
*/
if ((s.length() - position) > ".nnnnnnnnn".length()) { //$NON-NLS-1$
- throw new IllegalArgumentException(valueOfExceptionMessage);
+ throw new IllegalArgumentException(Messages.getString("sql.2")); //$NON-NLS-1$
}
// Require the next character to be a "."
@@ -454,12 +458,12 @@
theNanos = Integer.parseInt(theNanoString);
} catch (Exception e) {
// If we get here, the string was not a number
- throw new IllegalArgumentException(valueOfExceptionMessage);
+ throw new IllegalArgumentException(Messages.getString("sql.2")); //$NON-NLS-1$
}
}
if (theNanos < 0 || theNanos > 999999999) {
- throw new IllegalArgumentException(valueOfExceptionMessage);
+ throw new IllegalArgumentException(Messages.getString("sql.2")); //$NON-NLS-1$
}
Timestamp theTimestamp = new Timestamp(theDate.getTime());