Skip to content

Commit d37c37c

Browse files
author
Philip Z
committed
Map Oracle Business ID counters to integral NUMBER
1 parent 903e795 commit d37c37c

6 files changed

Lines changed: 76 additions & 12 deletions

File tree

‎examples/business-id-runtime/README.md‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ mvn -pl examples/business-id-runtime -am \
3434

3535
The live suite also verifies PostgreSQL, MySQL, and SQL Server in CI. The
3636
SQL Server cases include independent-connection allocation and concurrent
37-
schema startup. The DM8 case is deliberately local-only until a durable,
38-
licensed CI image is available. Run it only against a disposable DM8 instance;
37+
schema startup. DM8 and Oracle are local-only live checks until durable CI
38+
images and dedicated test credentials are available. Run DM8 only against a
39+
disposable instance;
3940
the test refuses to run without `TEAQL_TEST_DM8_ISOLATED=true`:
4041

4142
```bash
@@ -48,3 +49,18 @@ mvn -pl examples/business-id-runtime -am \
4849
'-Dtest=JdbcBusinessIdLiveDialectIT#dm8AllocatesAcrossInstancesAndRestart' \
4950
-Dsurefire.failIfNoSpecifiedTests=false test
5051
```
52+
53+
For Oracle, create a dedicated `TEAQL_LIVE_*` user in an isolated test PDB,
54+
then run the Oracle method with that user's credentials. Oracle requires
55+
`new JdbcBusinessIdAllocator(database, table, new OracleDialect())` so the
56+
Business ID counter uses `NUMBER(19,0)` rather than unsupported `BIGINT`:
57+
58+
```bash
59+
TEAQL_REQUIRE_LIVE_DB=true \
60+
TEAQL_TEST_ORACLE_URL='jdbc:oracle:thin:@//127.0.0.1:1521/FREEPDB1' \
61+
TEAQL_TEST_ORACLE_USER='TEAQL_LIVE_BID' \
62+
TEAQL_TEST_ORACLE_PASSWORD='<test-user-password>' \
63+
mvn -pl examples/business-id-runtime -am \
64+
'-Dtest=JdbcBusinessIdLiveDialectIT#oracleAllocatesAcrossInstancesAndRestart' \
65+
-Dsurefire.failIfNoSpecifiedTests=false test
66+
```

‎examples/business-id-runtime/pom.xml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,11 @@
5555
<version>8.1.3.140</version>
5656
<scope>test</scope>
5757
</dependency>
58+
<dependency>
59+
<groupId>com.oracle.database.jdbc</groupId>
60+
<artifactId>ojdbc11</artifactId>
61+
<version>23.9.0.25.07</version>
62+
<scope>test</scope>
63+
</dependency>
5864
</dependencies>
5965
</project>

‎examples/business-id-runtime/src/test/java/io/teaql/examples/businessid/JdbcBusinessIdLiveDialectIT.java‎

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import io.teaql.core.businessid.BusinessIdGenerationRequest;
88
import io.teaql.core.businessid.BusinessIdPlan;
99
import io.teaql.runtime.businessid.DailySequenceBusinessIdProfile;
10+
import io.teaql.core.sql.dialect.OracleDialect;
1011
import java.sql.Connection;
1112
import java.sql.DriverManager;
1213
import java.time.LocalDate;
@@ -49,6 +50,11 @@ public void dm8AllocatesAcrossInstancesAndRestart() throws Exception {
4950
verify("DM8");
5051
}
5152

53+
@Test
54+
public void oracleAllocatesAcrossInstancesAndRestart() throws Exception {
55+
verify("ORACLE");
56+
}
57+
5258
@Test
5359
public void sqlServerConcurrentSchemaStartupIsIdempotent() throws Exception {
5460
String url = System.getenv("TEAQL_TEST_MSSQL_URL");
@@ -107,6 +113,9 @@ private void verify(String dialect) throws Exception {
107113
if ("DM8".equals(dialect)) {
108114
Assert.assertEquals("Use only an isolated disposable DM8 instance",
109115
"true", System.getenv("TEAQL_TEST_DM8_ISOLATED"));
116+
} else if ("ORACLE".equals(dialect)) {
117+
Assert.assertTrue("Use only a dedicated TEAQL_LIVE_* Oracle user",
118+
user.toUpperCase(java.util.Locale.ROOT).startsWith("TEAQL_LIVE_"));
110119
} else {
111120
Assert.assertTrue("Use a dedicated teaql_live_* database for " + dialect,
112121
url.contains("teaql_live_"));
@@ -120,8 +129,7 @@ private void verify(String dialect) throws Exception {
120129
"commerce_order", BUSINESS_DATE));
121130

122131
try (Connection schemaConnection = DriverManager.getConnection(url, user, password)) {
123-
JdbcBusinessIdAllocator allocator = new JdbcBusinessIdAllocator(
124-
BusinessIdRuntimeExampleTest.database(schemaConnection));
132+
JdbcBusinessIdAllocator allocator = allocator(schemaConnection, dialect);
125133
UserContext context = BusinessIdRuntimeExampleTest.context(BUSINESS_DATE, allocator);
126134
context.putAttribute(SchemaExecutor.class.getName(),
127135
BusinessIdRuntimeExampleTest.noOpSchemaExecutor());
@@ -136,8 +144,7 @@ private void verify(String dialect) throws Exception {
136144
for (int worker = 0; worker < 2; worker++) {
137145
futures.add(workers.submit(() -> {
138146
try (Connection connection = DriverManager.getConnection(url, user, password)) {
139-
JdbcBusinessIdAllocator allocator = new JdbcBusinessIdAllocator(
140-
BusinessIdRuntimeExampleTest.database(connection));
147+
JdbcBusinessIdAllocator allocator = allocator(connection, dialect);
141148
Assert.assertTrue("Concurrent start timed out",
142149
start.await(15, TimeUnit.SECONDS));
143150
List<Long> sequences = new ArrayList<>();
@@ -163,10 +170,19 @@ private void verify(String dialect) throws Exception {
163170
}
164171

165172
try (Connection restarted = DriverManager.getConnection(url, user, password)) {
166-
JdbcBusinessIdAllocator allocator = new JdbcBusinessIdAllocator(
167-
BusinessIdRuntimeExampleTest.database(restarted));
173+
JdbcBusinessIdAllocator allocator = allocator(restarted, dialect);
168174
Assert.assertEquals(2L * ALLOCATIONS_PER_INSTANCE + 1,
169175
allocator.allocate(plan).sequence());
170176
}
171177
}
178+
179+
private static JdbcBusinessIdAllocator allocator(Connection connection, String dialect) {
180+
if ("ORACLE".equals(dialect)) {
181+
return new JdbcBusinessIdAllocator(
182+
BusinessIdRuntimeExampleTest.database(connection),
183+
JdbcBusinessIdAllocator.DEFAULT_TABLE,
184+
new OracleDialect());
185+
}
186+
return new JdbcBusinessIdAllocator(BusinessIdRuntimeExampleTest.database(connection));
187+
}
172188
}

‎teaql-business-id-jdbc/src/main/java/io/teaql/businessid/jdbc/JdbcBusinessIdAllocator.java‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import io.teaql.core.UserContext;
44
import io.teaql.core.businessid.*;
55
import io.teaql.core.sql.portable.TeaQLDatabase;
6+
import io.teaql.core.sql.dialect.PostgreSqlDialect;
7+
import io.teaql.core.sql.dialect.SqlDialect;
68
import java.time.ZoneOffset;
79
import java.util.List;
810
import java.util.Map;
@@ -18,17 +20,23 @@ public final class JdbcBusinessIdAllocator
1820

1921
private final TeaQLDatabase database;
2022
private final String table;
23+
private final SqlDialect dialect;
2124

2225
public JdbcBusinessIdAllocator(TeaQLDatabase database) {
2326
this(database, DEFAULT_TABLE);
2427
}
2528

2629
public JdbcBusinessIdAllocator(TeaQLDatabase database, String table) {
30+
this(database, table, new PostgreSqlDialect());
31+
}
32+
33+
public JdbcBusinessIdAllocator(TeaQLDatabase database, String table, SqlDialect dialect) {
2734
this.database = java.util.Objects.requireNonNull(database, "database");
2835
if (table == null || !table.matches("[A-Za-z][A-Za-z0-9_]*")) {
2936
throw new IllegalArgumentException("Invalid Business ID table name: " + table);
3037
}
3138
this.table = table;
39+
this.dialect = java.util.Objects.requireNonNull(dialect, "dialect");
3240
}
3341

3442
/** Explicit development/test schema operation; construction never executes DDL. */
@@ -41,10 +49,10 @@ public void ensureSchema(UserContext context) {
4149
}
4250
try {
4351
database.execute(context, "CREATE TABLE " + table + " ("
44-
+ "scope_key VARCHAR(512) PRIMARY KEY, "
45-
+ "current_value BIGINT NOT NULL, "
46-
+ "version BIGINT NOT NULL, "
47-
+ "updated_at BIGINT NOT NULL)");
52+
+ "scope_key " + dialect.mapColumnType("VARCHAR(512)") + " PRIMARY KEY, "
53+
+ "current_value " + dialect.mapColumnType("BIGINT") + " NOT NULL, "
54+
+ "version " + dialect.mapColumnType("BIGINT") + " NOT NULL, "
55+
+ "updated_at " + dialect.mapColumnType("BIGINT") + " NOT NULL)");
4856
} catch (RuntimeException createFailure) {
4957
// Another instance may have created the table after inspection.
5058
// Only accept that race when the installed table can be inspected.

‎teaql-sql-portable/src/main/java/io/teaql/core/sql/dialect/OracleDialect.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public String mapColumnType(String type) {
4040
if ("LARGE_TEXT".equalsIgnoreCase(type)) {
4141
return "CLOB";
4242
}
43+
if ("BIGINT".equalsIgnoreCase(type)) {
44+
return "NUMBER(19,0)";
45+
}
4346
return type;
4447
}
4548
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package io.teaql.core.sql.portable;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
import io.teaql.core.sql.dialect.OracleDialect;
6+
import org.junit.Test;
7+
8+
public class OracleDialectTypeTest {
9+
@Test
10+
public void mapsBusinessIdCounterToIntegralNumber() {
11+
OracleDialect dialect = new OracleDialect();
12+
assertEquals("NUMBER(19,0)", dialect.mapColumnType("BIGINT"));
13+
assertEquals("VARCHAR(512)", dialect.mapColumnType("VARCHAR(512)"));
14+
}
15+
}

0 commit comments

Comments
 (0)