Skip to content

Commit c1cc144

Browse files
committed
Helidon Data basics example.
Signed-off-by: Tomáš Kraus <[email protected]>
1 parent 8aa90a4 commit c1cc144

File tree

10 files changed

+675
-0
lines changed

10 files changed

+675
-0
lines changed

examples/data/basics/pom.xml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright (c) 2025 Oracle and/or its affiliates.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
18+
-->
19+
20+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
22+
<modelVersion>4.0.0</modelVersion>
23+
<parent>
24+
<groupId>io.helidon.applications</groupId>
25+
<artifactId>helidon-se</artifactId>
26+
<version>4.3.0-SNAPSHOT</version>
27+
<relativePath/>
28+
</parent>
29+
<groupId>io.helidon.examples.data</groupId>
30+
<artifactId>helidon-examples-data-basics</artifactId>
31+
<version>1.0.0-SNAPSHOT</version>
32+
<name>Helidon Examples Data Repository Basics</name>
33+
34+
<description>
35+
The simplest example shows how to use Data Repository.
36+
</description>
37+
38+
<properties>
39+
<mainClass>io.helidon.examples.data.basics.Main</mainClass>
40+
</properties>
41+
42+
<dependencies>
43+
<dependency>
44+
<groupId>io.helidon.config</groupId>
45+
<artifactId>helidon-config-yaml</artifactId>
46+
</dependency>
47+
<dependency>
48+
<groupId>io.helidon.data</groupId>
49+
<artifactId>helidon-data</artifactId>
50+
</dependency>
51+
<dependency>
52+
<groupId>io.helidon.data.jakarta.persistence</groupId>
53+
<artifactId>helidon-data-jakarta-persistence</artifactId>
54+
</dependency>
55+
<dependency>
56+
<groupId>jakarta.persistence</groupId>
57+
<artifactId>jakarta.persistence-api</artifactId>
58+
</dependency>
59+
<dependency>
60+
<groupId>org.eclipse.persistence</groupId>
61+
<artifactId>org.eclipse.persistence.jpa</artifactId>
62+
<scope>runtime</scope>
63+
</dependency>
64+
<dependency>
65+
<groupId>org.eclipse.persistence</groupId>
66+
<artifactId>org.eclipse.persistence.core</artifactId>
67+
<scope>runtime</scope>
68+
</dependency>
69+
<dependency>
70+
<groupId>com.mysql</groupId>
71+
<artifactId>mysql-connector-j</artifactId>
72+
<scope>runtime</scope>
73+
</dependency>
74+
</dependencies>
75+
76+
<build>
77+
<plugins>
78+
<plugin>
79+
<groupId>org.apache.maven.plugins</groupId>
80+
<artifactId>maven-compiler-plugin</artifactId>
81+
<configuration>
82+
<annotationProcessorPaths>
83+
<path>
84+
<groupId>io.helidon.bundles</groupId>
85+
<artifactId>helidon-bundles-apt</artifactId>
86+
<version>${helidon.version}</version>
87+
</path>
88+
<path>
89+
<groupId>io.helidon.data.jakarta.persistence</groupId>
90+
<artifactId>helidon-data-jakarta-persistence-codegen</artifactId>
91+
<version>${helidon.version}</version>
92+
</path>
93+
</annotationProcessorPaths>
94+
</configuration>
95+
</plugin>
96+
97+
<plugin>
98+
<groupId>org.apache.maven.plugins</groupId>
99+
<artifactId>maven-dependency-plugin</artifactId>
100+
<executions>
101+
<execution>
102+
<id>copy-libs</id>
103+
</execution>
104+
</executions>
105+
</plugin>
106+
</plugins>
107+
</build>
108+
</project>
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright (c) 2025 Oracle and/or its affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.helidon.examples.data.basics.model;
17+
18+
import jakarta.persistence.Entity;
19+
import jakarta.persistence.Id;
20+
import jakarta.persistence.Table;
21+
22+
/**
23+
* A breed entity.
24+
*/
25+
@Entity
26+
@Table(name = "BREED")
27+
public class Breed {
28+
29+
@Id
30+
private int id;
31+
32+
private String name;
33+
34+
/**
35+
* Creates an instance of {@link Breed} class with the specified id and name.
36+
*
37+
* @param id the primary key of the breed
38+
* @param name the name of the breed
39+
*/
40+
public Breed(int id, String name) {
41+
this.id = id;
42+
this.name = name;
43+
}
44+
45+
/**
46+
* Creates a default instance of {@link Breed} class with id set to {@code -1}
47+
* and name set to {@code null}.
48+
*/
49+
public Breed() {
50+
this(-1, null);
51+
}
52+
53+
/**
54+
* Returns the primary key of this {@link Breed}.
55+
*
56+
* @return the primary key
57+
*/
58+
public int getId() {
59+
return id;
60+
}
61+
62+
/**
63+
* Sets the primary key of this {@link Breed}.
64+
*
65+
* @param id the new primary key
66+
*/
67+
public void setId(int id) {
68+
this.id = id;
69+
}
70+
71+
/**
72+
* Returns the name of this {@link Breed}.
73+
*
74+
* @return the name of the breed
75+
*/
76+
public String getName() {
77+
return name;
78+
}
79+
80+
/**
81+
* Sets the name of this {@link Breed}.
82+
*
83+
* @param name the new name of the breed
84+
*/
85+
public void setName(String name) {
86+
this.name = name;
87+
}
88+
89+
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Copyright (c) 2025 Oracle and/or its affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.helidon.examples.data.basics.model;
17+
18+
import java.util.List;
19+
20+
import jakarta.persistence.Entity;
21+
import jakarta.persistence.FetchType;
22+
import jakarta.persistence.Id;
23+
import jakarta.persistence.OneToMany;
24+
import jakarta.persistence.Table;
25+
26+
/**
27+
* An owner entity.
28+
*/
29+
@Entity
30+
@Table(name = "OWNER")
31+
public class Owner {
32+
33+
@Id
34+
private int id;
35+
36+
private String name;
37+
38+
@OneToMany(mappedBy = "owner", fetch = FetchType.LAZY)
39+
private List<Pet> pets;
40+
41+
/**
42+
* Creates an instance of {@link Owner} class with the specified id and name.
43+
*
44+
* @param id the primary key of the owner
45+
* @param name the name of the owner
46+
*/
47+
public Owner(int id, String name) {
48+
this.id = id;
49+
this.name = name;
50+
}
51+
52+
/**
53+
* Creates a default instance of {@link Owner} class with id set to {@code -1}
54+
* and name set to {@code null}.
55+
*/
56+
public Owner() {
57+
this(-1, null);
58+
}
59+
60+
/**
61+
* Returns the primary key of this {@link Owner}.
62+
*
63+
* @return the primary key
64+
*/
65+
public int getId() {
66+
return id;
67+
}
68+
69+
/**
70+
* Sets the primary key of this {@link Owner}.
71+
*
72+
* @param id the new primary key
73+
*/
74+
public void setId(int id) {
75+
this.id = id;
76+
}
77+
78+
/**
79+
* Returns the name of this {@link Owner}.
80+
*
81+
* @return the name of the owner
82+
*/
83+
public String getName() {
84+
return name;
85+
}
86+
87+
/**
88+
* Sets the name of this {@link Owner}.
89+
*
90+
* @param name the new name of the owner
91+
*/
92+
public void setName(String name) {
93+
this.name = name;
94+
}
95+
96+
/**
97+
* Returns the list of {@link Pet}s owned by this owner {@link Owner}.
98+
*
99+
* @return the list of pets owned by this owner
100+
*/
101+
public List<Pet> getPets() {
102+
return pets;
103+
}
104+
105+
/**
106+
* Sets the list of {@link Pet}s owned by this {@link Owner}.
107+
* <p>
108+
* Note that this method does not update the {@link Owner} reference in the {@link Pet} objects.
109+
* To establish a bidirectional relationship, you should also call {@link Pet#setOwner(Owner)} on each pet.
110+
*
111+
* @param pets the new list of pets
112+
*/
113+
public void setPets(List<Pet> pets) {
114+
this.pets = pets;
115+
}
116+
117+
}

0 commit comments

Comments
 (0)