Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Apress committed Oct 19, 2016
0 parents commit 58b210c
Show file tree
Hide file tree
Showing 218 changed files with 14,568 additions and 0 deletions.
Binary file added 9781484201282.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions LICENSE.txt
@@ -0,0 +1,27 @@
Freeware License, some rights reserved

Copyright (c) 2015 Gary Mak, Srinivas Guruzu, and Joseph Ottinger

Permission is hereby granted, free of charge, to anyone obtaining a copy
of this software and associated documentation files (the "Software"),
to work with the Software within the limits of freeware distribution and fair use.
This includes the rights to use, copy, and modify the Software for personal use.
Users are also allowed and encouraged to submit corrections and modifications
to the Software for the benefit of other users.

It is not allowed to reuse, modify, or redistribute the Software for
commercial use in any way, or for a user�s educational materials such as books
or blog articles without prior permission from the copyright holder.

The above copyright notice and this permission notice need to be included
in all copies or substantial portions of the software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS OR APRESS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


15 changes: 15 additions & 0 deletions README.md
@@ -0,0 +1,15 @@
#Apress Source Code

This repository accompanies [*Hibernate Recipes*](http://www.apress.com/9781484201282) by Gary Mak, Srinivas Guruzu, and Joseph Ottinger (Apress, 2015).

![Cover image](9781484201282.jpg)

Download the files as a zip using the green button, or clone the repository to your machine using Git.

##Releases

Release v1.0 corresponds to the code in the published book, without corrections or updates.

##Contributions

See the file Contributing.md for more information on how you can contribute to this repository.
40 changes: 40 additions & 0 deletions chapter1/pom.xml
@@ -0,0 +1,40 @@
<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>
<groupId>com.apress.hibernaterecipes</groupId>
<artifactId>ver2</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>chapter1</artifactId>

<dependencies>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>com.apress.hibernaterecipes</groupId>
<artifactId>util</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${version.slf4j}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${version.logback}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${version.logback}</version>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,80 @@
package com.apress.hibernaterecipes.chapter1.model;

import java.math.BigDecimal;
import java.sql.Date;

/**
* Created by jottinge on 6/25/14.
*/
public class Book {
private String isbn;
private String name;
private Date publishdate;
private BigDecimal price;
private Publisher publisher;

public String getIsbn() {
return isbn;
}

public void setIsbn(String isbn) {
this.isbn = isbn;
}

public String getName() {
return name;
}

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

public Date getPublishdate() {
return publishdate;
}

public void setPublishdate(Date publishdate) {
this.publishdate = publishdate;
}

public BigDecimal getPrice() {
return price;
}

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

public Publisher getPublisher() {
return publisher;
}

public void setPublisher(Publisher publisher) {
this.publisher = publisher;
}


@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Book book = (Book) o;

if (isbn != null ? !isbn.equals(book.isbn) : book.isbn != null) return false;
if (name != null ? !name.equals(book.name) : book.name != null) return false;
if (price != null ? !price.equals(book.price) : book.price != null) return false;
if (publishdate != null ? !publishdate.equals(book.publishdate) : book.publishdate != null) return false;

return true;
}

@Override
public int hashCode() {
int result = isbn != null ? isbn.hashCode() : 0;
result = 31 * result + (name != null ? name.hashCode() : 0);
result = 31 * result + (publishdate != null ? publishdate.hashCode() : 0);
result = 31 * result + (price != null ? price.hashCode() : 0);
return result;
}
}
@@ -0,0 +1,56 @@
package com.apress.hibernaterecipes.chapter1.model;

/**
* Created by jottinge on 6/25/14.
*/
public class Publisher {
private String code;
private String name;
private String address;

public String getCode() {
return code;
}

public void setCode(String code) {
this.code = code;
}

public String getName() {
return name;
}

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

public String getAddress() {
return address;
}

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

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Publisher publisher = (Publisher) o;

if (address != null ? !address.equals(publisher.address) : publisher.address != null) return false;
if (code != null ? !code.equals(publisher.code) : publisher.code != null) return false;
if (name != null ? !name.equals(publisher.name) : publisher.name != null) return false;

return true;
}

@Override
public int hashCode() {
int result = code != null ? code.hashCode() : 0;
result = 31 * result + (name != null ? name.hashCode() : 0);
result = 31 * result + (address != null ? address.hashCode() : 0);
return result;
}
}
18 changes: 18 additions & 0 deletions chapter1/src/main/resources/META-INF/persistence.xml
@@ -0,0 +1,18 @@
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="chapter1" transaction-type="RESOURCE_LOCAL">

<class>com.apress.hibernaterecipes.chapter1.model.Publisher</class>
<class>com.apress.hibernaterecipes.chapter1.model.Book</class>

<properties>
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:h2:file:./chapter1"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
<property name="hibernate.hbm2ddl.auto" value="create"/>
<property name="hibernate.show_sql" value="true"/>
</properties>
</persistence-unit>
</persistence>
@@ -0,0 +1,22 @@
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>

<class name="com.apress.hibernaterecipes.chapter1.model.Book" table="BOOK" lazy="false">
<id name="isbn">
<column name="ISBN" sql-type="varchar(13)" not-null="true"/>
</id>
<property name="name">
<column name="NAME" sql-type="varchar(64)" not-null="true" unique="true"/>
</property>
<property name="publishdate">
<column name="PUBLISHDATE" sql-type="date"/>
</property>
<property name="price">
<column name="PRICE" sql-type="decimal" precision="8" scale="2"/>
</property>
<many-to-one name="publisher" column="PUBLISHERCODE" cascade="all"/>
</class>
</hibernate-mapping>
@@ -0,0 +1,18 @@
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>

<class name="com.apress.hibernaterecipes.chapter1.model.Publisher" table="PUBLISHER" lazy="false">
<id name="code">
<column name="CODE" sql-type="varchar(6)" not-null="true"/>
</id>
<property name="name">
<column name="NAME" sql-type="varchar(64)" not-null="true"/>
</property>
<property name="address">
<column name="ADDRESS" sql-type="varchar(128)" not-null="true"/>
</property>
</class>
</hibernate-mapping>
18 changes: 18 additions & 0 deletions chapter1/src/main/resources/ddl.sql
@@ -0,0 +1,18 @@
# note that this file IS NOT used BY this project.

CREATE TABLE publisher (
code VARCHAR(6) PRIMARY KEY,
name VARCHAR(64) NOT NULL,
address VARCHAR(128) NOT NULL,
UNIQUE (name)
);

CREATE TABLE book (
isbn VARCHAR(13) PRIMARY KEY,
name VARCHAR(64) NOT NULL,
publishDate DATE,
price DECIMAL(8, 2),
publisher VARCHAR(6),
FOREIGN KEY (publisher) REFERENCES publisher (code),
UNIQUE (name)
);
16 changes: 16 additions & 0 deletions chapter1/src/main/resources/hibernate.cfg.xml
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">org.h2.Driver</property>
<property name="connection.url">jdbc:h2:file:./chapter1</property>
<property name="hibernate.dialect">org.hibernate.dialect.H2Dialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">create</property>
<property name="hibernate.generate_statistics">true</property>
<mapping resource="com/apress/hibernaterecipes/chapter1/model/Book.hbm.xml"/>
<mapping resource="com/apress/hibernaterecipes/chapter1/model/Publisher.hbm.xml"/>
</session-factory>
</hibernate-configuration>
28 changes: 28 additions & 0 deletions chapter1/src/main/resources/logback.xml
@@ -0,0 +1,28 @@
<configuration>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>mylog.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>mylog.%i.log.zip</fileNamePattern>
<minIndex>1</minIndex>
<maxIndex>3</maxIndex>
</rollingPolicy>

<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>5MB</maxFileSize>
</triggeringPolicy>
<encoder>
<pattern>%date{YYYY-MM-dd HH:mm:ss} %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
</encoder>
</appender>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%msg%n</pattern>
</encoder>
</appender>

<root level="info">
<appender-ref ref="FILE" />
<appender-ref ref="STDOUT" />
</root>
</configuration>

0 comments on commit 58b210c

Please sign in to comment.