Skip to content

Commit b2299c3

Browse files
committed
initial commit
1 parent 4ae01b6 commit b2299c3

File tree

10 files changed

+1397
-0
lines changed

10 files changed

+1397
-0
lines changed

.github/dependabot.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "maven"
4+
directory: "/" # Location of your Maven project
5+
schedule:
6+
interval: "daily" # Check for updates daily
7+
open-pull-requests-limit: 10

.github/workflows/maven-deploy.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Maven Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- main # or your default branch
7+
pull_request:
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v3
16+
17+
- name: Set up JDK 21
18+
uses: actions/setup-java@v3
19+
with:
20+
java-version: '21'
21+
22+
- name: Cache Maven packages
23+
uses: actions/cache@v3
24+
with:
25+
path: ~/.m2/repository
26+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
27+
restore-keys: |
28+
${{ runner.os }}-maven-
29+
30+
- name: Build with Maven
31+
run: mvn clean install
32+
33+
- name: Deploy with Maven
34+
run: mvn deploy
35+
env:
36+
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
37+
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}

pom.xml

Lines changed: 275 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,275 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.orbitalhq</groupId>
8+
<artifactId>mysql-connector</artifactId>
9+
<version>0.34.0-SNAPSHOT</version>
10+
11+
<properties>
12+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13+
14+
<kotlin.version>1.9.24</kotlin.version>
15+
<kotlin.code.style>official</kotlin.code.style>
16+
17+
18+
<java.version>21</java.version>
19+
<kotlin.compiler.jvmTarget>${java.version}</kotlin.compiler.jvmTarget>
20+
21+
<maven.compiler.source>${java.version}</maven.compiler.source>
22+
<maven.compiler.target>${java.version}</maven.compiler.target>
23+
<schemacrawler.version>16.19.7</schemacrawler.version>
24+
<orbital.version>0.34.0-SNAPSHOT</orbital.version>
25+
26+
<testcontainers.version>1.19.3</testcontainers.version>
27+
<junit.jupiter.version>5.9.2</junit.jupiter.version>
28+
<junit.vintage.version>5.9.2</junit.vintage.version>
29+
<kotest.version>5.5.5</kotest.version>
30+
</properties>
31+
<dependencies>
32+
<dependency>
33+
<groupId>us.fatehi</groupId>
34+
<artifactId>schemacrawler-mysql</artifactId>
35+
<version>${schemacrawler.version}</version>
36+
<exclusions>
37+
<exclusion>
38+
<groupId>org.slf4j</groupId>
39+
<artifactId>slf4j-nop</artifactId>
40+
</exclusion>
41+
</exclusions>
42+
</dependency>
43+
<dependency>
44+
<groupId>mysql</groupId>
45+
<artifactId>mysql-connector-java</artifactId>
46+
<version>8.0.33</version>
47+
</dependency>
48+
<dependency>
49+
<groupId>com.orbitalhq</groupId>
50+
<artifactId>jdbc-connector</artifactId>
51+
<version>${orbital.version}</version>
52+
<scope>provided</scope>
53+
</dependency>
54+
55+
56+
<dependency>
57+
<groupId>org.jetbrains.kotlin</groupId>
58+
<artifactId>kotlin-stdlib</artifactId>
59+
<version>${kotlin.version}</version>
60+
</dependency>
61+
62+
<!-- test dependencies -->
63+
<dependency>
64+
<groupId>org.jetbrains.kotlin</groupId>
65+
<artifactId>kotlin-test-junit5</artifactId>
66+
<version>${kotlin.version}</version>
67+
<scope>test</scope>
68+
</dependency>
69+
<dependency>
70+
<groupId>org.junit.jupiter</groupId>
71+
<artifactId>junit-jupiter</artifactId>
72+
<version>5.10.0</version>
73+
<scope>test</scope>
74+
</dependency>
75+
76+
77+
<dependency>
78+
<groupId>org.testcontainers</groupId>
79+
<artifactId>testcontainers</artifactId>
80+
<scope>test</scope>
81+
</dependency>
82+
<dependency>
83+
<groupId>org.testcontainers</groupId>
84+
<artifactId>junit-jupiter</artifactId>
85+
<scope>test</scope>
86+
</dependency>
87+
<dependency>
88+
<groupId>org.testcontainers</groupId>
89+
<artifactId>mysql</artifactId>
90+
<scope>test</scope>
91+
</dependency>
92+
<dependency>
93+
<groupId>io.kotest</groupId>
94+
<artifactId>kotest-runner-junit5-jvm</artifactId>
95+
<version>${kotest.version}</version>
96+
<scope>test</scope>
97+
</dependency>
98+
<dependency>
99+
<groupId>io.kotest</groupId>
100+
<artifactId>kotest-assertions-core-jvm</artifactId>
101+
<version>${kotest.version}</version>
102+
<scope>test</scope>
103+
</dependency>
104+
<dependency>
105+
<groupId>org.junit.jupiter</groupId>
106+
<artifactId>junit-jupiter-api</artifactId>
107+
<version>${junit.jupiter.version}</version>
108+
<scope>test</scope>
109+
</dependency>
110+
<dependency>
111+
<groupId>org.junit.vintage</groupId>
112+
<artifactId>junit-vintage-engine</artifactId>
113+
<version>${junit.vintage.version}</version>
114+
<scope>test</scope>
115+
</dependency>
116+
117+
<dependency>
118+
<groupId>org.junit.jupiter</groupId>
119+
<artifactId>junit-jupiter-engine</artifactId>
120+
<version>${junit.jupiter.version}</version>
121+
<scope>test</scope>
122+
</dependency>
123+
<dependency>
124+
<groupId>com.orbitalhq</groupId>
125+
<artifactId>taxiql-query-engine</artifactId>
126+
<version>${orbital.version}</version>
127+
<scope>test</scope>
128+
</dependency>
129+
<dependency>
130+
<groupId>com.orbitalhq</groupId>
131+
<artifactId>taxiql-query-engine</artifactId>
132+
<version>${orbital.version}</version>
133+
<scope>test</scope>
134+
<type>test-jar</type>
135+
</dependency>
136+
<dependency>
137+
<groupId>jakarta.persistence</groupId>
138+
<artifactId>jakarta.persistence-api</artifactId>
139+
<version>3.1.0</version>
140+
<scope>test</scope>
141+
</dependency>
142+
<dependency>
143+
<groupId>org.springframework.boot</groupId>
144+
<artifactId>spring-boot-test</artifactId>
145+
<scope>test</scope>
146+
</dependency>
147+
<dependency>
148+
<groupId>org.springframework.boot</groupId>
149+
<artifactId>spring-boot-starter-data-jpa</artifactId>
150+
<scope>test</scope>
151+
</dependency>
152+
<dependency>
153+
<groupId>org.springframework.boot</groupId>
154+
<artifactId>spring-boot-testcontainers</artifactId>
155+
<scope>test</scope>
156+
</dependency>
157+
</dependencies>
158+
159+
<build>
160+
<sourceDirectory>src/main/kotlin</sourceDirectory>
161+
<testSourceDirectory>src/test/kotlin</testSourceDirectory>
162+
<plugins>
163+
<plugin>
164+
<groupId>org.jetbrains.kotlin</groupId>
165+
<artifactId>kotlin-maven-plugin</artifactId>
166+
<version>${kotlin.version}</version>
167+
<configuration>
168+
<compilerPlugins>
169+
<plugin>jpa</plugin>
170+
<plugin>spring</plugin>
171+
</compilerPlugins>
172+
<args>
173+
<arg>-Xjsr305=strict</arg>
174+
</args>
175+
</configuration>
176+
<dependencies>
177+
<dependency>
178+
<groupId>org.jetbrains.kotlin</groupId>
179+
<artifactId>kotlin-maven-noarg</artifactId>
180+
<version>${kotlin.version}</version>
181+
</dependency>
182+
<dependency>
183+
<groupId>org.jetbrains.kotlin</groupId>
184+
<artifactId>kotlin-maven-allopen</artifactId>
185+
<version>${kotlin.version}</version>
186+
</dependency>
187+
</dependencies>
188+
<executions>
189+
<execution>
190+
<id>compile</id>
191+
<phase>compile</phase>
192+
<goals>
193+
<goal>compile</goal>
194+
</goals>
195+
</execution>
196+
<execution>
197+
<id>test-compile</id>
198+
<phase>test-compile</phase>
199+
<goals>
200+
<goal>test-compile</goal>
201+
</goals>
202+
</execution>
203+
</executions>
204+
</plugin>
205+
<plugin>
206+
<artifactId>maven-surefire-plugin</artifactId>
207+
<version>2.22.2</version>
208+
</plugin>
209+
<plugin>
210+
<artifactId>maven-failsafe-plugin</artifactId>
211+
<version>2.22.2</version>
212+
</plugin>
213+
</plugins>
214+
</build>
215+
216+
<dependencyManagement>
217+
<dependencies>
218+
<dependency>
219+
<groupId>org.testcontainers</groupId>
220+
<artifactId>testcontainers-bom</artifactId>
221+
<version>${testcontainers.version}</version>
222+
<type>pom</type>
223+
<scope>import</scope>
224+
</dependency>
225+
<dependency>
226+
<groupId>org.springframework.boot</groupId>
227+
<artifactId>spring-boot-dependencies</artifactId>
228+
<version>3.1.2</version>
229+
<type>pom</type>
230+
<scope>import</scope>
231+
</dependency>
232+
233+
</dependencies>
234+
</dependencyManagement>
235+
236+
<repositories>
237+
<!-- for orbital snapshots -->
238+
<repository>
239+
<id>orbital-snapshots</id>
240+
<url>https://repo.orbitalhq.com/snapshot</url>
241+
<snapshots>
242+
<enabled>true</enabled>
243+
</snapshots>
244+
</repository>
245+
<repository>
246+
<!-- for taxi snapshots -->
247+
<id>maven-central-snapshots</id>
248+
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
249+
<snapshots>
250+
<enabled>true</enabled>
251+
</snapshots>
252+
</repository>
253+
<repository>
254+
<id>vyne</id>
255+
<url>https://repo.orbitalhq.com/release</url>
256+
<snapshots>
257+
<enabled>false</enabled>
258+
</snapshots>
259+
</repository>
260+
<repository>
261+
<id>jooq-pro</id>
262+
<url>https://repo.jooq.org/repo</url>
263+
</repository>
264+
</repositories>
265+
<distributionManagement>
266+
<repository>
267+
<id>repo.orbitalhq.com</id>
268+
<url>s3://repo.orbitalhq.com/release</url>
269+
</repository>
270+
<snapshotRepository>
271+
<id>repo.orbitalhq.com</id>
272+
<url>s3://repo.orbitalhq.com/snapshot</url>
273+
</snapshotRepository>
274+
</distributionManagement>
275+
</project>
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package com.orbitalhq.connectors.jdbc.mysql
2+
3+
import com.orbitalhq.connectors.config.jdbc.DatabaseDriverName
4+
import com.orbitalhq.connectors.config.jdbc.JdbcMetadataParams
5+
import com.orbitalhq.connectors.config.jdbc.JdbcUrlBuilder
6+
import com.orbitalhq.connectors.jdbc.UpsertVerb
7+
import com.orbitalhq.connectors.jdbc.drivers.DatabaseDriverRegistry
8+
import com.orbitalhq.connectors.jdbc.drivers.DatabaseSupport
9+
import com.orbitalhq.connectors.jdbc.sql.dml.SqlOperation
10+
import com.orbitalhq.connectors.jdbc.sql.dml.SqlQuery
11+
import com.orbitalhq.schemas.AttributeName
12+
import org.jooq.DSLContext
13+
import org.jooq.Field
14+
import org.jooq.RowN
15+
import org.jooq.impl.DSL
16+
17+
/**
18+
* Documenting known issues:
19+
*
20+
* ## DDL
21+
* - When generating a table, if the column type is string, and the column is used in an index,
22+
* then the size must be set. We default to VARCHAR(255), which cannot be changed currently
23+
*
24+
* - MySQL doesn't support create index if not exists, so we've had to fall back to create index.
25+
* This means that the creation may fail if the index already exists
26+
*
27+
* ## DML
28+
* - MySQL (and therefore JOOQ) doesn't support UPDATE ... RETURNING syntaxes. This means on an
29+
* upsert, we are unable to find the id of the created entry (see related jOOQ issue)
30+
*/
31+
object MySqlDbSupport : DatabaseSupport{
32+
33+
fun register() {
34+
DatabaseSupport.register(MySqlDbSupport)
35+
}
36+
37+
override val driverName: DatabaseDriverName = "MYSQL"
38+
override val jdbcDriverMetadata = JdbcMetadataParams()
39+
override fun jdbcUrlBuilder(): JdbcUrlBuilder = MySqlJdbcUrlBuilder
40+
41+
override fun buildUpsertStatement(
42+
sql: DSLContext,
43+
actualTableName: String,
44+
sqlFields: List<Field<out Any>>,
45+
rows: List<RowN>,
46+
valuesAsMaps: List<Map<AttributeName, Any?>>,
47+
verb: UpsertVerb,
48+
primaryKeyFields: List<Field<out Any>>,
49+
generatedFields: List<Field<out Any>>
50+
): SqlOperation {
51+
// TODO : Support for explicit Insert / Update.
52+
// Currently verything is upsert
53+
54+
// Note:
55+
// MySQL (and therefore jOOQ) doesn't support UPDATE ... RETURNING.
56+
// As a result, currently when we do an UPSERT, we can get the affected row count,
57+
// but not the affected rows.
58+
// See: https://github.com/jOOQ/jOOQ/issues/6865
59+
val statement = sql.insertInto(DSL.table(DSL.name(actualTableName)), *sqlFields.toTypedArray())
60+
.valuesOfRows(*rows.toTypedArray())
61+
.let { insert ->
62+
if (primaryKeyFields.isNotEmpty()) {
63+
insert.onConflict(primaryKeyFields)
64+
.doUpdate().setAllToExcluded()
65+
// .returningResult(generatedFields)
66+
} else {
67+
insert
68+
// insert.returningResult(generatedFields)
69+
}
70+
}
71+
return SqlQuery(statement, returnsValues = false)
72+
}
73+
}

0 commit comments

Comments
 (0)