-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(quartz): allow serializing complex objects in JobDataMaps
- Loading branch information
Showing
15 changed files
with
300 additions
and
65 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
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
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
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
26 changes: 26 additions & 0 deletions
26
extensions/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/jdbc/DBDelegateUtils.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,26 @@ | ||
package io.quarkus.quartz.runtime.jdbc; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.ObjectInputStream; | ||
|
||
class DBDelegateUtils { | ||
/** | ||
* A method to deserialize a marshalled object in an input stream. | ||
* This implementation uses {@link QuarkusObjectInputStream} instead of {@link ObjectInputStream} to workaround | ||
* a {@link ClassNotFoundException} issue observed in Test & Dev mode when `resolveClass(ObjectStreamClass)` is called. | ||
*/ | ||
static Object getObjectFromInput(InputStream binaryInput) throws ClassNotFoundException, IOException { | ||
if (binaryInput == null || binaryInput.available() == 0) { | ||
return null; | ||
} | ||
// use an instance of the QuarkusObjectInputStream class instead of the ObjectInputStream when deserializing | ||
// to workaround a CNFE in test and dev mode. | ||
ObjectInputStream in = new QuarkusObjectInputStream(binaryInput); | ||
try { | ||
return in.readObject(); | ||
} finally { | ||
in.close(); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...ions/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/jdbc/QuarkusDBv8Delegate.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,25 @@ | ||
package io.quarkus.quartz.runtime.jdbc; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.ObjectStreamClass; | ||
import java.sql.Blob; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
|
||
public class QuarkusDBv8Delegate extends org.quartz.impl.jdbcjobstore.DB2v8Delegate { | ||
/** | ||
* See the javadoc in {@link QuarkusObjectInputStream#resolveClass(ObjectStreamClass)} and | ||
* {@link DBDelegateUtils#getObjectFromInput(InputStream)} | ||
* on why this is needed | ||
*/ | ||
@Override | ||
protected Object getObjectFromBlob(ResultSet rs, String colName) throws ClassNotFoundException, IOException, SQLException { | ||
Blob blobLocator = rs.getBlob(colName); | ||
if (blobLocator == null || blobLocator.length() == 0) { | ||
return null; | ||
} | ||
InputStream binaryInput = blobLocator.getBinaryStream(); | ||
return DBDelegateUtils.getObjectFromInput(binaryInput); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...ns/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/jdbc/QuarkusHSQLDBDelegate.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,20 @@ | ||
package io.quarkus.quartz.runtime.jdbc; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.ObjectStreamClass; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
|
||
public class QuarkusHSQLDBDelegate extends org.quartz.impl.jdbcjobstore.HSQLDBDelegate { | ||
/** | ||
* See the javadoc in {@link QuarkusObjectInputStream#resolveClass(ObjectStreamClass)} and | ||
* {@link DBDelegateUtils#getObjectFromInput(InputStream)} | ||
* on why this is needed | ||
*/ | ||
@Override | ||
protected Object getObjectFromBlob(ResultSet rs, String colName) throws ClassNotFoundException, IOException, SQLException { | ||
InputStream binaryInput = rs.getBinaryStream(colName); | ||
return DBDelegateUtils.getObjectFromInput(binaryInput); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...ons/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/jdbc/QuarkusMSSQLDelegate.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,20 @@ | ||
package io.quarkus.quartz.runtime.jdbc; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.ObjectStreamClass; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
|
||
public class QuarkusMSSQLDelegate extends org.quartz.impl.jdbcjobstore.HSQLDBDelegate { | ||
/** | ||
* See the javadoc in {@link QuarkusObjectInputStream#resolveClass(ObjectStreamClass)} and | ||
* {@link DBDelegateUtils#getObjectFromInput(InputStream)} | ||
* on why this is needed | ||
*/ | ||
@Override | ||
protected Object getObjectFromBlob(ResultSet rs, String colName) throws ClassNotFoundException, IOException, SQLException { | ||
InputStream binaryInput = rs.getBinaryStream(colName); | ||
return DBDelegateUtils.getObjectFromInput(binaryInput); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...quartz/runtime/src/main/java/io/quarkus/quartz/runtime/jdbc/QuarkusObjectInputStream.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,38 @@ | ||
package io.quarkus.quartz.runtime.jdbc; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.ObjectInputStream; | ||
import java.io.ObjectStreamClass; | ||
|
||
/** | ||
* See the javadoc in {@link QuarkusObjectInputStream#resolveClass(ObjectStreamClass)} | ||
*/ | ||
class QuarkusObjectInputStream extends ObjectInputStream { | ||
public QuarkusObjectInputStream(InputStream in) throws IOException { | ||
super(in); | ||
} | ||
|
||
/** | ||
* We override the {@link ObjectInputStream#resolveClass(ObjectStreamClass)} method to workaround a class loading issue | ||
* in Test & Dev mode. | ||
* This is because, the implementation of this method in ObjectInputStream returns the result of calling | ||
* Class.forName(desc.getName(), false, loader) | ||
* where loader is the first class loader on the current thread's stack (starting from the currently executing method) | ||
* that is neither the platform class loader nor its ancestor; otherwise, loader is the platform class loader. | ||
* That classloader happens to the Base Runtime QuarkusClassLoader in Test and Dev mode which was causing | ||
* {@link ClassNotFoundException} | ||
* when loading user/application classes. | ||
* | ||
*/ | ||
@Override | ||
protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { | ||
String name = desc.getName(); | ||
try { | ||
// uses the TCCL to workaround CNFE encountered in test & dev mode | ||
return Class.forName(name, false, Thread.currentThread().getContextClassLoader()); | ||
} catch (ClassNotFoundException ex) { | ||
return super.resolveClass(desc); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...uartz/runtime/src/main/java/io/quarkus/quartz/runtime/jdbc/QuarkusPostgreSQLDelegate.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,26 @@ | ||
package io.quarkus.quartz.runtime.jdbc; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.ObjectStreamClass; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
|
||
public class QuarkusPostgreSQLDelegate extends org.quartz.impl.jdbcjobstore.PostgreSQLDelegate { | ||
/** | ||
* See the javadoc in {@link QuarkusObjectInputStream#resolveClass(ObjectStreamClass)} and | ||
* {@link DBDelegateUtils#getObjectFromInput(InputStream)} | ||
* on why this is needed | ||
*/ | ||
@Override | ||
protected Object getObjectFromBlob(ResultSet rs, String colName) throws ClassNotFoundException, IOException, SQLException { | ||
byte[] bytes = rs.getBytes(colName); | ||
if (bytes == null || bytes.length == 0) { | ||
return null; | ||
} | ||
|
||
InputStream binaryInput = new ByteArrayInputStream(bytes); | ||
return DBDelegateUtils.getObjectFromInput(binaryInput); | ||
} | ||
} |
Oops, something went wrong.