forked from spring-projects/spring-boot
-
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.
Showing
15 changed files
with
604 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<!-- Your own application should inherit from spring-boot-starter-parent --> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-samples</artifactId> | ||
<version>1.2.0.BUILD-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>spring-boot-sample-jpa</artifactId> | ||
<name>Spring Boot JPA Sample</name> | ||
<description>Spring Boot JPA Sample</description> | ||
<url>http://projects.spring.io/spring-boot/</url> | ||
<organization> | ||
<name>Pivotal Software, Inc.</name> | ||
<url>http://www.spring.io</url> | ||
</organization> | ||
<properties> | ||
<main.basedir>${basedir}/../..</main.basedir> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-freemarker</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hibernate</groupId> | ||
<artifactId>hibernate-entitymanager</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hsqldb</groupId> | ||
<artifactId>hsqldb</artifactId> | ||
<scope>runtime</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-orm</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
29 changes: 29 additions & 0 deletions
29
...ng-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/SampleJpaApplication.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,29 @@ | ||
/* | ||
* Copyright 2012-2014 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package sample.jpa; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class SampleJpaApplication { | ||
|
||
public static void main(String[] args) throws Exception { | ||
SpringApplication.run(SampleJpaApplication.class, args); | ||
} | ||
|
||
} |
73 changes: 73 additions & 0 deletions
73
spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/domain/Note.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,73 @@ | ||
/* | ||
* Copyright 2012-2014 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package sample.jpa.domain; | ||
|
||
import java.util.List; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.ManyToMany; | ||
|
||
@Entity | ||
public class Note { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
private long id; | ||
|
||
private String title; | ||
|
||
private String body; | ||
|
||
@ManyToMany | ||
private List<Tag> tags; | ||
|
||
public long getId() { | ||
return this.id; | ||
} | ||
|
||
public void setId(long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getTitle() { | ||
return this.title; | ||
} | ||
|
||
public void setTitle(String title) { | ||
this.title = title; | ||
} | ||
|
||
public String getBody() { | ||
return this.body; | ||
} | ||
|
||
public void setBody(String body) { | ||
this.body = body; | ||
} | ||
|
||
public List<Tag> getTags() { | ||
return this.tags; | ||
} | ||
|
||
public void setTags(List<Tag> tags) { | ||
this.tags = tags; | ||
} | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/domain/Tag.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,63 @@ | ||
/* | ||
* Copyright 2012-2014 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package sample.jpa.domain; | ||
|
||
import java.util.List; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.ManyToMany; | ||
|
||
@Entity | ||
public class Tag { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
private long id; | ||
|
||
private String name; | ||
|
||
@ManyToMany(mappedBy = "tags") | ||
private List<Note> notes; | ||
|
||
public long getId() { | ||
return this.id; | ||
} | ||
|
||
public void setId(long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return this.name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public List<Note> getNotes() { | ||
return this.notes; | ||
} | ||
|
||
public void setNotes(List<Note> notes) { | ||
this.notes = notes; | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
...samples/spring-boot-sample-jpa/src/main/java/sample/jpa/repository/JpaNoteRepository.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 @@ | ||
/* | ||
* Copyright 2012-2014 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package sample.jpa.repository; | ||
|
||
import java.util.List; | ||
|
||
import javax.persistence.EntityManager; | ||
import javax.persistence.PersistenceContext; | ||
|
||
import org.springframework.stereotype.Repository; | ||
|
||
import sample.jpa.domain.Note; | ||
|
||
@Repository | ||
class JpaNoteRepository implements NoteRepository { | ||
|
||
@PersistenceContext | ||
private EntityManager entityManager; | ||
|
||
@Override | ||
public List<Note> findAll() { | ||
return this.entityManager.createQuery("SELECT n FROM Note n", Note.class) | ||
.getResultList(); | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
...-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/repository/JpaTagRepository.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 @@ | ||
/* | ||
* Copyright 2012-2014 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package sample.jpa.repository; | ||
|
||
import java.util.List; | ||
|
||
import javax.persistence.EntityManager; | ||
import javax.persistence.PersistenceContext; | ||
|
||
import org.springframework.stereotype.Repository; | ||
|
||
import sample.jpa.domain.Tag; | ||
|
||
@Repository | ||
class JpaTagRepository implements TagRepository { | ||
|
||
@PersistenceContext | ||
private EntityManager entityManager; | ||
|
||
@Override | ||
public List<Tag> findAll() { | ||
return this.entityManager.createQuery("SELECT t FROM Tag t", Tag.class) | ||
.getResultList(); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
...ot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/repository/NoteRepository.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,27 @@ | ||
/* | ||
* Copyright 2012-2014 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package sample.jpa.repository; | ||
|
||
import java.util.List; | ||
|
||
import sample.jpa.domain.Note; | ||
|
||
public interface NoteRepository { | ||
|
||
List<Note> findAll(); | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
...oot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/repository/TagRepository.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,27 @@ | ||
/* | ||
* Copyright 2012-2014 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package sample.jpa.repository; | ||
|
||
import java.util.List; | ||
|
||
import sample.jpa.domain.Tag; | ||
|
||
public interface TagRepository { | ||
|
||
List<Tag> findAll(); | ||
|
||
} |
Oops, something went wrong.