generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: declarative JVM databases (#4161)
- Loading branch information
1 parent
c589e41
commit 8191669
Showing
11 changed files
with
173 additions
and
50 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
2 changes: 0 additions & 2 deletions
2
backend/controller/sql/testdata/java/database/src/main/resources/application.properties
This file was deleted.
Oops, something went wrong.
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
2 changes: 0 additions & 2 deletions
2
backend/controller/sql/testdata/java/mysql/src/main/resources/application.properties
This file was deleted.
Oops, something went wrong.
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
56 changes: 56 additions & 0 deletions
56
...untime/common/deployment/src/main/java/xyz/block/ftl/deployment/DatabaseConfigSource.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,56 @@ | ||
package xyz.block.ftl.deployment; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
import java.util.Set; | ||
|
||
import org.eclipse.microprofile.config.spi.ConfigSource; | ||
|
||
public class DatabaseConfigSource implements ConfigSource { | ||
|
||
private final Map<String, String> properties; | ||
|
||
public DatabaseConfigSource() { | ||
properties = new HashMap<>(); | ||
var ds = Thread.currentThread().getContextClassLoader().getResourceAsStream("META-INF/ftl-sql-databases.txt"); | ||
if (ds == null) { | ||
return; | ||
} | ||
try (var in = ds) { | ||
Properties p = new Properties(); | ||
p.load(in); | ||
for (var name : p.stringPropertyNames()) { | ||
properties.put("quarkus.datasource." + name + ".db-kind", p.getProperty(name)); | ||
} | ||
if (properties.size() == 1) { | ||
try { | ||
// Temporary implicit support for hibernate orm | ||
Thread.currentThread().getContextClassLoader() | ||
.loadClass("io.quarkus.hibernate.orm.runtime.HibernateOrmRecorder"); | ||
properties.put("quarkus.hibernate-orm.datasource", p.entrySet().iterator().next().getKey().toString()); | ||
} catch (ClassNotFoundException ignore) { | ||
|
||
} | ||
} | ||
} catch (Exception e) { | ||
throw new RuntimeException("Failed to load database properties", e); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public Set<String> getPropertyNames() { | ||
return properties.keySet(); | ||
} | ||
|
||
@Override | ||
public String getValue(String propertyName) { | ||
return properties.get(propertyName); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "FTL Database Config Source"; | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
...ent/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
xyz.block.ftl.deployment.StaticConfigSource | ||
xyz.block.ftl.deployment.StaticConfigSource | ||
xyz.block.ftl.deployment.DatabaseConfigSource |
6 changes: 6 additions & 0 deletions
6
jvm-runtime/ftl-runtime/common/runtime/src/main/java/xyz/block/ftl/SQLDatabaseType.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,6 @@ | ||
package xyz.block.ftl; | ||
|
||
public enum SQLDatabaseType { | ||
MYSQL, | ||
POSTGRESQL, | ||
} |
32 changes: 32 additions & 0 deletions
32
jvm-runtime/ftl-runtime/common/runtime/src/main/java/xyz/block/ftl/SQLDatasource.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,32 @@ | ||
package xyz.block.ftl; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Annotation to specify a SQL datasource. | ||
* | ||
* This can be added anywhere in your application, but it is recommended to add it to a package-info.java file | ||
* at the root of your package hierarchy. | ||
* | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ ElementType.PACKAGE, ElementType.TYPE }) | ||
public @interface SQLDatasource { | ||
/** | ||
* The name of the datasource. | ||
* | ||
* @return the name of the datasource | ||
*/ | ||
String name(); | ||
|
||
/** | ||
* The type of the SQL database. | ||
* | ||
* @return the type of the SQL database | ||
*/ | ||
SQLDatabaseType type(); | ||
|
||
} |
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