-
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.
Enhanced character set support for Oracle database
- Loading branch information
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
...deployment/src/main/java/io/quarkus/jdbc/oracle/deployment/ExtendedCharactersSupport.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,19 @@ | ||
package io.quarkus.jdbc.oracle.deployment; | ||
|
||
import static io.quarkus.deployment.annotations.ExecutionTime.STATIC_INIT; | ||
|
||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.annotations.Record; | ||
import io.quarkus.deployment.pkg.NativeConfig; | ||
import io.quarkus.deployment.pkg.steps.NativeBuild; | ||
import io.quarkus.jdbc.oracle.runtime.OracleInitRecorder; | ||
|
||
public final class ExtendedCharactersSupport { | ||
|
||
@Record(STATIC_INIT) | ||
@BuildStep(onlyIf = NativeBuild.class) | ||
public void preinitializeCharacterSets(NativeConfig config, OracleInitRecorder recorder) { | ||
recorder.setupCharSets(config.addAllCharsets); | ||
} | ||
|
||
} |
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
41 changes: 41 additions & 0 deletions
41
.../jdbc-oracle/runtime/src/main/java/io/quarkus/jdbc/oracle/runtime/OracleInitRecorder.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,41 @@ | ||
package io.quarkus.jdbc.oracle.runtime; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import io.quarkus.runtime.annotations.Recorder; | ||
import oracle.sql.CharacterSet; | ||
|
||
@Recorder | ||
public class OracleInitRecorder { | ||
|
||
public void setupCharSets(boolean addAllCharsets) { | ||
if (addAllCharsets) { | ||
for (short id : reflectivelyReadAllCharacterSetIdentifiers()) { | ||
oracle.sql.CharacterSet.make(id); | ||
} | ||
} else { | ||
//By default, support at least the following charsets; | ||
//without these, we're unable to connect to an Oracle container image which is using default settings. | ||
oracle.sql.CharacterSet.make(CharacterSet.AL32UTF8_CHARSET); | ||
oracle.sql.CharacterSet.make(CharacterSet.AL16UTF16_CHARSET); | ||
} | ||
} | ||
|
||
private List<Short> reflectivelyReadAllCharacterSetIdentifiers() { | ||
final Field[] fields = CharacterSet.class.getFields(); | ||
final ArrayList<Short> collectedIds = new ArrayList<>(fields.length); | ||
for (Field field : fields) { | ||
if (field.getType() == short.class && field.getName().endsWith("_CHARSET")) { | ||
try { | ||
collectedIds.add(field.getShort(null)); | ||
} catch (IllegalAccessException e) { | ||
//ignore | ||
} | ||
} | ||
} | ||
return collectedIds; | ||
} | ||
|
||
} |