Skip to content

Commit 39ce68b

Browse files
committed
feat: return document database again
Signed-off-by: Otavio Santana <[email protected]>
1 parent 5997aa6 commit 39ce68b

File tree

4 files changed

+161
-0
lines changed

4 files changed

+161
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package org.soujava.demos.arangodb.document;
2+
3+
import jakarta.nosql.Column;
4+
import jakarta.nosql.DiscriminatorValue;
5+
import jakarta.nosql.Entity;
6+
import net.datafaker.Faker;
7+
8+
import java.util.UUID;
9+
10+
@Entity
11+
@DiscriminatorValue("AWS")
12+
public class AWSCloudProvider extends CloudProvider {
13+
14+
15+
@Column
16+
private String accountId;
17+
18+
public String getAccountId() {
19+
return accountId;
20+
}
21+
22+
@Override
23+
public String toString() {
24+
return "AWSCloudProvider{" +
25+
"accountId='" + accountId + '\'' +
26+
", id='" + id + '\'' +
27+
", region='" + region + '\'' +
28+
'}';
29+
}
30+
31+
public static AWSCloudProvider of(Faker faker) {
32+
var aws = faker.aws();
33+
var cloudProvider = new AWSCloudProvider();
34+
cloudProvider.region = aws.region();
35+
cloudProvider.region = aws.region();
36+
cloudProvider.id = UUID.randomUUID().toString();
37+
cloudProvider.accountId = aws.accountId();
38+
return cloudProvider;
39+
}
40+
41+
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2022 Contributors to the Eclipse Foundation
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* and Apache License v2.0 which accompanies this distribution.
6+
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7+
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
8+
*
9+
* You may elect to redistribute this code under either of these licenses.
10+
*/
11+
12+
package org.soujava.demos.arangodb.document;
13+
14+
15+
import jakarta.enterprise.inject.se.SeContainer;
16+
import jakarta.enterprise.inject.se.SeContainerInitializer;
17+
import net.datafaker.Faker;
18+
import org.eclipse.jnosql.mapping.document.DocumentTemplate;
19+
20+
import java.util.List;
21+
import java.util.logging.Logger;
22+
23+
24+
public class App {
25+
26+
private static final Logger LOGGER = Logger.getLogger(App.class.getName());
27+
28+
public static void main(String[] args) {
29+
var faker = new Faker();
30+
LOGGER.info("Starting the application");
31+
try (SeContainer container = SeContainerInitializer.newInstance().initialize()) {
32+
var template = container.select(DocumentTemplate.class).get();
33+
LOGGER.info("Creating 10 documents");
34+
for (int index = 0; index < 5; index++) {
35+
template.insert(List.of(AWSCloudProvider.of(faker), AzureCloudProvider.of(faker)));
36+
}
37+
template.select(CloudProvider.class).stream().forEach(System.out::println);
38+
}
39+
}
40+
41+
private App() {
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package org.soujava.demos.arangodb.document;
2+
3+
import jakarta.nosql.Column;
4+
import jakarta.nosql.DiscriminatorValue;
5+
import jakarta.nosql.Entity;
6+
import net.datafaker.Faker;
7+
8+
import java.util.UUID;
9+
10+
@Entity
11+
@DiscriminatorValue("AZURE")
12+
public class AzureCloudProvider extends CloudProvider {
13+
14+
15+
@Column
16+
private String tenantId;
17+
18+
public String getTenantId() {
19+
return tenantId;
20+
}
21+
22+
@Override
23+
public String toString() {
24+
return "AzureCloudProvider{" +
25+
"tenantId='" + tenantId + '\'' +
26+
", id='" + id + '\'' +
27+
", region='" + region + '\'' +
28+
'}';
29+
}
30+
31+
public static AzureCloudProvider of(Faker faker) {
32+
var azure = faker.azure();
33+
var cloudProvider = new AzureCloudProvider();
34+
cloudProvider.region = azure.region();
35+
cloudProvider.region = azure.region();
36+
cloudProvider.id = UUID.randomUUID().toString();
37+
cloudProvider.tenantId = azure.tenantId();
38+
return cloudProvider;
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.soujava.demos.arangodb.document;
2+
3+
import jakarta.nosql.Column;
4+
import jakarta.nosql.DiscriminatorColumn;
5+
import jakarta.nosql.Entity;
6+
import jakarta.nosql.Id;
7+
import jakarta.nosql.Inheritance;
8+
9+
import java.util.Objects;
10+
11+
@Entity
12+
@Inheritance
13+
@DiscriminatorColumn("type")
14+
public class CloudProvider {
15+
16+
@Id
17+
protected String id;
18+
19+
@Column
20+
protected String region;
21+
22+
23+
@Override
24+
public boolean equals(Object o) {
25+
if (o == null || getClass() != o.getClass()) {
26+
return false;
27+
}
28+
CloudProvider that = (CloudProvider) o;
29+
return Objects.equals(id, that.id);
30+
}
31+
32+
@Override
33+
public int hashCode() {
34+
return Objects.hashCode(id);
35+
}
36+
}

0 commit comments

Comments
 (0)