master
WuXianChaoPin 7 years ago
parent 7a28ff4209
commit 51e82d7d90
  1. 11
      core/pom.xml
  2. 4
      core/src/main/java/core/aop/Advisor.java
  3. 79
      core/src/main/java/core/config/HibernateConfig.java
  4. 9
      core/src/main/java/core/dao/BaseDao1.java
  5. 26
      core/src/main/java/core/dao/BaseDao2.java
  6. 6
      core/src/main/java/core/service/BaseService.java
  7. 63
      db/pom.xml
  8. 117
      db/src/main/java/db/config/HibernateConfig.java
  9. 30
      db/src/main/java/db/config/MyEmptyInterceptor.java
  10. 2
      db/src/main/java/db/model/AbstractModel.java
  11. 4
      db/src/main/java/db/model/CidEntity.java
  12. 373
      db/src/main/java/db/model/DataModel.java
  13. 4
      db/src/main/java/db/model/ScheduledTaskEntity.java
  14. 4
      db/src/main/java/db/model/TaskEntity.java
  15. 8
      pom.xml
  16. 5
      web/pom.xml
  17. 5
      web/src/main/java/web/config/AbstractWebConfig.java
  18. 14
      web/src/main/java/web/config/AppConfig.java
  19. 13
      web/src/main/java/web/config/SpringConfig.java
  20. 2
      web/src/main/java/web/controller/BaseController.java
  21. 10
      web/src/main/java/web/controller/CommentController.java
  22. 8
      web/src/main/java/web/util/DynamicTimer.java
  23. 18
      web/src/main/resources/config.properties
  24. 5
      web/src/main/resources/log4j2.xml
  25. 144
      web/src/test/java/SpringTest.java

@ -80,6 +80,17 @@
<artifactId>druid</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.pqh</groupId>
<artifactId>db</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<finalName>core</finalName>

@ -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

@ -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;
}
}

@ -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 <T extends AbstractModel> void delete(Class<T> tClass, Serializable key) throws DataAccessException {

@ -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 <T extends AbstractModel> void delete(Class<T> tClass, Serializable key) throws DataAccessException {
T model = load(tClass, key);
if (model != null) {
delete(model);
}
}
}

@ -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<T extends AbstractModel> String curd(DBAction action, T command) {
Class<T> tClass = (Class<T>) command.getClass();

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>Webcrawler</artifactId>
<groupId>org.pqh</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>db</artifactId>
<packaging>jar</packaging>
<name>core Maven Webapp</name>
<url>https://gitee.com/WuXianChaoPin/webCrawler</url>
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-web</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</dependency>
</dependencies>
</project>

@ -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;
}
}

@ -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);
}
}

@ -1,4 +1,4 @@
package core.model;
package db.model;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

@ -1,6 +1,4 @@
package web.model;
import core.model.AbstractModel;
package db.model;
import javax.persistence.*;
import java.io.Serializable;

@ -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

@ -1,6 +1,4 @@
package web.model;
import core.model.AbstractModel;
package db.model;
import javax.persistence.*;
import java.io.Serializable;

@ -1,6 +1,4 @@
package web.model;
import core.model.AbstractModel;
package db.model;
import javax.persistence.*;
import java.io.Serializable;

@ -8,6 +8,7 @@
<modules>
<module>core</module>
<module>web</module>
<module>db</module>
</modules>
<name>Webcrawler Maven Webapp</name>
<url>https://gitee.com/WuXianChaoPin/WebCrawler</url>
@ -26,6 +27,7 @@
<log4j.version>RELEASE</log4j.version>
<commons-io.version>RELEASE</commons-io.version>
<druid.version>RELEASE</druid.version>
<lang3.version>RELEASE</lang3.version>
</properties>
<dependencyManagement>
@ -108,6 +110,12 @@
<version>${druid.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${lang3.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

@ -87,11 +87,6 @@
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>

@ -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/*");

@ -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 {
}

@ -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);
}
}

@ -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;

@ -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<DataEntity>{
public class CommentController extends BaseController<DataModel>{
@RequestMapping(value = "find",produces = "application/json;charset=UTF-8")
public String get(DataEntity dataEntity){
return "";
}
}

@ -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(){

@ -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
spring.scan=core,web,db
sessionFactory.scan=db.model

@ -16,9 +16,12 @@
</Appenders>
<Loggers>
<Logger name="test1" level="debug" additivity="false">
<Logger name="test1" level="TRACE" additivity="false">
<AppenderRef ref="STDOUT"/>
</Logger>
<!--<Logger name="org.hibernate.SQL" level="debug" additivity="false">-->
<!--<AppenderRef ref="STDOUT"/>-->
<!--</Logger>-->
<Logger name="test2" level="debug" additivity="false">
<AppenderRef ref="File_debug"/>
</Logger>

@ -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<Integer> typeid= (List<Integer>) baseDao1.findByCriteria(DetachedCriteria.forClass(CidEntity.class).setProjection(Projections.groupProperty("typeid")));
List<String> 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();
}
}
}
Loading…
Cancel
Save