From 51e82d7d90867a92b110d72a5668d4f9e82713a4 Mon Sep 17 00:00:00 2001
From: WuXianChaoPin <1029559041@qq.com>
Date: Mon, 7 May 2018 19:04:02 +0800
Subject: [PATCH] thift
---
core/pom.xml | 11 +
core/src/main/java/core/aop/Advisor.java | 4 +-
.../java/core/config/HibernateConfig.java | 79 ----
.../core/dao/{BaseDao.java => BaseDao1.java} | 9 +-
core/src/main/java/core/dao/BaseDao2.java | 26 ++
.../main/java/core/service/BaseService.java | 6 +-
db/pom.xml | 63 +++
.../main/java/db/config/HibernateConfig.java | 117 ++++++
.../java/db/config/MyEmptyInterceptor.java | 30 ++
.../main/java/db}/model/AbstractModel.java | 2 +-
.../src/main/java/db}/model/CidEntity.java | 4 +-
.../src/main/java/db/model/DataModel.java | 373 +++++++++---------
.../java/db}/model/ScheduledTaskEntity.java | 4 +-
.../src/main/java/db}/model/TaskEntity.java | 4 +-
pom.xml | 8 +
web/pom.xml | 5 -
.../java/web/config/AbstractWebConfig.java | 5 +-
web/src/main/java/web/config/AppConfig.java | 14 +
.../main/java/web/config/SpringConfig.java | 13 +-
.../java/web/controller/BaseController.java | 2 +-
.../web/controller/CommentController.java | 10 +-
web/src/main/java/web/util/DynamicTimer.java | 8 +-
web/src/main/resources/config.properties | 18 +-
web/src/main/resources/log4j2.xml | 5 +-
web/src/test/java/SpringTest.java | 144 +++++++
25 files changed, 643 insertions(+), 321 deletions(-)
delete mode 100644 core/src/main/java/core/config/HibernateConfig.java
rename core/src/main/java/core/dao/{BaseDao.java => BaseDao1.java} (74%)
create mode 100644 core/src/main/java/core/dao/BaseDao2.java
create mode 100644 db/pom.xml
create mode 100644 db/src/main/java/db/config/HibernateConfig.java
create mode 100644 db/src/main/java/db/config/MyEmptyInterceptor.java
rename {core/src/main/java/core => db/src/main/java/db}/model/AbstractModel.java (97%)
rename {web/src/main/java/web => db/src/main/java/db}/model/CidEntity.java (99%)
rename web/src/main/java/web/model/DataEntity.java => db/src/main/java/db/model/DataModel.java (73%)
rename {web/src/main/java/web => db/src/main/java/db}/model/ScheduledTaskEntity.java (98%)
rename {web/src/main/java/web => db/src/main/java/db}/model/TaskEntity.java (95%)
create mode 100644 web/src/main/java/web/config/AppConfig.java
create mode 100644 web/src/test/java/SpringTest.java
diff --git a/core/pom.xml b/core/pom.xml
index af344df..7ab1604 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -80,6 +80,17 @@
druid
+
+ org.apache.commons
+ commons-lang3
+
+
+ org.pqh
+ db
+ 1.0-SNAPSHOT
+ compile
+
+
core
diff --git a/core/src/main/java/core/aop/Advisor.java b/core/src/main/java/core/aop/Advisor.java
index 2ac7b8c..2e45084 100644
--- a/core/src/main/java/core/aop/Advisor.java
+++ b/core/src/main/java/core/aop/Advisor.java
@@ -1,6 +1,6 @@
package core.aop;
-import core.dao.BaseDao;
+import core.dao.BaseDao1;
import org.aopalliance.aop.Advice;
import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor;
import org.springframework.stereotype.Component;
@@ -19,7 +19,7 @@ public class Advisor extends StaticMethodMatcherPointcutAdvisor {
@Override
public boolean matches(Method method, Class> aClass) {
- return BaseDao.class.isAssignableFrom(aClass);
+ return BaseDao1.class.isAssignableFrom(aClass);
}
@PostConstruct
diff --git a/core/src/main/java/core/config/HibernateConfig.java b/core/src/main/java/core/config/HibernateConfig.java
deleted file mode 100644
index f917e3b..0000000
--- a/core/src/main/java/core/config/HibernateConfig.java
+++ /dev/null
@@ -1,79 +0,0 @@
-package core.config;
-
-import com.alibaba.druid.pool.DruidDataSource;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.hibernate.SessionFactory;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.orm.hibernate5.HibernateTransactionManager;
-import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
-import org.springframework.transaction.annotation.EnableTransactionManagement;
-
-import javax.annotation.PostConstruct;
-import java.io.IOException;
-import java.util.Properties;
-
-/**
- * Created by reborn on 2017/7/28.
- */
-@Configuration
-@EnableTransactionManagement
-public class HibernateConfig{
-
- private Logger log=LogManager.getLogger();
-
- @Value("${hibernate.dialect}")
- private String dialect;
- @Value("${hibernate.connection.driver_class}")
- private String driver;
- @Value("${hibernate.connection.url}")
- private String url;
- @Value("${hibernate.connection.username}")
- private String username;
- @Value("${hibernate.connection.password}")
- private String password;
- @Value("${sessionFactory.scan:web.model}")
- private String packagesToScan[];
-
- public static LocalSessionFactoryBean sessionFactoryBean;
-
- private DruidDataSource druidDataSource(){
- DruidDataSource dataSource=new DruidDataSource();
- dataSource.setUrl(url);
- dataSource.setUsername(username);
- dataSource.setPassword(password);
- dataSource.setDriverClassName(driver);
- return dataSource;
- }
-
- @PostConstruct
- private void init() throws IOException {
- log.info("数据库配置初始化\nurl="+url+"\nusername="+username+"\npassword="+password);
- sessionFactoryBean=new LocalSessionFactoryBean();
- Properties properties=new Properties();
- properties.setProperty("hibernate.dialect",dialect);
- sessionFactoryBean.setHibernateProperties(properties);
- sessionFactoryBean.setDataSource(druidDataSource());
- sessionFactoryBean.setPackagesToScan(packagesToScan);
- sessionFactoryBean.afterPropertiesSet();
- }
-
- @Bean
- public SessionFactory sessionFactory(){
- return sessionFactoryBean.getObject();
- }
-
-
- @Bean("transactionManager")
- public HibernateTransactionManager hibernateTransactionManager() {
- HibernateTransactionManager hibernateTransactionManager=new HibernateTransactionManager();
- hibernateTransactionManager.setSessionFactory(sessionFactory());
- return hibernateTransactionManager;
- }
-
-
-
-
-}
diff --git a/core/src/main/java/core/dao/BaseDao.java b/core/src/main/java/core/dao/BaseDao1.java
similarity index 74%
rename from core/src/main/java/core/dao/BaseDao.java
rename to core/src/main/java/core/dao/BaseDao1.java
index d477543..e20edcb 100644
--- a/core/src/main/java/core/dao/BaseDao.java
+++ b/core/src/main/java/core/dao/BaseDao1.java
@@ -1,11 +1,12 @@
package core.dao;
-import core.model.AbstractModel;
+import db.model.AbstractModel;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
import java.io.Serializable;
@@ -14,11 +15,11 @@ import java.io.Serializable;
*/
@Repository
-public class BaseDao extends HibernateTemplate{
+public class BaseDao1 extends HibernateTemplate{
@Autowired
- public BaseDao(SessionFactory sessionFactory) {
- super(sessionFactory);
+ public BaseDao1(SessionFactory aliyun) {
+ super(aliyun);
}
public void delete(Class tClass, Serializable key) throws DataAccessException {
diff --git a/core/src/main/java/core/dao/BaseDao2.java b/core/src/main/java/core/dao/BaseDao2.java
new file mode 100644
index 0000000..e7fd30c
--- /dev/null
+++ b/core/src/main/java/core/dao/BaseDao2.java
@@ -0,0 +1,26 @@
+package core.dao;
+
+import db.model.AbstractModel;
+import org.hibernate.SessionFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.DataAccessException;
+import org.springframework.orm.hibernate5.HibernateTemplate;
+import org.springframework.stereotype.Repository;
+
+import java.io.Serializable;
+
+@Repository
+public class BaseDao2 extends HibernateTemplate {
+
+ @Autowired
+ public BaseDao2(SessionFactory huaWeiCloud) {
+ super(huaWeiCloud);
+ }
+
+ public void delete(Class tClass, Serializable key) throws DataAccessException {
+ T model = load(tClass, key);
+ if (model != null) {
+ delete(model);
+ }
+ }
+}
diff --git a/core/src/main/java/core/service/BaseService.java b/core/src/main/java/core/service/BaseService.java
index f38b369..643394b 100644
--- a/core/src/main/java/core/service/BaseService.java
+++ b/core/src/main/java/core/service/BaseService.java
@@ -1,8 +1,8 @@
package core.service;
-import core.dao.BaseDao;
-import core.model.AbstractModel;
+import core.dao.BaseDao1;
import core.util.DBAction;
+import db.model.AbstractModel;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;
@@ -18,7 +18,7 @@ public class BaseService {
protected Logger log=LogManager.getLogger();
@Resource
- private BaseDao baseDao;
+ private BaseDao1 baseDao;
public String curd(DBAction action, T command) {
Class tClass = (Class) command.getClass();
diff --git a/db/pom.xml b/db/pom.xml
new file mode 100644
index 0000000..3820860
--- /dev/null
+++ b/db/pom.xml
@@ -0,0 +1,63 @@
+
+
+
+ Webcrawler
+ org.pqh
+ 1.0-SNAPSHOT
+
+ 4.0.0
+
+ db
+ jar
+ core Maven Webapp
+ https://gitee.com/WuXianChaoPin/webCrawler
+
+
+
+ org.apache.logging.log4j
+ log4j-api
+
+
+
+ org.apache.logging.log4j
+ log4j-core
+
+
+
+ org.apache.logging.log4j
+ log4j-web
+
+
+
+ com.fasterxml.jackson.core
+ jackson-databind
+
+
+
+ org.hibernate
+ hibernate-core
+
+
+
+ org.springframework
+ spring-web
+
+
+
+ org.springframework
+ spring-webmvc
+
+
+
+ org.springframework
+ spring-orm
+
+
+
+ com.alibaba
+ druid
+
+
+
\ No newline at end of file
diff --git a/db/src/main/java/db/config/HibernateConfig.java b/db/src/main/java/db/config/HibernateConfig.java
new file mode 100644
index 0000000..bb9dc9c
--- /dev/null
+++ b/db/src/main/java/db/config/HibernateConfig.java
@@ -0,0 +1,117 @@
+package db.config;
+
+import com.alibaba.druid.pool.DruidDataSource;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.hibernate.SessionFactory;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.orm.hibernate5.HibernateTransactionManager;
+import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+
+import javax.annotation.PostConstruct;
+import javax.sql.DataSource;
+import java.io.IOException;
+import java.util.Properties;
+
+/**
+ * Created by reborn on 2017/7/28.
+ */
+public class HibernateConfig{
+
+ private Logger log=LogManager.getLogger();
+
+ @Value("${hibernate.dialect}")
+ private String dialect;
+ @Value("${hibernate.connection.driver_class}")
+ private String driver;
+
+ @Value("${hibernate.connection.url}")
+ private String url;
+ @Value("${hibernate.connection.username}")
+ private String username;
+ @Value("${hibernate.connection.password}")
+ private String password;
+
+ @Value("${hibernate.connection.url2}")
+ private String url2;
+ @Value("${hibernate.connection.username2}")
+ private String username2;
+ @Value("${hibernate.connection.password2}")
+ private String password2;
+
+ @Value("${sessionFactory.scan}")
+ private String packagesToScan[];
+
+
+
+ private LocalSessionFactoryBean aliyun = new LocalSessionFactoryBean();
+
+ private LocalSessionFactoryBean huaWeiCloud = new LocalSessionFactoryBean();
+
+ private MyEmptyInterceptor interceptor =new MyEmptyInterceptor();
+
+ private DruidDataSource dataSource(String url,String username,String password){
+ DruidDataSource dataSource=new DruidDataSource();
+ dataSource.setUrl(url);
+ dataSource.setUsername(username);
+ dataSource.setPassword(password);
+ dataSource.setDriverClassName(driver);
+ log.info("数据源初始化\nurl="+url+"\nusername="+username+"\npassword="+password);
+ return dataSource;
+ }
+
+
+
+ @PostConstruct
+ private void init() {
+ initSessionFactory(aliyun,dataSource(url,username,password));
+ initSessionFactory(huaWeiCloud,dataSource(url2,username2,password2));
+ }
+
+ private void initSessionFactory(LocalSessionFactoryBean bean, DataSource dataSource){
+ Properties properties=new Properties();
+ properties.setProperty("hibernate.dialect",dialect);
+ properties.setProperty("hibernate.format_sql","true");
+ bean.setHibernateProperties(properties);
+ bean.setDataSource(dataSource);
+ bean.setPackagesToScan(packagesToScan);
+ bean.setEntityInterceptor(interceptor);
+ try {
+ bean.afterPropertiesSet();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Bean("aliyun")
+ public SessionFactory aliyun(){
+ return aliyun.getObject();
+ }
+
+
+ @Bean("huaWeiCloud")
+ public SessionFactory huaWeiCloud(){
+ return huaWeiCloud.getObject();
+ }
+
+ @Bean("transactionManager1")
+ public HibernateTransactionManager aliyunTransaction() {
+ HibernateTransactionManager hibernateTransactionManager=new HibernateTransactionManager();
+ hibernateTransactionManager.setSessionFactory(aliyun());
+ return hibernateTransactionManager;
+ }
+
+ @Bean("transactionManager2")
+ public HibernateTransactionManager huaweiTransaction() {
+ HibernateTransactionManager hibernateTransactionManager=new HibernateTransactionManager();
+ hibernateTransactionManager.setSessionFactory(huaWeiCloud());
+ return hibernateTransactionManager;
+ }
+
+
+
+
+}
diff --git a/db/src/main/java/db/config/MyEmptyInterceptor.java b/db/src/main/java/db/config/MyEmptyInterceptor.java
new file mode 100644
index 0000000..76f522c
--- /dev/null
+++ b/db/src/main/java/db/config/MyEmptyInterceptor.java
@@ -0,0 +1,30 @@
+package db.config;
+
+
+import db.model.DataModel;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.hibernate.EmptyInterceptor;
+import org.hibernate.type.Type;
+
+
+import java.io.Serializable;
+
+public class MyEmptyInterceptor extends EmptyInterceptor {
+ private Logger log=LogManager.getLogger();
+
+ @Override
+ public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
+ if(entity instanceof DataModel){
+ DataModel dataModel= (DataModel) entity;
+ log.info(dataModel);
+ }
+ return true;
+ }
+
+ @Override
+ public String onPrepareStatement(String sql) {
+// log.info(sql);
+ return super.onPrepareStatement(sql);
+ }
+}
diff --git a/core/src/main/java/core/model/AbstractModel.java b/db/src/main/java/db/model/AbstractModel.java
similarity index 97%
rename from core/src/main/java/core/model/AbstractModel.java
rename to db/src/main/java/db/model/AbstractModel.java
index 848aab9..2aced40 100644
--- a/core/src/main/java/core/model/AbstractModel.java
+++ b/db/src/main/java/db/model/AbstractModel.java
@@ -1,4 +1,4 @@
-package core.model;
+package db.model;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
diff --git a/web/src/main/java/web/model/CidEntity.java b/db/src/main/java/db/model/CidEntity.java
similarity index 99%
rename from web/src/main/java/web/model/CidEntity.java
rename to db/src/main/java/db/model/CidEntity.java
index f375f61..a0cd8b9 100644
--- a/web/src/main/java/web/model/CidEntity.java
+++ b/db/src/main/java/db/model/CidEntity.java
@@ -1,6 +1,4 @@
-package web.model;
-
-import core.model.AbstractModel;
+package db.model;
import javax.persistence.*;
import java.io.Serializable;
diff --git a/web/src/main/java/web/model/DataEntity.java b/db/src/main/java/db/model/DataModel.java
similarity index 73%
rename from web/src/main/java/web/model/DataEntity.java
rename to db/src/main/java/db/model/DataModel.java
index 6855e7d..5a91574 100644
--- a/web/src/main/java/web/model/DataEntity.java
+++ b/db/src/main/java/db/model/DataModel.java
@@ -1,6 +1,4 @@
-package web.model;
-
-import core.model.AbstractModel;
+package db.model;
import javax.persistence.*;
import java.io.Serializable;
@@ -8,37 +6,37 @@ import java.util.Objects;
@Entity
@Table(name = "data", schema = "bilibili", catalog = "")
-public class DataEntity extends AbstractModel {
+public class DataModel extends AbstractModel {
private int cid;
private Integer aid;
- private Byte dpDoneMp4;
- private String letvVu;
- private Byte dpDoneFlv;
- private Integer uploadMeta;
- private String type;
- private Integer vp;
- private Integer upload;
private String author;
+ private String backupVid;
+ private String cache;
private String cover;
- private String title;
- private Integer page;
private Integer dispatch;
- private String vid;
- private String backupVid;
- private Integer files;
private Integer dispatchServers;
- private String cache;
- private Integer storageServer;
private Byte dpDone;
- private Double duration;
- private Integer mid;
+ private Byte dpDoneFlv;
private Byte dpDoneHdmp4;
+ private Byte dpDoneMp4;
+ private Double duration;
+ private Integer files;
+ private String letvAddr;
private Integer letvVid;
+ private String letvVu;
+ private Integer mid;
+ private Integer page;
private Integer storage;
- private String letvAddr;
+ private Integer storageServer;
private String subtitle;
+ private String title;
+ private String type;
+ private Integer upload;
+ private Integer uploadMeta;
+ private String vid;
+ private Integer vp;
+ private Integer typeId;
- private CidEntity cidEntity;
@Id
@Column(name = "cid")
public int getCid() {
@@ -60,173 +58,183 @@ public class DataEntity extends AbstractModel {
}
@Basic
- @Column(name = "dp_done_mp4")
- public Byte getDpDoneMp4() {
- return dpDoneMp4;
+ @Column(name = "author")
+ public String getAuthor() {
+ return author;
}
- public void setDpDoneMp4(Byte dpDoneMp4) {
- this.dpDoneMp4 = dpDoneMp4;
+ public void setAuthor(String author) {
+ this.author = author;
}
@Basic
- @Column(name = "letv_vu")
- public String getLetvVu() {
- return letvVu;
+ @Column(name = "backup_vid")
+ public String getBackupVid() {
+ return backupVid;
}
- public void setLetvVu(String letvVu) {
- this.letvVu = letvVu;
+ public void setBackupVid(String backupVid) {
+ this.backupVid = backupVid;
}
@Basic
- @Column(name = "dp_done_flv")
- public Byte getDpDoneFlv() {
- return dpDoneFlv;
+ @Column(name = "cache")
+ public String getCache() {
+ return cache;
}
- public void setDpDoneFlv(Byte dpDoneFlv) {
- this.dpDoneFlv = dpDoneFlv;
+ public void setCache(String cache) {
+ this.cache = cache;
}
@Basic
- @Column(name = "upload_meta")
- public Integer getUploadMeta() {
- return uploadMeta;
+ @Column(name = "cover")
+ public String getCover() {
+ return cover;
}
- public void setUploadMeta(Integer uploadMeta) {
- this.uploadMeta = uploadMeta;
+ public void setCover(String cover) {
+ this.cover = cover;
}
@Basic
- @Column(name = "type")
- public String getType() {
- return type;
+ @Column(name = "dispatch")
+ public Integer getDispatch() {
+ return dispatch;
}
- public void setType(String type) {
- this.type = type;
+ public void setDispatch(Integer dispatch) {
+ this.dispatch = dispatch;
}
@Basic
- @Column(name = "vp")
- public Integer getVp() {
- return vp;
+ @Column(name = "dispatch_servers")
+ public Integer getDispatchServers() {
+ return dispatchServers;
}
- public void setVp(Integer vp) {
- this.vp = vp;
+ public void setDispatchServers(Integer dispatchServers) {
+ this.dispatchServers = dispatchServers;
}
@Basic
- @Column(name = "upload")
- public Integer getUpload() {
- return upload;
+ @Column(name = "dp_done")
+ public Byte getDpDone() {
+ return dpDone;
}
- public void setUpload(Integer upload) {
- this.upload = upload;
+ public void setDpDone(Byte dpDone) {
+ this.dpDone = dpDone;
}
@Basic
- @Column(name = "author")
- public String getAuthor() {
- return author;
+ @Column(name = "dp_done_flv")
+ public Byte getDpDoneFlv() {
+ return dpDoneFlv;
}
- public void setAuthor(String author) {
- this.author = author;
+ public void setDpDoneFlv(Byte dpDoneFlv) {
+ this.dpDoneFlv = dpDoneFlv;
}
@Basic
- @Column(name = "cover")
- public String getCover() {
- return cover;
+ @Column(name = "dp_done_hdmp4")
+ public Byte getDpDoneHdmp4() {
+ return dpDoneHdmp4;
}
- public void setCover(String cover) {
- this.cover = cover;
+ public void setDpDoneHdmp4(Byte dpDoneHdmp4) {
+ this.dpDoneHdmp4 = dpDoneHdmp4;
}
@Basic
- @Column(name = "title")
- public String getTitle() {
- return title;
+ @Column(name = "dp_done_mp4")
+ public Byte getDpDoneMp4() {
+ return dpDoneMp4;
}
- public void setTitle(String title) {
- this.title = title;
+ public void setDpDoneMp4(Byte dpDoneMp4) {
+ this.dpDoneMp4 = dpDoneMp4;
}
@Basic
- @Column(name = "page")
- public Integer getPage() {
- return page;
+ @Column(name = "duration")
+ public Double getDuration() {
+ return duration;
}
- public void setPage(Integer page) {
- this.page = page;
+ public void setDuration(Double duration) {
+ this.duration = duration;
}
@Basic
- @Column(name = "dispatch")
- public Integer getDispatch() {
- return dispatch;
+ @Column(name = "files")
+ public Integer getFiles() {
+ return files;
}
- public void setDispatch(Integer dispatch) {
- this.dispatch = dispatch;
+ public void setFiles(Integer files) {
+ this.files = files;
}
@Basic
- @Column(name = "vid")
- public String getVid() {
- return vid;
+ @Column(name = "letv_addr")
+ public String getLetvAddr() {
+ return letvAddr;
}
- public void setVid(String vid) {
- this.vid = vid;
+ public void setLetvAddr(String letvAddr) {
+ this.letvAddr = letvAddr;
}
@Basic
- @Column(name = "backup_vid")
- public String getBackupVid() {
- return backupVid;
+ @Column(name = "letv_vid")
+ public Integer getLetvVid() {
+ return letvVid;
}
- public void setBackupVid(String backupVid) {
- this.backupVid = backupVid;
+ public void setLetvVid(Integer letvVid) {
+ this.letvVid = letvVid;
}
@Basic
- @Column(name = "files")
- public Integer getFiles() {
- return files;
+ @Column(name = "letv_vu")
+ public String getLetvVu() {
+ return letvVu;
}
- public void setFiles(Integer files) {
- this.files = files;
+ public void setLetvVu(String letvVu) {
+ this.letvVu = letvVu;
}
@Basic
- @Column(name = "dispatch_servers")
- public Integer getDispatchServers() {
- return dispatchServers;
+ @Column(name = "mid")
+ public Integer getMid() {
+ return mid;
}
- public void setDispatchServers(Integer dispatchServers) {
- this.dispatchServers = dispatchServers;
+ public void setMid(Integer mid) {
+ this.mid = mid;
}
@Basic
- @Column(name = "cache")
- public String getCache() {
- return cache;
+ @Column(name = "page")
+ public Integer getPage() {
+ return page;
}
- public void setCache(String cache) {
- this.cache = cache;
+ public void setPage(Integer page) {
+ this.page = page;
+ }
+
+ @Basic
+ @Column(name = "storage")
+ public Integer getStorage() {
+ return storage;
+ }
+
+ public void setStorage(Integer storage) {
+ this.storage = storage;
}
@Basic
@@ -240,134 +248,125 @@ public class DataEntity extends AbstractModel {
}
@Basic
- @Column(name = "dp_done")
- public Byte getDpDone() {
- return dpDone;
+ @Column(name = "subtitle")
+ public String getSubtitle() {
+ return subtitle;
}
- public void setDpDone(Byte dpDone) {
- this.dpDone = dpDone;
+ public void setSubtitle(String subtitle) {
+ this.subtitle = subtitle;
}
@Basic
- @Column(name = "duration")
- public Double getDuration() {
- return duration;
+ @Column(name = "title")
+ public String getTitle() {
+ return title;
}
- public void setDuration(Double duration) {
- this.duration = duration;
+ public void setTitle(String title) {
+ this.title = title;
}
@Basic
- @Column(name = "mid")
- public Integer getMid() {
- return mid;
+ @Column(name = "type")
+ public String getType() {
+ return type;
}
- public void setMid(Integer mid) {
- this.mid = mid;
+ public void setType(String type) {
+ this.type = type;
}
@Basic
- @Column(name = "dp_done_hdmp4")
- public Byte getDpDoneHdmp4() {
- return dpDoneHdmp4;
+ @Column(name = "upload")
+ public Integer getUpload() {
+ return upload;
}
- public void setDpDoneHdmp4(Byte dpDoneHdmp4) {
- this.dpDoneHdmp4 = dpDoneHdmp4;
+ public void setUpload(Integer upload) {
+ this.upload = upload;
}
@Basic
- @Column(name = "letv_vid")
- public Integer getLetvVid() {
- return letvVid;
+ @Column(name = "upload_meta")
+ public Integer getUploadMeta() {
+ return uploadMeta;
}
- public void setLetvVid(Integer letvVid) {
- this.letvVid = letvVid;
+ public void setUploadMeta(Integer uploadMeta) {
+ this.uploadMeta = uploadMeta;
}
@Basic
- @Column(name = "storage")
- public Integer getStorage() {
- return storage;
+ @Column(name = "vid")
+ public String getVid() {
+ return vid;
}
- public void setStorage(Integer storage) {
- this.storage = storage;
+ public void setVid(String vid) {
+ this.vid = vid;
}
@Basic
- @Column(name = "letv_addr")
- public String getLetvAddr() {
- return letvAddr;
+ @Column(name = "vp")
+ public Integer getVp() {
+ return vp;
}
- public void setLetvAddr(String letvAddr) {
- this.letvAddr = letvAddr;
+ public void setVp(Integer vp) {
+ this.vp = vp;
}
@Basic
- @Column(name = "subtitle")
- public String getSubtitle() {
- return subtitle;
- }
-
- public void setSubtitle(String subtitle) {
- this.subtitle = subtitle;
- }
-
- @OneToOne
- @JoinColumn(name = "cid")
- public CidEntity getCidEntity() {
- return cidEntity;
+ @Column(name = "type_id")
+ public Integer getTypeId() {
+ return typeId;
}
- public void setCidEntity(CidEntity cidEntity) {
- this.cidEntity = cidEntity;
+ public void setTypeId(Integer typeId) {
+ this.typeId = typeId;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
- DataEntity that = (DataEntity) o;
- return cid == that.cid &&
- Objects.equals(aid, that.aid) &&
- Objects.equals(dpDoneMp4, that.dpDoneMp4) &&
- Objects.equals(letvVu, that.letvVu) &&
- Objects.equals(dpDoneFlv, that.dpDoneFlv) &&
- Objects.equals(uploadMeta, that.uploadMeta) &&
- Objects.equals(type, that.type) &&
- Objects.equals(vp, that.vp) &&
- Objects.equals(upload, that.upload) &&
- Objects.equals(author, that.author) &&
- Objects.equals(cover, that.cover) &&
- Objects.equals(title, that.title) &&
- Objects.equals(page, that.page) &&
- Objects.equals(dispatch, that.dispatch) &&
- Objects.equals(vid, that.vid) &&
- Objects.equals(backupVid, that.backupVid) &&
- Objects.equals(files, that.files) &&
- Objects.equals(dispatchServers, that.dispatchServers) &&
- Objects.equals(cache, that.cache) &&
- Objects.equals(storageServer, that.storageServer) &&
- Objects.equals(dpDone, that.dpDone) &&
- Objects.equals(duration, that.duration) &&
- Objects.equals(mid, that.mid) &&
- Objects.equals(dpDoneHdmp4, that.dpDoneHdmp4) &&
- Objects.equals(letvVid, that.letvVid) &&
- Objects.equals(storage, that.storage) &&
- Objects.equals(letvAddr, that.letvAddr) &&
- Objects.equals(subtitle, that.subtitle);
+ DataModel dataModel = (DataModel) o;
+ return cid == dataModel.cid &&
+ Objects.equals(aid, dataModel.aid) &&
+ Objects.equals(author, dataModel.author) &&
+ Objects.equals(backupVid, dataModel.backupVid) &&
+ Objects.equals(cache, dataModel.cache) &&
+ Objects.equals(cover, dataModel.cover) &&
+ Objects.equals(dispatch, dataModel.dispatch) &&
+ Objects.equals(dispatchServers, dataModel.dispatchServers) &&
+ Objects.equals(dpDone, dataModel.dpDone) &&
+ Objects.equals(dpDoneFlv, dataModel.dpDoneFlv) &&
+ Objects.equals(dpDoneHdmp4, dataModel.dpDoneHdmp4) &&
+ Objects.equals(dpDoneMp4, dataModel.dpDoneMp4) &&
+ Objects.equals(duration, dataModel.duration) &&
+ Objects.equals(files, dataModel.files) &&
+ Objects.equals(letvAddr, dataModel.letvAddr) &&
+ Objects.equals(letvVid, dataModel.letvVid) &&
+ Objects.equals(letvVu, dataModel.letvVu) &&
+ Objects.equals(mid, dataModel.mid) &&
+ Objects.equals(page, dataModel.page) &&
+ Objects.equals(storage, dataModel.storage) &&
+ Objects.equals(storageServer, dataModel.storageServer) &&
+ Objects.equals(subtitle, dataModel.subtitle) &&
+ Objects.equals(title, dataModel.title) &&
+ Objects.equals(type, dataModel.type) &&
+ Objects.equals(upload, dataModel.upload) &&
+ Objects.equals(uploadMeta, dataModel.uploadMeta) &&
+ Objects.equals(vid, dataModel.vid) &&
+ Objects.equals(vp, dataModel.vp) &&
+ Objects.equals(typeId, dataModel.typeId);
}
@Override
public int hashCode() {
- return Objects.hash(cid, aid, dpDoneMp4, letvVu, dpDoneFlv, uploadMeta, type, vp, upload, author, cover, title, page, dispatch, vid, backupVid, files, dispatchServers, cache, storageServer, dpDone, duration, mid, dpDoneHdmp4, letvVid, storage, letvAddr, subtitle);
+ return Objects.hash(cid, aid, author, backupVid, cache, cover, dispatch, dispatchServers, dpDone, dpDoneFlv, dpDoneHdmp4, dpDoneMp4, duration, files, letvAddr, letvVid, letvVu, mid, page, storage, storageServer, subtitle, title, type, upload, uploadMeta, vid, vp, typeId);
}
@Override
diff --git a/web/src/main/java/web/model/ScheduledTaskEntity.java b/db/src/main/java/db/model/ScheduledTaskEntity.java
similarity index 98%
rename from web/src/main/java/web/model/ScheduledTaskEntity.java
rename to db/src/main/java/db/model/ScheduledTaskEntity.java
index eb76236..ea4c62f 100644
--- a/web/src/main/java/web/model/ScheduledTaskEntity.java
+++ b/db/src/main/java/db/model/ScheduledTaskEntity.java
@@ -1,6 +1,4 @@
-package web.model;
-
-import core.model.AbstractModel;
+package db.model;
import javax.persistence.*;
import java.io.Serializable;
diff --git a/web/src/main/java/web/model/TaskEntity.java b/db/src/main/java/db/model/TaskEntity.java
similarity index 95%
rename from web/src/main/java/web/model/TaskEntity.java
rename to db/src/main/java/db/model/TaskEntity.java
index 7e9f8b3..5132119 100644
--- a/web/src/main/java/web/model/TaskEntity.java
+++ b/db/src/main/java/db/model/TaskEntity.java
@@ -1,6 +1,4 @@
-package web.model;
-
-import core.model.AbstractModel;
+package db.model;
import javax.persistence.*;
import java.io.Serializable;
diff --git a/pom.xml b/pom.xml
index 6b58bd4..691915b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -8,6 +8,7 @@
core
web
+ db
Webcrawler Maven Webapp
https://gitee.com/WuXianChaoPin/WebCrawler
@@ -26,6 +27,7 @@
RELEASE
RELEASE
RELEASE
+ RELEASE
@@ -108,6 +110,12 @@
${druid.version}
+
+ org.apache.commons
+ commons-lang3
+ ${lang3.version}
+
+
diff --git a/web/pom.xml b/web/pom.xml
index 4a22576..ee9121d 100644
--- a/web/pom.xml
+++ b/web/pom.xml
@@ -87,11 +87,6 @@
commons-io
-
- com.alibaba
- druid
-
-
javax.servlet
javax.servlet-api
diff --git a/web/src/main/java/web/config/AbstractWebConfig.java b/web/src/main/java/web/config/AbstractWebConfig.java
index b22bcf9..591aa45 100644
--- a/web/src/main/java/web/config/AbstractWebConfig.java
+++ b/web/src/main/java/web/config/AbstractWebConfig.java
@@ -23,7 +23,7 @@ public class AbstractWebConfig extends AbstractAnnotationConfigDispatcherServlet
@Override
protected Class>[] getRootConfigClasses() {
- return new Class[]{SpringConfig.class};
+ return new Class[]{AppConfig.class};
}
@Override
@@ -39,9 +39,6 @@ public class AbstractWebConfig extends AbstractAnnotationConfigDispatcherServlet
FilterRegistration.Dynamic characterEncodingFilter=super.registerServletFilter(servletContext,new CharacterEncodingFilter(encoding));
characterEncodingFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST),true,"/*");
- FilterRegistration.Dynamic openSessionInViewFilter=super.registerServletFilter(servletContext,new OpenSessionInViewFilter());
- openSessionInViewFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST),true,"/*");
-
ServletRegistration.Dynamic servlet=servletContext.addServlet("DruidStatView", StatViewServlet.class);
servlet.addMapping("/druid/*");
diff --git a/web/src/main/java/web/config/AppConfig.java b/web/src/main/java/web/config/AppConfig.java
new file mode 100644
index 0000000..802550e
--- /dev/null
+++ b/web/src/main/java/web/config/AppConfig.java
@@ -0,0 +1,14 @@
+package web.config;
+
+import db.config.HibernateConfig;
+import org.springframework.context.annotation.*;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+
+@Configuration
+@EnableAspectJAutoProxy(proxyTargetClass = true)
+@EnableTransactionManagement
+@PropertySource("classpath:config.properties")
+@ComponentScan({"core"})
+@Import(HibernateConfig.class)
+public class AppConfig {
+}
diff --git a/web/src/main/java/web/config/SpringConfig.java b/web/src/main/java/web/config/SpringConfig.java
index 01a685f..e55490c 100644
--- a/web/src/main/java/web/config/SpringConfig.java
+++ b/web/src/main/java/web/config/SpringConfig.java
@@ -1,7 +1,8 @@
package web.config;
-import core.config.HibernateConfig;
+import core.dao.BaseDao1;
import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.PropertySource;
import org.springframework.orm.hibernate5.support.OpenSessionInViewInterceptor;
@@ -10,16 +11,20 @@ import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+import javax.annotation.Resource;
+
/**
* Created by reborn on 2017/7/28.
*/
+@Configuration
@EnableWebMvc
@PropertySource("classpath:config.properties")
-@ComponentScan({"${spring.scan}"})
-@EnableAspectJAutoProxy(proxyTargetClass = true)
+@ComponentScan({"web.controller"})
public class SpringConfig implements WebMvcConfigurer {
+ @Resource
+ private BaseDao1 baseDao;
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
@@ -30,7 +35,7 @@ public class SpringConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
OpenSessionInViewInterceptor interceptor=new OpenSessionInViewInterceptor();
- interceptor.setSessionFactory(HibernateConfig.sessionFactoryBean.getObject());
+ interceptor.setSessionFactory(baseDao.getSessionFactory());
registry.addWebRequestInterceptor(interceptor);
}
}
diff --git a/web/src/main/java/web/controller/BaseController.java b/web/src/main/java/web/controller/BaseController.java
index 0fb172b..63e9211 100644
--- a/web/src/main/java/web/controller/BaseController.java
+++ b/web/src/main/java/web/controller/BaseController.java
@@ -1,8 +1,8 @@
package web.controller;
-import core.model.AbstractModel;
import core.service.BaseService;
import core.util.DBAction;
+import db.model.AbstractModel;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.bind.annotation.PathVariable;
diff --git a/web/src/main/java/web/controller/CommentController.java b/web/src/main/java/web/controller/CommentController.java
index 362d25e..8a0a09c 100644
--- a/web/src/main/java/web/controller/CommentController.java
+++ b/web/src/main/java/web/controller/CommentController.java
@@ -1,17 +1,11 @@
package web.controller;
+import db.model.DataModel;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
-import web.model.DataEntity;
@Controller
@RequestMapping("/comment")
-public class CommentController extends BaseController{
+public class CommentController extends BaseController{
-
- @RequestMapping(value = "find",produces = "application/json;charset=UTF-8")
- public String get(DataEntity dataEntity){
-
- return "";
- }
}
diff --git a/web/src/main/java/web/util/DynamicTimer.java b/web/src/main/java/web/util/DynamicTimer.java
index 7b3e443..c8c9328 100644
--- a/web/src/main/java/web/util/DynamicTimer.java
+++ b/web/src/main/java/web/util/DynamicTimer.java
@@ -1,6 +1,8 @@
package web.util;
-import core.dao.BaseDao;
+import core.dao.BaseDao1;
+import db.model.ScheduledTaskEntity;
+import db.model.TaskEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
@@ -12,8 +14,6 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.scheduling.config.TriggerTask;
import org.springframework.scheduling.support.CronTrigger;
import org.springframework.stereotype.Component;
-import web.model.ScheduledTaskEntity;
-import web.model.TaskEntity;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
@@ -30,7 +30,7 @@ public class DynamicTimer extends ScheduledTaskRegistrar {
private Logger log=LogManager.getLogger();
@Resource
- private BaseDao baseDao;
+ private BaseDao1 baseDao;
@PostConstruct
public void init(){
diff --git a/web/src/main/resources/config.properties b/web/src/main/resources/config.properties
index b51b7e8..8e1b01b 100644
--- a/web/src/main/resources/config.properties
+++ b/web/src/main/resources/config.properties
@@ -1,16 +1,16 @@
-#-----------------------hibernate-----------------------------
+#-----------------------hibernate\u914D\u7F6E-----------------------------
hibernate.dialect=org.hibernate.dialect.MySQL57Dialect
hibernate.connection.driver_class=com.mysql.cj.jdbc.Driver
-hibernate.connection.url=jdbc:mysql://mikuhime.xyz:3306/bilibili?serverTimezone=UTC
+#\u6570\u636E\u6E901
+hibernate.connection.url=jdbc:mysql://sukura.top:3306/bilibili?serverTimezone=UTC&useSSL=false
hibernate.connection.username=sukura
hibernate.connection.password=@
-#Դ2
-hibernate.dialect2=org.hibernate.dialect.MySQL57Dialect
-hibernate.connection.driver_class2=com.mysql.cj.jdbc.Driver
-hibernate.connection.url2=jdbc:mysql://mikuhime.xyz:3306/bilibili?serverTimezone=UTC
+#\u6570\u636E\u6E902
+hibernate.connection.url2=jdbc:mysql://mysql.sukura.top:8635/bilibili?serverTimezone=UTC&useSSL=false
hibernate.connection.username2=sukura
-hibernate.connection.password2=@
-#-----------------------DruidDataSource-----------------------
+hibernate.connection.password2=Luffy9412!
+#-----------------------DruidDataSource\u914D\u7F6E-----------------------
druid.maxActive=20
-spring.scan=core,web
\ No newline at end of file
+spring.scan=core,web,db
+sessionFactory.scan=db.model
\ No newline at end of file
diff --git a/web/src/main/resources/log4j2.xml b/web/src/main/resources/log4j2.xml
index 3957516..cecb423 100644
--- a/web/src/main/resources/log4j2.xml
+++ b/web/src/main/resources/log4j2.xml
@@ -16,9 +16,12 @@
-
+
+
+
+
diff --git a/web/src/test/java/SpringTest.java b/web/src/test/java/SpringTest.java
new file mode 100644
index 0000000..0e05e5d
--- /dev/null
+++ b/web/src/test/java/SpringTest.java
@@ -0,0 +1,144 @@
+import core.dao.BaseDao1;
+import core.dao.BaseDao2;
+import db.model.CidEntity;
+import db.model.DataModel;
+import db.model.TaskEntity;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.hibernate.Session;
+import org.hibernate.boot.Metadata;
+import org.hibernate.boot.MetadataSources;
+import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
+import org.hibernate.criterion.DetachedCriteria;
+import org.hibernate.criterion.Projections;
+import org.hibernate.service.ServiceRegistry;
+import org.hibernate.tool.hbm2ddl.SchemaExport;
+import org.hibernate.tool.schema.TargetType;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.BeanUtils;
+import org.springframework.dao.DataAccessException;
+import org.springframework.test.annotation.Rollback;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.transaction.annotation.Transactional;
+import web.config.AppConfig;
+import web.config.SpringConfig;
+
+import javax.annotation.Resource;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.EnumSet;
+import java.util.List;
+
+//让测试运行于Spring环境
+@RunWith(SpringJUnit4ClassRunner.class)
+@SpringJUnitWebConfig
+@ContextConfiguration(classes = {AppConfig.class})
+public class SpringTest {
+ private Logger log=LogManager.getLogger();
+
+ @Resource
+ private BaseDao1 baseDao1;
+
+ @Resource
+ private BaseDao2 baseDao2;
+
+
+ @Test
+ @Transactional("transactionManager2")
+ @Rollback(false)
+ public void test1(){
+ DataModel dataModel=new DataModel();
+ dataModel.setCid(333);
+ TaskEntity taskEntity=new TaskEntity();
+ taskEntity.setApi("fdsfsdf");
+ baseDao2.save(dataModel);
+ }
+
+ @Test
+ @Transactional("transactionManager2")
+ @Rollback(false)
+ public void test(){
+// for (int id=1;id<10;id++){
+ int id=103;
+ DataModel dataModel=baseDao1.get(DataModel.class,id);
+ CidEntity cidEntity=baseDao1.get(CidEntity.class,id);
+ if(dataModel!=null&&cidEntity!=null){
+ dataModel.setTypeId(cidEntity.getTypeid());
+ try {
+ log.info(baseDao2.save(dataModel));
+ }catch (DataAccessException e){
+ log.error(e);
+ }
+ }
+
+
+// }
+ }
+
+// @Test
+ public void exportTableSql(){
+ ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(baseDao1.getSessionFactory().getProperties()).build();
+ Metadata metadata = new MetadataSources(serviceRegistry).addAnnotatedClass(DataModel.class).buildMetadata();
+ SchemaExport schemaExport = new SchemaExport();
+ schemaExport.setOutputFile("test.sql");
+ schemaExport.setFormat(true);
+ schemaExport.create(EnumSet.of(TargetType.SCRIPT), metadata);
+
+
+ List typeid= (List) baseDao1.findByCriteria(DetachedCriteria.forClass(CidEntity.class).setProjection(Projections.groupProperty("typeid")));
+
+ List tableNames=new ArrayList<>();
+ StringBuffer sb=new StringBuffer();
+ for(Integer id:typeid){
+ String tableName="data_"+id;
+ sb.append("create table "+tableName+" like data_1;\n");
+ tableNames.add(tableName);
+ }
+
+ sb.append("create table data (\n" +
+ " cid integer not null,\n" +
+ " aid integer,\n" +
+ " author varchar(255),\n" +
+ " backup_vid varchar(255),\n" +
+ " cache varchar(255),\n" +
+ " cover varchar(255),\n" +
+ " dispatch integer,\n" +
+ " dispatch_servers integer,\n" +
+ " dp_done tinyint,\n" +
+ " dp_done_flv tinyint,\n" +
+ " dp_done_hdmp4 tinyint,\n" +
+ " dp_done_mp4 tinyint,\n" +
+ " duration double precision,\n" +
+ " files integer,\n" +
+ " letv_addr varchar(255),\n" +
+ " letv_vid integer,\n" +
+ " letv_vu varchar(255),\n" +
+ " mid integer,\n" +
+ " page integer,\n" +
+ " storage integer,\n" +
+ " storage_server integer,\n" +
+ " subtitle varchar(255),\n" +
+ " title varchar(255),\n" +
+ " type varchar(255),\n" +
+ " upload integer,\n" +
+ " upload_meta integer,\n" +
+ " vid varchar(255),\n" +
+ " vp integer,\n" +
+ " type_id integer,\n" +
+ " primary key (cid)\n" +
+ " ) engine=MERGE UNION=("+StringUtils.join(tableNames,",")+") insert_method=no;");
+
+
+ try {
+ FileUtils.writeStringToFile(new File("test.sql"),sb.toString(),"utf-8",true);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+}