-
-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed DateFormat reentrant bug (#213)
* Fixed DateFormat reentrant bug. Thanks to Bob Lacatena. * Added some attempt at threaded tests. Can't reproduce the error tho.
- Loading branch information
Showing
5 changed files
with
186 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/com/j256/ormlite/field/types/DateStringFormatConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.j256.ormlite.field.types; | ||
|
||
import java.text.DateFormat; | ||
import java.text.SimpleDateFormat; | ||
|
||
/** | ||
* Date string format config that is it's own class to force the hiding of the DateFormat. | ||
* | ||
* @author graywatson | ||
*/ | ||
public class DateStringFormatConfig { | ||
|
||
private final String dateFormatStr; | ||
// used with clone | ||
private final DateFormat dateFormat; | ||
|
||
public DateStringFormatConfig(String dateFormatStr) { | ||
this.dateFormatStr = dateFormatStr; | ||
this.dateFormat = new SimpleDateFormat(dateFormatStr); | ||
} | ||
|
||
public DateFormat getDateFormat() { | ||
return (DateFormat) dateFormat.clone(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return dateFormatStr; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
src/test/java/com/j256/ormlite/LockedConnectionSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package com.j256.ormlite; | ||
|
||
import java.io.IOException; | ||
import java.sql.SQLException; | ||
|
||
import com.j256.ormlite.db.DatabaseType; | ||
import com.j256.ormlite.misc.IOUtils; | ||
import com.j256.ormlite.support.ConnectionSource; | ||
import com.j256.ormlite.support.DatabaseConnection; | ||
|
||
/** | ||
* Connection source that has a simple lock around it the delegate. | ||
* | ||
* @author graywatson | ||
*/ | ||
public class LockedConnectionSource implements ConnectionSource { | ||
|
||
protected ConnectionSource delegate; | ||
|
||
public LockedConnectionSource(ConnectionSource cs) { | ||
this.delegate = cs; | ||
} | ||
|
||
@Override | ||
public DatabaseConnection getReadOnlyConnection(String tableName) throws SQLException { | ||
synchronized (delegate) { | ||
return delegate.getReadOnlyConnection(tableName); | ||
} | ||
} | ||
|
||
@Override | ||
public DatabaseConnection getReadWriteConnection(String tableName) throws SQLException { | ||
synchronized (delegate) { | ||
return delegate.getReadWriteConnection(tableName); | ||
} | ||
} | ||
|
||
@Override | ||
public void releaseConnection(DatabaseConnection connection) throws SQLException { | ||
synchronized (delegate) { | ||
delegate.releaseConnection(connection); | ||
} | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
synchronized (delegate) { | ||
delegate.close(); | ||
} | ||
} | ||
|
||
@Override | ||
public void closeQuietly() { | ||
IOUtils.closeQuietly(this); | ||
} | ||
|
||
@Override | ||
public boolean saveSpecialConnection(DatabaseConnection connection) throws SQLException { | ||
synchronized (delegate) { | ||
return delegate.saveSpecialConnection(connection); | ||
} | ||
} | ||
|
||
@Override | ||
public void clearSpecialConnection(DatabaseConnection connection) { | ||
synchronized (delegate) { | ||
delegate.clearSpecialConnection(connection); | ||
} | ||
} | ||
|
||
@Override | ||
public DatabaseConnection getSpecialConnection(String tableName) { | ||
synchronized (delegate) { | ||
return delegate.getSpecialConnection(tableName); | ||
} | ||
} | ||
|
||
@Override | ||
public DatabaseType getDatabaseType() { | ||
synchronized (delegate) { | ||
return delegate.getDatabaseType(); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isOpen(String tableName) { | ||
synchronized (delegate) { | ||
return delegate.isOpen(tableName); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isSingleConnection(String tableName) { | ||
synchronized (delegate) { | ||
return delegate.isSingleConnection(tableName); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters