-
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: return document database again
Signed-off-by: Otavio Santana <otaviopolianasantana@gmail.com>
- Loading branch information
1 parent
5997aa6
commit 39ce68b
Showing
4 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/main/java/org/soujava/demos/arangodb/document/AWSCloudProvider.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,42 @@ | ||
package org.soujava.demos.arangodb.document; | ||
|
||
import jakarta.nosql.Column; | ||
import jakarta.nosql.DiscriminatorValue; | ||
import jakarta.nosql.Entity; | ||
import net.datafaker.Faker; | ||
|
||
import java.util.UUID; | ||
|
||
@Entity | ||
@DiscriminatorValue("AWS") | ||
public class AWSCloudProvider extends CloudProvider { | ||
|
||
|
||
@Column | ||
private String accountId; | ||
|
||
public String getAccountId() { | ||
return accountId; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "AWSCloudProvider{" + | ||
"accountId='" + accountId + '\'' + | ||
", id='" + id + '\'' + | ||
", region='" + region + '\'' + | ||
'}'; | ||
} | ||
|
||
public static AWSCloudProvider of(Faker faker) { | ||
var aws = faker.aws(); | ||
var cloudProvider = new AWSCloudProvider(); | ||
cloudProvider.region = aws.region(); | ||
cloudProvider.region = aws.region(); | ||
cloudProvider.id = UUID.randomUUID().toString(); | ||
cloudProvider.accountId = aws.accountId(); | ||
return cloudProvider; | ||
} | ||
|
||
|
||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/org/soujava/demos/arangodb/document/App.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,43 @@ | ||
/* | ||
* Copyright (c) 2022 Contributors to the Eclipse Foundation | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Apache License v2.0 which accompanies this distribution. | ||
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html | ||
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. | ||
* | ||
* You may elect to redistribute this code under either of these licenses. | ||
*/ | ||
|
||
package org.soujava.demos.arangodb.document; | ||
|
||
|
||
import jakarta.enterprise.inject.se.SeContainer; | ||
import jakarta.enterprise.inject.se.SeContainerInitializer; | ||
import net.datafaker.Faker; | ||
import org.eclipse.jnosql.mapping.document.DocumentTemplate; | ||
|
||
import java.util.List; | ||
import java.util.logging.Logger; | ||
|
||
|
||
public class App { | ||
|
||
private static final Logger LOGGER = Logger.getLogger(App.class.getName()); | ||
|
||
public static void main(String[] args) { | ||
var faker = new Faker(); | ||
LOGGER.info("Starting the application"); | ||
try (SeContainer container = SeContainerInitializer.newInstance().initialize()) { | ||
var template = container.select(DocumentTemplate.class).get(); | ||
LOGGER.info("Creating 10 documents"); | ||
for (int index = 0; index < 5; index++) { | ||
template.insert(List.of(AWSCloudProvider.of(faker), AzureCloudProvider.of(faker))); | ||
} | ||
template.select(CloudProvider.class).stream().forEach(System.out::println); | ||
} | ||
} | ||
|
||
private App() { | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/org/soujava/demos/arangodb/document/AzureCloudProvider.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,40 @@ | ||
package org.soujava.demos.arangodb.document; | ||
|
||
import jakarta.nosql.Column; | ||
import jakarta.nosql.DiscriminatorValue; | ||
import jakarta.nosql.Entity; | ||
import net.datafaker.Faker; | ||
|
||
import java.util.UUID; | ||
|
||
@Entity | ||
@DiscriminatorValue("AZURE") | ||
public class AzureCloudProvider extends CloudProvider { | ||
|
||
|
||
@Column | ||
private String tenantId; | ||
|
||
public String getTenantId() { | ||
return tenantId; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "AzureCloudProvider{" + | ||
"tenantId='" + tenantId + '\'' + | ||
", id='" + id + '\'' + | ||
", region='" + region + '\'' + | ||
'}'; | ||
} | ||
|
||
public static AzureCloudProvider of(Faker faker) { | ||
var azure = faker.azure(); | ||
var cloudProvider = new AzureCloudProvider(); | ||
cloudProvider.region = azure.region(); | ||
cloudProvider.region = azure.region(); | ||
cloudProvider.id = UUID.randomUUID().toString(); | ||
cloudProvider.tenantId = azure.tenantId(); | ||
return cloudProvider; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/org/soujava/demos/arangodb/document/CloudProvider.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,36 @@ | ||
package org.soujava.demos.arangodb.document; | ||
|
||
import jakarta.nosql.Column; | ||
import jakarta.nosql.DiscriminatorColumn; | ||
import jakarta.nosql.Entity; | ||
import jakarta.nosql.Id; | ||
import jakarta.nosql.Inheritance; | ||
|
||
import java.util.Objects; | ||
|
||
@Entity | ||
@Inheritance | ||
@DiscriminatorColumn("type") | ||
public class CloudProvider { | ||
|
||
@Id | ||
protected String id; | ||
|
||
@Column | ||
protected String region; | ||
|
||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
CloudProvider that = (CloudProvider) o; | ||
return Objects.equals(id, that.id); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(id); | ||
} | ||
} |