Skip to content

Commit

Permalink
整理代码,拆分sql演示flyway
Browse files Browse the repository at this point in the history
  • Loading branch information
calvin1978 committed Nov 11, 2015
1 parent 84c3aa4 commit 75dd67e
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 22 deletions.
5 changes: 5 additions & 0 deletions examples/boot-api/refresh-db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

echo "cleanup the production/qa db,just for demo"

mvn flyway:clean
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springside.examples.bootapi.service.AccountService;
import org.springside.examples.bootapi.service.ServiceException;
import org.springside.examples.bootapi.service.exception.ErrorCode;
import org.springside.examples.bootapi.service.exception.ServiceException;
import org.springside.modules.web.MediaTypes;

// Spring Restful MVC Controller的标识, 直接输出内容,不调用template引擎.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import org.springside.examples.bootapi.service.AccountService;
import org.springside.examples.bootapi.service.BookAdminService;
import org.springside.examples.bootapi.service.BookBorrowService;
import org.springside.examples.bootapi.service.ServiceException;
import org.springside.examples.bootapi.service.exception.ErrorCode;
import org.springside.examples.bootapi.service.exception.ServiceException;
import org.springside.modules.mapper.BeanMapper;
import org.springside.modules.web.MediaTypes;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
import org.springside.examples.bootapi.service.ServiceException;
import org.springside.examples.bootapi.service.exception.ServiceException;
import org.springside.modules.web.MediaTypes;

@ControllerAdvice
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
// JPA实体类的标识
@Entity
public class Account {
// JPA 主键标识

// JPA 主键标识, 策略为由数据库生成主键
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Book {
public static final String STATUS_REQUEST = "request";
public static final String STATUS_OUT = "out";

// JPA 主键标识
// JPA 主键标识, 策略为由数据库生成主键
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@Entity
public class Message {

// JPA 主键标识
// JPA 主键标识, 策略为由数据库生成主键
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.springside.examples.bootapi.domain.Account;
import org.springside.examples.bootapi.repository.AccountDao;
import org.springside.examples.bootapi.service.exception.ErrorCode;
import org.springside.examples.bootapi.service.exception.ServiceException;
import org.springside.modules.utils.Digests;
import org.springside.modules.utils.Encodes;
import org.springside.modules.utils.Ids;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.springside.examples.bootapi.domain.Book;
import org.springside.examples.bootapi.repository.BookDao;
import org.springside.examples.bootapi.service.exception.ErrorCode;
import org.springside.examples.bootapi.service.exception.ServiceException;
import org.springside.modules.utils.Clock;

// Spring Bean的标识.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.springside.examples.bootapi.repository.BookDao;
import org.springside.examples.bootapi.repository.MessageDao;
import org.springside.examples.bootapi.service.exception.ErrorCode;
import org.springside.examples.bootapi.service.exception.ServiceException;
import org.springside.modules.utils.Clock;

// Spring Bean的标识.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
package org.springside.examples.bootapi.service;

import org.springside.examples.bootapi.service.exception.ErrorCode;
package org.springside.examples.bootapi.service.exception;

public class ServiceException extends RuntimeException {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
drop table if exists book;
drop table if exists account;
drop table if exists message;

create table book (
id bigint generated by default as identity,
douban_id varchar(64) not null,
Expand All @@ -24,15 +20,6 @@ create table account (
primary key (id)
);

create table message (
id bigint generated by default as identity,
receiver_id bigint null,
message varchar(256),
receive_date timestamp,
primary key (id)
);



insert into book (id, douban_id, title, url, description, owner_id,status,onboard_date) values(1,'25984046', 'Big Data日知录', 'http://book.douban.com/subject/25984046/','', 1,'idle','2015-01-01');
insert into book (id, douban_id, title, url, description, owner_id,status,onboard_date) values(2,'25900156', 'Redis设计与实现', 'http://book.douban.com/subject/25900156/','', 1,'idle','2015-01-02');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
create table message (
id bigint generated by default as identity,
receiver_id bigint null,
message varchar(256),
receive_date timestamp,
primary key (id)
);

0 comments on commit 75dd67e

Please sign in to comment.