Skip to content

Commit

Permalink
add undo_log.sql and add database driver class config (apache#1323)
Browse files Browse the repository at this point in the history
  • Loading branch information
vikenlove authored and slievrly committed Jul 19, 2019
1 parent c6d8e4d commit c4c5faf
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ public class ConfigurationKeys {
* The constant STORE_DB_TYPE.
*/
public static final String STORE_DB_TYPE = "store.db.db-type";
/**
* The constant STORE_DB_DRIVER_CLASS_NAME.
*/
public static final String STORE_DB_DRIVER_CLASS_NAME = "store.db.driver-class-name";

/**
* The constant STORE_DB_URL.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,17 @@ public abstract class AbstractDataSourceGenerator implements DataSourceGenerator
protected DBType getDBType() {
return DBType.valueof(CONFIG.getConfig(ConfigurationKeys.STORE_DB_TYPE));
}

/**
* get db driver class name
* @return the db driver class name
*/
protected String getDriverClassName() {
String driverClassName = CONFIG.getConfig(ConfigurationKeys.STORE_DB_DRIVER_CLASS_NAME);
if (StringUtils.isBlank(driverClassName)) {
throw new StoreException("the {store.db.driver-class-name} can't be empty.");
}
return driverClassName;
}
/**
* Get url string.
*
Expand All @@ -52,7 +62,7 @@ protected DBType getDBType() {
protected String getUrl() {
String url = CONFIG.getConfig(ConfigurationKeys.STORE_DB_URL);
if (StringUtils.isBlank(url)) {
throw new StoreException("the {store.db.url} can't empty.");
throw new StoreException("the {store.db.url} can't be empty.");
}
return url;
}
Expand All @@ -65,7 +75,7 @@ protected String getUrl() {
protected String getUser() {
String user = CONFIG.getConfig(ConfigurationKeys.STORE_DB_USER);
if (StringUtils.isBlank(user)) {
throw new StoreException("the {store.db.user} can't empty.");
throw new StoreException("the {store.db.user} can't be empty.");
}
return user;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class DbcpDataSourceGenerator extends AbstractDataSourceGenerator {
@Override
public DataSource generateDataSource() {
BasicDataSource ds = new BasicDataSource();
ds.setDriverClassName(getDriverName(getDBType()));
ds.setDriverClassName(getDriverClassName());
ds.setUrl(getUrl());
ds.setUsername(getUser());
ds.setPassword(getPassword());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class DruidDataSourceGenerator extends AbstractDataSourceGenerator {
@Override
public DataSource generateDataSource() {
DruidDataSource ds = new DruidDataSource();
ds.setDriverClassName(getDriverName(getDBType()));
ds.setDriverClassName(getDriverClassName());
ds.setUrl(getUrl());
ds.setUsername(getUser());
ds.setPassword(getPassword());
Expand Down
19 changes: 19 additions & 0 deletions server/src/main/resources/db_undo_log.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- the table to store seata xid data
-- 0.7.0+ add context
-- you must to init this sql for you business databese. the seata server not need it.
-- 此脚本必须初始化在你当前的业务数据库中,用于AT 模式XID记录。与server端无关(注:业务数据库)
-- 注意此处0.3.0+ 增加唯一索引 ux_undo_log
drop table `undo_log`;
CREATE TABLE `undo_log` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`branch_id` bigint(20) NOT NULL,
`xid` varchar(100) NOT NULL,
`context` varchar(128) NOT NULL,
`rollback_info` longblob NOT NULL,
`log_status` int(11) NOT NULL,
`log_created` datetime NOT NULL,
`log_modified` datetime NOT NULL,
`ext` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
1 change: 1 addition & 0 deletions server/src/main/resources/file.conf
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ store {
datasource = "dbcp"
## mysql/oracle/h2/oceanbase etc.
db-type = "mysql"
driver-class-name = "com.mysql.jdbc.Driver"
url = "jdbc:mysql://127.0.0.1:3306/seata"
user = "mysql"
password = "mysql"
Expand Down

0 comments on commit c4c5faf

Please sign in to comment.