-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(user): added support for easier table schema interaction
- Loading branch information
1 parent
8fd4da3
commit 6b7a63d
Showing
17 changed files
with
372 additions
and
248 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
108 changes: 108 additions & 0 deletions
108
...count/deployment/src/main/java/dev/cloudeko/zenei/user/deployment/DefaultTableSchema.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,108 @@ | ||
package dev.cloudeko.zenei.user.deployment; | ||
|
||
import io.quarkus.deployment.Capabilities; | ||
import io.quarkus.deployment.Capability; | ||
|
||
import java.util.Arrays; | ||
import java.util.function.Function; | ||
|
||
public enum DefaultTableSchema { | ||
USER_ACCOUNT("zenei_user_account", UserAccountTableSchema::fromClient); | ||
|
||
private final String tableName; | ||
private final Function<Capabilities, TableSchema> schemaFunction; | ||
|
||
DefaultTableSchema(String tableName, Function<Capabilities, TableSchema> schemaFunction) { | ||
this.tableName = tableName; | ||
this.schemaFunction = schemaFunction; | ||
} | ||
|
||
public static TableSchema[] schemas(Capabilities capabilities) { | ||
return Arrays.stream(values()) | ||
.map(schema -> schema.getSchema(capabilities)) | ||
.toArray(TableSchema[]::new); | ||
} | ||
|
||
public String getTableName() { | ||
return tableName; | ||
} | ||
|
||
public TableSchema getSchema(Capabilities capabilities) { | ||
return schemaFunction.apply(capabilities); | ||
} | ||
|
||
public enum UserAccountTableSchema implements TableSchema { | ||
REACTIVE_PG_CLIENT(Capability.REACTIVE_PG_CLIENT, | ||
"CREATE TABLE IF NOT EXISTS zenei_user_account (" | ||
+ "id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, " | ||
+ "username VARCHAR(100) NOT NULL, " | ||
+ "image VARCHAR(1000) NULL, " | ||
+ "created_at TIMESTAMP NOT NULL, " | ||
+ "updated_at TIMESTAMP NOT NULL)", | ||
true), | ||
REACTIVE_MYSQL_CLIENT(Capability.REACTIVE_MYSQL_CLIENT, | ||
"CREATE TABLE IF NOT EXISTS zenei_user_account (" | ||
+ "id BIGINT AUTO_INCREMENT PRIMARY KEY, " | ||
+ "username VARCHAR(100) NOT NULL, " | ||
+ "image VARCHAR(1000) NULL, " | ||
+ "created_at TIMESTAMP NOT NULL, " | ||
+ "updated_at TIMESTAMP NOT NULL)", | ||
true), | ||
REACTIVE_MSSQL_CLIENT(Capability.REACTIVE_MSSQL_CLIENT, | ||
"CREATE TABLE zenei_user_account (" | ||
+ "id BIGINT IDENTITY(1,1) PRIMARY KEY, " | ||
+ "username NVARCHAR(100) NOT NULL, " | ||
+ "image NVARCHAR(1000) NULL, " | ||
+ "created_at DATETIME2 NOT NULL, " | ||
+ "updated_at DATETIME2 NOT NULL)", | ||
false), | ||
REACTIVE_DB2_CLIENT(Capability.REACTIVE_DB2_CLIENT, | ||
"CREATE TABLE zenei_user_account (" | ||
+ "id BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), " | ||
+ "username VARCHAR(100) NOT NULL, " | ||
+ "image VARCHAR(1000), " | ||
+ "created_at TIMESTAMP NOT NULL, " | ||
+ "updated_at TIMESTAMP NOT NULL, " | ||
+ "PRIMARY KEY (id))", | ||
false), | ||
REACTIVE_ORACLE_CLIENT(Capability.REACTIVE_ORACLE_CLIENT, | ||
"CREATE TABLE zenei_user_account (" | ||
+ "id NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, " | ||
+ "username VARCHAR2(100) NOT NULL, " | ||
+ "image VARCHAR2(1000), " | ||
+ "created_at TIMESTAMP NOT NULL, " | ||
+ "updated_at TIMESTAMP NOT NULL)", | ||
true); | ||
|
||
private final String client; | ||
private final String ddl; | ||
private final boolean supportsIfNotExists; | ||
|
||
UserAccountTableSchema(String client, String ddl, boolean supportsIfNotExists) { | ||
this.client = client; | ||
this.ddl = ddl; | ||
this.supportsIfNotExists = supportsIfNotExists; | ||
} | ||
|
||
public static UserAccountTableSchema fromClient(Capabilities capabilities) { | ||
for (UserAccountTableSchema schema : values()) { | ||
if (capabilities.isPresent(schema.client)) { | ||
return schema; | ||
} | ||
} | ||
throw new IllegalArgumentException("No table schema found for the given capabilities"); | ||
} | ||
|
||
public String getClient() { | ||
return client; | ||
} | ||
|
||
public String getDdl() { | ||
return ddl; | ||
} | ||
|
||
public boolean isSupportsIfNotExists() { | ||
return supportsIfNotExists; | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...user-account/deployment/src/main/java/dev/cloudeko/zenei/user/deployment/TableSchema.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,9 @@ | ||
package dev.cloudeko.zenei.user.deployment; | ||
|
||
public interface TableSchema { | ||
String getClient(); | ||
|
||
String getDdl(); | ||
|
||
boolean isSupportsIfNotExists(); | ||
} |
64 changes: 64 additions & 0 deletions
64
...ns/zenei-user-account/runtime/src/main/java/dev/cloudeko/zenei/user/BasicUserAccount.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,64 @@ | ||
package dev.cloudeko.zenei.user; | ||
|
||
import io.vertx.sqlclient.Row; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
public abstract class BasicUserAccount<ID> extends UserAccount<ID> { | ||
|
||
protected String username; | ||
|
||
private List<EmailAddress> emailAddresses; | ||
private List<PhoneNumber> phoneNumbers; | ||
|
||
public BasicUserAccount() { | ||
|
||
} | ||
|
||
public BasicUserAccount(String username) { | ||
this.username = username; | ||
} | ||
|
||
protected BasicUserAccount(ID id, LocalDateTime createdAt, LocalDateTime updatedAt) { | ||
super(id, createdAt, updatedAt); | ||
} | ||
|
||
public String getUsername() { | ||
return username; | ||
} | ||
|
||
public void setUsername(String username) { | ||
this.username = username; | ||
} | ||
|
||
public EmailAddress getPrimaryEmailAddress() { | ||
return emailAddresses.stream().filter(EmailAddress::primary).findFirst().orElse(null); | ||
} | ||
|
||
public List<EmailAddress> getEmailAddresses() { | ||
return emailAddresses; | ||
} | ||
|
||
public void setEmailAddresses(List<EmailAddress> emailAddresses) { | ||
this.emailAddresses = emailAddresses; | ||
} | ||
|
||
public PhoneNumber getPrimaryPhoneNumber() { | ||
return phoneNumbers.stream().filter(PhoneNumber::primary).findFirst().orElse(null); | ||
} | ||
|
||
public List<PhoneNumber> getPhoneNumbers() { | ||
return phoneNumbers; | ||
} | ||
|
||
public void setPhoneNumbers(List<PhoneNumber> phoneNumbers) { | ||
this.phoneNumbers = phoneNumbers; | ||
} | ||
|
||
public record EmailAddress(String email, boolean verified, boolean primary) { | ||
} | ||
|
||
public record PhoneNumber(String number, boolean verified, boolean primary) { | ||
} | ||
} |
Oops, something went wrong.