Spring JPA: renaming packages
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 3 Jul 2016 15:46:47 +0000 (17:46 +0200)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 3 Jul 2016 15:46:47 +0000 (17:46 +0200)
14 files changed:
SpringJava/JPA/src/main/java/de/spring/example/persistence/converters/OffsetDateTimeAttributeConverter.java [new file with mode: 0644]
SpringJava/JPA/src/main/java/de/spring/example/persistence/domain/Ad.java [new file with mode: 0644]
SpringJava/JPA/src/main/java/de/spring/example/persistence/domain/AdDescription.java [new file with mode: 0644]
SpringJava/JPA/src/main/java/de/spring/example/persistence/repository/AdDescriptionRepository.java [new file with mode: 0644]
SpringJava/JPA/src/main/java/de/spring/example/persistence/repository/AdRepository.java [new file with mode: 0644]
SpringJava/JPA/src/main/java/de/spring/example/rest/controllers/AdController.java [new file with mode: 0644]
SpringJava/JPA/src/main/java/de/spring/persistence/converters/OffsetDateTimeAttributeConverter.java [deleted file]
SpringJava/JPA/src/main/java/de/spring/persistence/example/domain/Ad.java [deleted file]
SpringJava/JPA/src/main/java/de/spring/persistence/example/domain/AdDescription.java [deleted file]
SpringJava/JPA/src/main/java/de/spring/persistence/example/repository/AdDescriptionRepository.java [deleted file]
SpringJava/JPA/src/main/java/de/spring/persistence/example/repository/AdRepository.java [deleted file]
SpringJava/JPA/src/main/java/de/spring/rest/controllers/AdController.java [deleted file]
SpringJava/JPA/src/main/resources/spring-configuration/jpa-configuration.xml
SpringJava/JPA/src/main/resources/spring-configuration/mvc/rest/rest-config.xml

diff --git a/SpringJava/JPA/src/main/java/de/spring/example/persistence/converters/OffsetDateTimeAttributeConverter.java b/SpringJava/JPA/src/main/java/de/spring/example/persistence/converters/OffsetDateTimeAttributeConverter.java
new file mode 100644 (file)
index 0000000..30ab6bb
--- /dev/null
@@ -0,0 +1,39 @@
+package de.spring.example.persistence.converters;
+
+import java.sql.Timestamp;
+import java.time.LocalDateTime;
+import java.time.OffsetDateTime;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
+
+import javax.persistence.AttributeConverter;
+import javax.persistence.Converter;
+
+@Converter(autoApply = true)
+public class OffsetDateTimeAttributeConverter implements AttributeConverter<OffsetDateTime, Timestamp> {
+
+       @Override
+       public Timestamp convertToDatabaseColumn(OffsetDateTime offsetDateTime) {
+               Timestamp timestamp = null;
+               
+               if (offsetDateTime != null) {
+                       timestamp = Timestamp.valueOf(offsetDateTime.toLocalDateTime());
+               }
+               
+               return timestamp;
+       }
+
+       @Override
+       public OffsetDateTime convertToEntityAttribute(Timestamp sqlTimestamp) {
+               OffsetDateTime offsetDateTime = null;
+               
+               if (sqlTimestamp != null) {
+                       final LocalDateTime localDateTime = sqlTimestamp.toLocalDateTime();
+                       final ZonedDateTime zonedDateTime = localDateTime.atZone(ZoneId.systemDefault());
+                       offsetDateTime = zonedDateTime.toOffsetDateTime();
+               }
+               
+               return offsetDateTime;
+       }
+
+}
diff --git a/SpringJava/JPA/src/main/java/de/spring/example/persistence/domain/Ad.java b/SpringJava/JPA/src/main/java/de/spring/example/persistence/domain/Ad.java
new file mode 100644 (file)
index 0000000..5ef5871
--- /dev/null
@@ -0,0 +1,131 @@
+package de.spring.example.persistence.domain;
+
+import java.io.Serializable;
+import java.time.OffsetDateTime;
+import java.util.Set;
+
+import javax.persistence.Column;
+import javax.persistence.Convert;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+//import javax.persistence.NamedNativeQueries;
+//import javax.persistence.NamedNativeQuery;
+//import javax.persistence.NamedQueries;
+//import javax.persistence.NamedQuery;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+import javax.validation.constraints.Max;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+
+import de.spring.example.persistence.converters.OffsetDateTimeAttributeConverter;
+
+@Entity
+@Table(name="ad", schema="mybatis_example")
+// 1. Named query is JPL. It is portable.
+// 2. Instead of annotating the domain class we should be using @Query annotation at the query method
+//    because it should be cleaner :)
+//    So you'd better use @Query.
+//http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods.at-query
+//See: de.spring.persistence.example.repository.AdRepository 
+//@NamedQueries(
+//             {
+//                     @NamedQuery(
+//                     name="Ad.findByIdQuery",
+//                     query="select a from Ad a where a.id = :id)
+//             }
+//     
+//)
+// 1. Native query IS NOT JPL. It is not portable and it is written directly in the native language
+//    of the store. We can use special features at the cost of portability.
+// 2. Instead of annotating the domain class we should be using @Query annotation at the query method
+//       because it should be cleaner :)
+//    So you'd better use @Query.
+//    http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods.at-query
+//    See: de.spring.persistence.example.repository.AdRepository 
+//@NamedNativeQueries(
+//     {
+//             @NamedNativeQuery(
+//                     name="Ad.findByIdNativeQuery",
+//                     query="SELECT * FROM ad WHERE ad.id = :id",
+//                     resultClass=Ad.class)
+//     }               
+//)
+public class Ad implements Serializable {
+
+       @Id
+       @GeneratedValue(strategy=GenerationType.IDENTITY)
+       @Column(name="id", updatable=false, nullable=false)
+       private Long id;
+       
+       @OneToMany(mappedBy="ad", fetch=FetchType.LAZY, targetEntity=AdDescription.class)
+       private Set<AdDescription> adDescriptions;
+       
+       @Max(60)
+       @Column(name="company_id")
+       private Long companyId;
+       
+       @Max(40)
+       @Column(name="company_categ_id")
+       private Long companyCategId;
+       
+       @Size(min=2, max=255)
+       @Column(name="ad_mobile_image")
+       private String adMobileImage;
+
+       @NotNull
+       @Convert(converter=OffsetDateTimeAttributeConverter.class)
+       @Column(name="created_at", nullable=false)
+       @JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ssZ")
+       private OffsetDateTime createdAt;
+       
+       @NotNull
+       @Convert(converter=OffsetDateTimeAttributeConverter.class)
+       @Column(name="updated_at", nullable = false)
+       @JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ssZ")
+       private OffsetDateTime updatedAt;
+
+       // It will be used by JPA when filling the property fields with data coming from data base.
+       protected Ad() {
+
+       }
+
+       // It will be used by my code (for example by Unit Tests)
+       public Ad(Long id, Long companyId, Long companyCategId, String adMobileImage, OffsetDateTime createdAt,
+                       OffsetDateTime updatedAt) {
+               this.id = id;
+               this.companyCategId = companyCategId;
+               this.adMobileImage = adMobileImage;
+               this.createdAt = createdAt;
+               this.updatedAt = updatedAt;
+       }
+
+       public Long getId() {
+               return id;
+       }
+
+       public Long getCompanyId() {
+               return companyId;
+       }
+
+       public Long getCompanyCategId() {
+               return companyCategId;
+       }
+
+       public String getAdMobileImage() {
+               return adMobileImage;
+       }
+
+       public OffsetDateTime getCreatedAt() {
+               return createdAt;
+       }
+
+       public OffsetDateTime getUpdatedAt() {
+               return updatedAt;
+       }
+}
diff --git a/SpringJava/JPA/src/main/java/de/spring/example/persistence/domain/AdDescription.java b/SpringJava/JPA/src/main/java/de/spring/example/persistence/domain/AdDescription.java
new file mode 100644 (file)
index 0000000..9a65407
--- /dev/null
@@ -0,0 +1,102 @@
+package de.spring.example.persistence.domain;
+
+import java.io.Serializable;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+import javax.validation.constraints.Max;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+import de.spring.example.persistence.domain.Ad;
+
+@Entity
+@Table(name="ad_description", schema="mybatis_example")
+public class AdDescription implements Serializable {
+
+       @Id
+       @GeneratedValue(strategy=GenerationType.IDENTITY)
+       @Column(name="id", updatable=false, nullable=false)
+       private Long id;
+       
+       @NotNull
+       @ManyToOne(optional=false)
+       @JoinColumn(name="ad_id", referencedColumnName="id")
+       private Ad ad;
+       
+       @NotNull
+       @Max(60)
+       @Column(name="language_id")
+       private Long languageId;
+       
+       @NotNull
+       @Size(min=2, max=255)
+       @Column(name="ad_name")
+       private String adName;
+
+       @NotNull
+       @Size(min=2, max=255)
+       @Column(name="ad_description")
+       private String adDescription;
+       
+       @NotNull
+       @Size(min=2, max=500)
+       @Column(name="ad_mobile_text")
+       private String adMobileText;
+       
+       @NotNull
+       @Size(min=2, max=3000)
+       @Column(name="ad_link")
+       private String adLink;
+       
+       // It will be used by JPA when filling the property fields with data coming from data base.
+       protected AdDescription() {
+
+       }
+
+       // It will be used by my code (for example by Unit Tests)
+       public AdDescription(Long id, Ad ad, Long languageId, String adName, String adDescription,
+                       String adMobileText, String adLink) {
+               this.id = id;
+               this.languageId = languageId;
+               this.ad = ad;
+               this.adName = adName;
+               this.adDescription = adDescription;
+               this.adMobileText = adMobileText;
+               this.adLink = adLink;
+       }
+
+       public Long getId() {
+               return id;
+       }
+
+       public Ad getAd() {
+               return ad;
+       }
+
+       public Long getLanguageId() {
+               return languageId;
+       }
+
+       public String getAdName() {
+               return adName;
+       }
+
+       public String getAdDescription() {
+               return adDescription;
+       }
+
+       public String getAdMobileText() {
+               return adMobileText;
+       }
+
+       public String getAdLink() {
+               return adLink;
+       }
+}
diff --git a/SpringJava/JPA/src/main/java/de/spring/example/persistence/repository/AdDescriptionRepository.java b/SpringJava/JPA/src/main/java/de/spring/example/persistence/repository/AdDescriptionRepository.java
new file mode 100644 (file)
index 0000000..8116883
--- /dev/null
@@ -0,0 +1,14 @@
+package de.spring.example.persistence.repository;
+
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.repository.PagingAndSortingRepository;
+
+import de.spring.example.persistence.domain.Ad;
+import de.spring.example.persistence.domain.AdDescription;
+
+public interface AdDescriptionRepository extends PagingAndSortingRepository<AdDescription, Long> {
+
+       // Custom Query method
+       Page<AdDescription> findByAd(Ad ad, Pageable pageable);
+}
diff --git a/SpringJava/JPA/src/main/java/de/spring/example/persistence/repository/AdRepository.java b/SpringJava/JPA/src/main/java/de/spring/example/persistence/repository/AdRepository.java
new file mode 100644 (file)
index 0000000..a9b204f
--- /dev/null
@@ -0,0 +1,20 @@
+package de.spring.example.persistence.repository;
+
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.PagingAndSortingRepository;
+import org.springframework.data.repository.query.Param;
+
+import de.spring.example.persistence.domain.Ad;
+
+public interface AdRepository extends PagingAndSortingRepository<Ad, Long> {
+       
+       // Named Native Query (using the native language of the store) It is not portable.
+       // See de.spring.persistence.example.domain.Ad
+       @Query(value="SELECT * FROM ad WHERE ad.id = :id", nativeQuery=true)
+       Ad findByIdNativeQuery(@Param("id") Long id);
+       
+       // Named Query (using JPL) It is portable.
+       // See de.spring.persistence.example.domain.Ad
+       @Query("select a from Ad a where a.id = :id")
+       Ad findByIdQuery(@Param("id") Long id);
+}
diff --git a/SpringJava/JPA/src/main/java/de/spring/example/rest/controllers/AdController.java b/SpringJava/JPA/src/main/java/de/spring/example/rest/controllers/AdController.java
new file mode 100644 (file)
index 0000000..976a1df
--- /dev/null
@@ -0,0 +1,23 @@
+package de.spring.example.rest.controllers;
+
+import javax.inject.Inject;
+
+import org.resthub.web.controller.RepositoryBasedRestController;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import de.spring.example.persistence.domain.Ad;
+import de.spring.example.persistence.repository.AdRepository;
+
+@RestController
+@RequestMapping("/ads/")
+public class AdController extends RepositoryBasedRestController<Ad, Long, AdRepository> {
+
+    @Override
+    @Inject
+    public void setRepository(AdRepository repository) {
+        this.repository = repository;
+    }
+    
+       // I do not have to do anything here because all I need is implemented by RepositoryBasedRestController :)
+}
diff --git a/SpringJava/JPA/src/main/java/de/spring/persistence/converters/OffsetDateTimeAttributeConverter.java b/SpringJava/JPA/src/main/java/de/spring/persistence/converters/OffsetDateTimeAttributeConverter.java
deleted file mode 100644 (file)
index 3573265..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-package de.spring.persistence.converters;
-
-import java.sql.Timestamp;
-import java.time.LocalDateTime;
-import java.time.OffsetDateTime;
-import java.time.ZoneId;
-import java.time.ZonedDateTime;
-
-import javax.persistence.AttributeConverter;
-import javax.persistence.Converter;
-
-@Converter(autoApply = true)
-public class OffsetDateTimeAttributeConverter implements AttributeConverter<OffsetDateTime, Timestamp> {
-
-       @Override
-       public Timestamp convertToDatabaseColumn(OffsetDateTime offsetDateTime) {
-               Timestamp timestamp = null;
-               
-               if (offsetDateTime != null) {
-                       timestamp = Timestamp.valueOf(offsetDateTime.toLocalDateTime());
-               }
-               
-               return timestamp;
-       }
-
-       @Override
-       public OffsetDateTime convertToEntityAttribute(Timestamp sqlTimestamp) {
-               OffsetDateTime offsetDateTime = null;
-               
-               if (sqlTimestamp != null) {
-                       final LocalDateTime localDateTime = sqlTimestamp.toLocalDateTime();
-                       final ZonedDateTime zonedDateTime = localDateTime.atZone(ZoneId.systemDefault());
-                       offsetDateTime = zonedDateTime.toOffsetDateTime();
-               }
-               
-               return offsetDateTime;
-       }
-
-}
diff --git a/SpringJava/JPA/src/main/java/de/spring/persistence/example/domain/Ad.java b/SpringJava/JPA/src/main/java/de/spring/persistence/example/domain/Ad.java
deleted file mode 100644 (file)
index eb41328..0000000
+++ /dev/null
@@ -1,132 +0,0 @@
-package de.spring.persistence.example.domain;
-
-import java.io.Serializable;
-import java.time.LocalDateTime;
-import java.time.OffsetDateTime;
-import java.util.Set;
-
-import javax.persistence.Column;
-import javax.persistence.Convert;
-import javax.persistence.Entity;
-import javax.persistence.FetchType;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-//import javax.persistence.NamedNativeQueries;
-//import javax.persistence.NamedNativeQuery;
-//import javax.persistence.NamedQueries;
-//import javax.persistence.NamedQuery;
-import javax.persistence.OneToMany;
-import javax.persistence.Table;
-import javax.validation.constraints.Max;
-import javax.validation.constraints.NotNull;
-import javax.validation.constraints.Size;
-
-import com.fasterxml.jackson.annotation.JsonFormat;
-
-import de.spring.persistence.converters.OffsetDateTimeAttributeConverter;
-
-@Entity
-@Table(name="ad", schema="mybatis_example")
-// 1. Named query is JPL. It is portable.
-// 2. Instead of annotating the domain class we should be using @Query annotation at the query method
-//    because it should be cleaner :)
-//    So you'd better use @Query.
-//http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods.at-query
-//See: de.spring.persistence.example.repository.AdRepository 
-//@NamedQueries(
-//             {
-//                     @NamedQuery(
-//                     name="Ad.findByIdQuery",
-//                     query="select a from Ad a where a.id = :id)
-//             }
-//     
-//)
-// 1. Native query IS NOT JPL. It is not portable and it is written directly in the native language
-//    of the store. We can use special features at the cost of portability.
-// 2. Instead of annotating the domain class we should be using @Query annotation at the query method
-//       because it should be cleaner :)
-//    So you'd better use @Query.
-//    http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods.at-query
-//    See: de.spring.persistence.example.repository.AdRepository 
-//@NamedNativeQueries(
-//     {
-//             @NamedNativeQuery(
-//                     name="Ad.findByIdNativeQuery",
-//                     query="SELECT * FROM ad WHERE ad.id = :id",
-//                     resultClass=Ad.class)
-//     }               
-//)
-public class Ad implements Serializable {
-
-       @Id
-       @GeneratedValue(strategy=GenerationType.IDENTITY)
-       @Column(name="id", updatable=false, nullable=false)
-       private Long id;
-       
-       @OneToMany(mappedBy="ad", fetch=FetchType.LAZY, targetEntity=AdDescription.class)
-       private Set<AdDescription> adDescriptions;
-       
-       @Max(60)
-       @Column(name="company_id")
-       private Long companyId;
-       
-       @Max(40)
-       @Column(name="company_categ_id")
-       private Long companyCategId;
-       
-       @Size(min=2, max=255)
-       @Column(name="ad_mobile_image")
-       private String adMobileImage;
-
-       @NotNull
-       @Convert(converter=OffsetDateTimeAttributeConverter.class)
-       @Column(name="created_at", nullable=false)
-       @JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ssZ")
-       private OffsetDateTime createdAt;
-       
-       @NotNull
-       @Convert(converter=OffsetDateTimeAttributeConverter.class)
-       @Column(name="updated_at", nullable = false)
-       @JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ssZ")
-       private OffsetDateTime updatedAt;
-
-       // It will be used by JPA when filling the property fields with data coming from data base.
-       protected Ad() {
-
-       }
-
-       // It will be used by my code (for example by Unit Tests)
-       public Ad(Long id, Long companyId, Long companyCategId, String adMobileImage, OffsetDateTime createdAt,
-                       OffsetDateTime updatedAt) {
-               this.id = id;
-               this.companyCategId = companyCategId;
-               this.adMobileImage = adMobileImage;
-               this.createdAt = createdAt;
-               this.updatedAt = updatedAt;
-       }
-
-       public Long getId() {
-               return id;
-       }
-
-       public Long getCompanyId() {
-               return companyId;
-       }
-
-       public Long getCompanyCategId() {
-               return companyCategId;
-       }
-
-       public String getAdMobileImage() {
-               return adMobileImage;
-       }
-
-       public OffsetDateTime getCreatedAt() {
-               return createdAt;
-       }
-
-       public OffsetDateTime getUpdatedAt() {
-               return updatedAt;
-       }
-}
diff --git a/SpringJava/JPA/src/main/java/de/spring/persistence/example/domain/AdDescription.java b/SpringJava/JPA/src/main/java/de/spring/persistence/example/domain/AdDescription.java
deleted file mode 100644 (file)
index a3b7d16..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-package de.spring.persistence.example.domain;
-
-import java.io.Serializable;
-
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
-import javax.persistence.Table;
-import javax.validation.constraints.Max;
-import javax.validation.constraints.NotNull;
-import javax.validation.constraints.Size;
-
-@Entity
-@Table(name="ad_description", schema="mybatis_example")
-public class AdDescription implements Serializable {
-
-       @Id
-       @GeneratedValue(strategy=GenerationType.IDENTITY)
-       @Column(name="id", updatable=false, nullable=false)
-       private Long id;
-       
-       @NotNull
-       @ManyToOne(optional=false)
-       @JoinColumn(name="ad_id", referencedColumnName="id")
-       private Ad ad;
-       
-       @NotNull
-       @Max(60)
-       @Column(name="language_id")
-       private Long languageId;
-       
-       @NotNull
-       @Size(min=2, max=255)
-       @Column(name="ad_name")
-       private String adName;
-
-       @NotNull
-       @Size(min=2, max=255)
-       @Column(name="ad_description")
-       private String adDescription;
-       
-       @NotNull
-       @Size(min=2, max=500)
-       @Column(name="ad_mobile_text")
-       private String adMobileText;
-       
-       @NotNull
-       @Size(min=2, max=3000)
-       @Column(name="ad_link")
-       private String adLink;
-       
-       // It will be used by JPA when filling the property fields with data coming from data base.
-       protected AdDescription() {
-
-       }
-
-       // It will be used by my code (for example by Unit Tests)
-       public AdDescription(Long id, Ad ad, Long languageId, String adName, String adDescription,
-                       String adMobileText, String adLink) {
-               this.id = id;
-               this.languageId = languageId;
-               this.ad = ad;
-               this.adName = adName;
-               this.adDescription = adDescription;
-               this.adMobileText = adMobileText;
-               this.adLink = adLink;
-       }
-
-       public Long getId() {
-               return id;
-       }
-
-       public Ad getAd() {
-               return ad;
-       }
-
-       public Long getLanguageId() {
-               return languageId;
-       }
-
-       public String getAdName() {
-               return adName;
-       }
-
-       public String getAdDescription() {
-               return adDescription;
-       }
-
-       public String getAdMobileText() {
-               return adMobileText;
-       }
-
-       public String getAdLink() {
-               return adLink;
-       }
-}
diff --git a/SpringJava/JPA/src/main/java/de/spring/persistence/example/repository/AdDescriptionRepository.java b/SpringJava/JPA/src/main/java/de/spring/persistence/example/repository/AdDescriptionRepository.java
deleted file mode 100644 (file)
index d59ade2..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-package de.spring.persistence.example.repository;
-
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.Pageable;
-import org.springframework.data.repository.PagingAndSortingRepository;
-
-import de.spring.persistence.example.domain.Ad;
-import de.spring.persistence.example.domain.AdDescription;
-
-public interface AdDescriptionRepository extends PagingAndSortingRepository<AdDescription, Long> {
-
-       // Custom Query method
-       Page<AdDescription> findByAd(Ad ad, Pageable pageable);
-}
diff --git a/SpringJava/JPA/src/main/java/de/spring/persistence/example/repository/AdRepository.java b/SpringJava/JPA/src/main/java/de/spring/persistence/example/repository/AdRepository.java
deleted file mode 100644 (file)
index 24b9c47..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-package de.spring.persistence.example.repository;
-
-import org.springframework.data.jpa.repository.Query;
-import org.springframework.data.repository.PagingAndSortingRepository;
-import org.springframework.data.repository.query.Param;
-
-import de.spring.persistence.example.domain.Ad;
-
-public interface AdRepository extends PagingAndSortingRepository<Ad, Long> {
-       
-       // Named Native Query (using the native language of the store) It is not portable.
-       // See de.spring.persistence.example.domain.Ad
-       @Query(value="SELECT * FROM ad WHERE ad.id = :id", nativeQuery=true)
-       Ad findByIdNativeQuery(@Param("id") Long id);
-       
-       // Named Query (using JPL) It is portable.
-       // See de.spring.persistence.example.domain.Ad
-       @Query("select a from Ad a where a.id = :id")
-       Ad findByIdQuery(@Param("id") Long id);
-}
diff --git a/SpringJava/JPA/src/main/java/de/spring/rest/controllers/AdController.java b/SpringJava/JPA/src/main/java/de/spring/rest/controllers/AdController.java
deleted file mode 100644 (file)
index ae0e29f..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-package de.spring.rest.controllers;
-
-import javax.inject.Inject;
-
-import org.resthub.web.controller.RepositoryBasedRestController;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-import de.spring.persistence.example.domain.Ad;
-import de.spring.persistence.example.repository.AdRepository;
-
-@RestController
-@RequestMapping("/ads/")
-public class AdController extends RepositoryBasedRestController<Ad, Long, AdRepository> {
-
-    @Override
-    @Inject
-    public void setRepository(AdRepository repository) {
-        this.repository = repository;
-    }
-    
-       // I do not have to do anything here because all I need is implemented by RepositoryBasedRestController :)
-}
index 1a16615..2a7f621 100644 (file)
@@ -15,7 +15,7 @@
 \r
        <context:annotation-config />\r
 \r
-    <context:component-scan base-package="de.spring.persistence, org.resthub" />\r
+    <context:component-scan base-package="de.spring.example.persistence, org.resthub" />\r
     \r
     <context:property-placeholder location="classpath:jpa.properties" />\r
     \r
                                <property name="showSql" value="${jpa.show_sql}" />\r
                        </bean>\r
                </property>\r
-               <property name="packagesToScan" value="de.spring.persistence.**.domain" />\r
+               <property name="packagesToScan" value="de.spring.example.persistence.**.domain" />\r
        </bean>\r
 \r
        <jpa:repositories entity-manager-factory-ref="entityManagerFactory"\r
-               base-package="de.spring.persistence.**.repository"\r
+               base-package="de.spring.example.persistence.**.repository"\r
                transaction-manager-ref="transactionManager" />\r
 \r
 </beans>\r
index 1c2f309..d6a3185 100644 (file)
@@ -25,7 +25,7 @@
    
        <context:annotation-config />
    
-       <context:component-scan base-package="de.spring.rest"/>
+       <context:component-scan base-package="de.spring.example.rest"/>
        
        <!--
                Required beans for generating XML responses from Java objects using JAXB annotations