parent
7a28ff4209
commit
51e82d7d90
@ -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; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} |
|
@ -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); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -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.core.JsonProcessingException; |
||||||
import com.fasterxml.jackson.databind.ObjectMapper; |
import com.fasterxml.jackson.databind.ObjectMapper; |
@ -1,6 +1,4 @@ |
|||||||
package web.model; |
package db.model; |
||||||
|
|
||||||
import core.model.AbstractModel; |
|
||||||
|
|
||||||
import javax.persistence.*; |
import javax.persistence.*; |
||||||
import java.io.Serializable; |
import java.io.Serializable; |
@ -1,6 +1,4 @@ |
|||||||
package web.model; |
package db.model; |
||||||
|
|
||||||
import core.model.AbstractModel; |
|
||||||
|
|
||||||
import javax.persistence.*; |
import javax.persistence.*; |
||||||
import java.io.Serializable; |
import java.io.Serializable; |
@ -1,6 +1,4 @@ |
|||||||
package web.model; |
package db.model; |
||||||
|
|
||||||
import core.model.AbstractModel; |
|
||||||
|
|
||||||
import javax.persistence.*; |
import javax.persistence.*; |
||||||
import java.io.Serializable; |
import java.io.Serializable; |
@ -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,17 +1,11 @@ |
|||||||
package web.controller; |
package web.controller; |
||||||
|
|
||||||
|
import db.model.DataModel; |
||||||
import org.springframework.stereotype.Controller; |
import org.springframework.stereotype.Controller; |
||||||
import org.springframework.web.bind.annotation.RequestMapping; |
import org.springframework.web.bind.annotation.RequestMapping; |
||||||
import web.model.DataEntity; |
|
||||||
|
|
||||||
@Controller |
@Controller |
||||||
@RequestMapping("/comment") |
@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,16 +1,16 @@ |
|||||||
#-----------------------hibernate配置----------------------------- |
#-----------------------hibernate\u914D\u7F6E----------------------------- |
||||||
hibernate.dialect=org.hibernate.dialect.MySQL57Dialect |
hibernate.dialect=org.hibernate.dialect.MySQL57Dialect |
||||||
hibernate.connection.driver_class=com.mysql.cj.jdbc.Driver |
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.username=sukura |
||||||
hibernate.connection.password=@ |
hibernate.connection.password=@ |
||||||
#数据源2 |
#\u6570\u636E\u6E902 |
||||||
hibernate.dialect2=org.hibernate.dialect.MySQL57Dialect |
hibernate.connection.url2=jdbc:mysql://mysql.sukura.top:8635/bilibili?serverTimezone=UTC&useSSL=false |
||||||
hibernate.connection.driver_class2=com.mysql.cj.jdbc.Driver |
|
||||||
hibernate.connection.url2=jdbc:mysql://mikuhime.xyz:3306/bilibili?serverTimezone=UTC |
|
||||||
hibernate.connection.username2=sukura |
hibernate.connection.username2=sukura |
||||||
hibernate.connection.password2=@ |
hibernate.connection.password2=Luffy9412! |
||||||
#-----------------------DruidDataSource配置----------------------- |
#-----------------------DruidDataSource\u914D\u7F6E----------------------- |
||||||
druid.maxActive=20 |
druid.maxActive=20 |
||||||
|
|
||||||
spring.scan=core,web |
spring.scan=core,web,db |
||||||
|
sessionFactory.scan=db.model |
@ -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…
Reference in new issue