Skip to content

Commit

Permalink
Bookstore first attempt.
Browse files Browse the repository at this point in the history
  • Loading branch information
mdeinum committed Jan 11, 2012
1 parent 42441ac commit d65f182
Show file tree
Hide file tree
Showing 146 changed files with 1,863 additions and 689 deletions.
4 changes: 4 additions & 0 deletions bookstore-shared/.gitignore
@@ -1 +1,5 @@
/build/
/*.project
/*.classpath
/.settings/
/bin/
@@ -1,4 +1,4 @@
package com.apress.prospringmvc.pizzarus.config;
package com.apress.prospringmvc.bookstore.config;

import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
Expand All @@ -8,13 +8,9 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.Profile;
import org.springframework.core.io.ClassPathResource;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
import org.springframework.jdbc.datasource.init.DataSourceInitializer;
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.JpaVendorAdapter;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
Expand All @@ -29,8 +25,8 @@
*/
@Configuration
@EnableTransactionManagement
@ComponentScan(basePackages = { "com.apress.prospringmvc.pizzarus.service",
"com.apress.prospringmvc.pizzarus.repository" })
@ComponentScan(basePackages = { "com.apress.prospringmvc.bookstore.service",
"com.apress.prospringmvc.bookstore.repository" })
public class InfrastructureContextConfiguration {

@Autowired
Expand All @@ -44,7 +40,7 @@ public FactoryBean<EntityManagerFactory> entityManagerFactory() {
LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
localContainerEntityManagerFactoryBean.setDataSource(this.dataSource);
// localContainerEntityManagerFactoryBean.setPersistenceUnitName("pizzas-r-us");
localContainerEntityManagerFactoryBean.setPackagesToScan("com.apress.prospringmvc.pizzarus.domain");
localContainerEntityManagerFactoryBean.setPackagesToScan("com.apress.prospringmvc.bookstore.domain");
localContainerEntityManagerFactoryBean.setJpaVendorAdapter(jpaVendorAdapter());
return localContainerEntityManagerFactoryBean;
}
Expand All @@ -65,18 +61,6 @@ public PlatformTransactionManager transactionManager() {
return transactionManager;
}

@Bean
@DependsOn(value = "entityManagerFactory")
public DataSourceInitializer dataSourceInitializer() {
DataSourceInitializer initializer = new DataSourceInitializer();
initializer.setDataSource(this.dataSource);
initializer.setEnabled(true);
ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
populator.addScript(new ClassPathResource("/META-INF/sql/data.sql"));
initializer.setDatabasePopulator(populator);
return initializer;
}

@Configuration
@Profile("test")
public static class TestDataSourceConfiguration {
Expand Down
@@ -0,0 +1,85 @@
package com.apress.prospringmvc.bookstore.domain;

import java.io.Serializable;

import javax.persistence.Embeddable;

/**
* A component which resembles the address of a {@link Customer}
*
* @author Koen Serneels
*/

@Embeddable
public class Address implements Serializable {

private String street;
private String houseNumber;
private String boxNumber;
private String city;
private String postalCode;
private String country;

public Address() {
super();
}

public Address(Address source) {
super();
this.street = source.street;
this.houseNumber = source.houseNumber;
this.boxNumber = source.boxNumber;
this.city = source.city;
this.postalCode = source.postalCode;
this.country = source.country;
}

public String getStreet() {
return this.street;
}

public void setStreet(String street) {
this.street = street;
}

public String getHouseNumber() {
return this.houseNumber;
}

public void setHouseNumber(String houseNumber) {
this.houseNumber = houseNumber;
}

public String getBoxNumber() {
return this.boxNumber;

}

public void setBoxNumber(String boxNumber) {
this.boxNumber = boxNumber;
}

public String getCity() {
return this.city;
}

public void setCity(String city) {
this.city = city;
}

public String getPostalCode() {
return this.postalCode;
}

public void setPostalCode(String postalCode) {
this.postalCode = postalCode;
}

public String getCountry() {
return this.country;
}

public void setCountry(String country) {
this.country = country;
}
}
@@ -0,0 +1,79 @@
package com.apress.prospringmvc.bookstore.domain;

import java.math.BigDecimal;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;

@Entity
public class Book {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

private String title;
private String description;
private BigDecimal price;
private Integer year;
private String author;

@ManyToOne(optional = false)
private Category category;

public Long getId() {
return this.id;
}

public String getTitle() {
return this.title;
}

public void setTitle(String title) {
this.title = title;
}

public String getDescription() {
return this.description;
}

public void setDescription(String description) {
this.description = description;
}

public BigDecimal getPrice() {
return this.price;
}

public void setPrice(BigDecimal price) {
this.price = price;
}

public Integer getYear() {
return this.year;
}

public void setYear(Integer year) {
this.year = year;
}

public String getAuthor() {
return this.author;
}

public void setAuthor(String author) {
this.author = author;
}

public Category getCategory() {
return this.category;
}

public void setCategory(Category category) {
this.category = category;
}

}
@@ -0,0 +1,29 @@
package com.apress.prospringmvc.bookstore.domain;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
public class Category {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

private String name;

public Long getId() {
return this.id;
}

public void setName(String name) {
this.name = name;
}

public String getName() {
return this.name;
}

}
@@ -0,0 +1,87 @@
package com.apress.prospringmvc.bookstore.domain;

import java.io.Serializable;

import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

/**
* A customer resembles an authenticated user of our system. A customer is able to submit orders. A customer is
* identified by his or her username. When authenticating the user supplies its username and password. Besides
* identification information we also store basic legal information such as address, firstname, lastname and email
* address.
*
* @author Koen Serneels
*/

@Entity
public class Customer implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

private String firstName;
private String lastName;

@Embedded
private Address address;
private String emailAddress;
private String username;
private String password;

public Long getId() {
return this.id;
}

public String getFirstName() {
return this.firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return this.lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public String getEmailAddress() {
return this.emailAddress;
}

public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
}

public String getUsername() {
return this.username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return this.password;
}

public void setPassword(String password) {
this.password = password;
}

public Address getAddress() {
return this.address;
}

public void setAddress(Address address) {
this.address = address;
}
}

0 comments on commit d65f182

Please sign in to comment.