<commit_before>/*		
 * Copyright 2013-4-28 The EGF Co., Ltd. 
 * site: http://www.egfit.com
 * file: $Id: org.eclipse.jdt.ui.prefs,DatabaseServiceImpl.java,fangj Exp$
 * created at:下午01:08:24
 */
package com.egf.db.services.impl;

import org.apache.log4j.Logger;

import com.egf.db.core.CreateTableCallback;
import com.egf.db.core.db.DbFactory;
import com.egf.db.core.db.DbInterface;
import com.egf.db.core.define.ColumnType;
import com.egf.db.core.define.column.ColumnDefine;
import com.egf.db.core.define.column.Comment;
import com.egf.db.core.define.column.Default;
import com.egf.db.core.define.column.NotNull;
import com.egf.db.core.define.column.PrimaryKey;
import com.egf.db.core.define.column.Unique;
import com.egf.db.core.define.name.ColumnName;
import com.egf.db.core.define.name.ForeignKeyName;
import com.egf.db.core.define.name.IndexName;
import com.egf.db.core.define.name.PrimaryKeyName;
import com.egf.db.core.define.name.TableName;
import com.egf.db.core.define.name.UniqueName;
import com.egf.db.core.jdbc.JdbcService;
import com.egf.db.core.jdbc.JdbcServiceImpl;
import com.egf.db.core.sql.template.Generate;
import com.egf.db.core.sql.template.GenerateFactory;
import com.egf.db.exception.MigrationException;
import com.egf.db.services.DatabaseService;
import com.egf.db.utils.StringUtils;

/**
 * @author fangj
 * @version $Revision: 2.0 $
 * @since 1.0
 */
class DatabaseServiceImpl implements DatabaseService{

	Logger logger=Logger.getLogger(DatabaseServiceImpl.class);
	
	private final String PRIMARY_KEY="primary key";
	
	private final String FOREIGN_KEY="foreign key";
	
	private final String UNIQUE_KEY="unique";
	
	private final String NOT_NULL="not null";
	
	private final static String HANDLE_COLUMN_TYPE_ADD="add";
	
	private final static String HANDLE_COLUMN_TYPE_CHANGE="change";
	
	private JdbcService jdbcService=new JdbcServiceImpl();
	
	private Generate generate=GenerateFactory.getGenerate();
	
	//仅仅用来测试
	void setJdbcService(JdbcService jdbcService){
		this.jdbcService = jdbcService;
	}
	
	public void createTable(TableName tableName, Comment comment,CreateTableCallback createTableCallback)throws MigrationException {
		TableImpl tmi=new TableImpl();
		String tableComment="";
		//进行回调操作
		createTableCallback.doCreateAction(tmi);
		StringBuffer columns=tmi.columns;
		columns=columns.delete(columns.length()-2, columns.length());
		String tn=tableName.getName();
		if(tn.indexOf(".")!=-1){
			//创建用户
			DbInterface di=DbFactory.getDb();
			String schema=tn.split("\\.")[0];
			di.createSchema(schema);
		}
		String sql=String.format("create table %s (\n%s\n);",tableName.getName(),columns.toString());
		if(comment!=null){
			tableComment=GenerateFactory.getGenerate().changeTableComment(tableName.getName(),comment.getComment());
		}
		String commentsSql=tmi.comments.toString();
		commentsSql=commentsSql.replaceAll("TN", tableName.getName());
		logger.info("\n"+sql+"\n"+tableComment+commentsSql.toString());
		jdbcService.execute(sql+"\n"+tableComment+commentsSql.toString());
	}
	
	public void createTable(TableName tableName, CreateTableCallback createTableCallback) throws MigrationException{
		createTable(tableName, null, createTableCallback);
	}
	
	public void addColumn(TableName tableName, ColumnName columnName,ColumnType columnType, ColumnDefine... define) throws MigrationException{
		String sql=this.handleColumn(HANDLE_COLUMN_TYPE_ADD, tableName, columnName, columnType, define);
		logger.info("\n"+sql);
		jdbcService.execute(sql);
	}
	
	public void changeColumn(TableName tableName, ColumnName columnName,ColumnDefine... define) throws MigrationException {
		changeColumn(tableName, columnName,null, define);
	}<commit_msg>修改了表日志输出<commit_after>/*		
 * Copyright 2013-4-28 The EGF Co., Ltd. 
 * site: http://www.egfit.com
 * file: $Id: org.eclipse.jdt.ui.prefs,DatabaseServiceImpl.java,fangj Exp$
 * created at:下午01:08:24
 */
package com.egf.db.services.impl;

import org.apache.log4j.Logger;

import com.egf.db.core.CreateTableCallback;
import com.egf.db.core.db.DbFactory;
import com.egf.db.core.db.DbInterface;
import com.egf.db.core.define.ColumnType;
import com.egf.db.core.define.column.ColumnDefine;
import com.egf.db.core.define.column.Comment;
import com.egf.db.core.define.column.Default;
import com.egf.db.core.define.column.NotNull;
import com.egf.db.core.define.column.PrimaryKey;
import com.egf.db.core.define.column.Unique;
import com.egf.db.core.define.name.ColumnName;
import com.egf.db.core.define.name.ForeignKeyName;
import com.egf.db.core.define.name.IndexName;
import com.egf.db.core.define.name.PrimaryKeyName;
import com.egf.db.core.define.name.TableName;
import com.egf.db.core.define.name.UniqueName;
import com.egf.db.core.jdbc.JdbcService;
import com.egf.db.core.jdbc.JdbcServiceImpl;
import com.egf.db.core.sql.template.Generate;
import com.egf.db.core.sql.template.GenerateFactory;
import com.egf.db.exception.MigrationException;
import com.egf.db.services.DatabaseService;
import com.egf.db.utils.StringUtils;

/**
 * @author fangj
 * @version $Revision: 2.0 $
 * @since 1.0
 */
class DatabaseServiceImpl implements DatabaseService{

	Logger logger=Logger.getLogger(DatabaseServiceImpl.class);
	
	private final String PRIMARY_KEY="primary key";
	
	private final String FOREIGN_KEY="foreign key";
	
	private final String UNIQUE_KEY="unique";
	
	private final String NOT_NULL="not null";
	
	private final static String HANDLE_COLUMN_TYPE_ADD="add";
	
	private final static String HANDLE_COLUMN_TYPE_CHANGE="change";
	
	private JdbcService jdbcService=new JdbcServiceImpl();
	
	private Generate generate=GenerateFactory.getGenerate();
	
	//仅仅用来测试
	void setJdbcService(JdbcService jdbcService){
		this.jdbcService = jdbcService;
	}
	
	public void createTable(TableName tableName, Comment comment,CreateTableCallback createTableCallback)throws MigrationException {
		TableImpl tmi=new TableImpl();
		String tableComment="";
		//进行回调操作
		createTableCallback.doCreateAction(tmi);
		StringBuffer columns=tmi.columns;
		columns=columns.delete(columns.length()-2, columns.length());
		String tn=tableName.getName();
		if(tn.indexOf(".")!=-1){
			//创建用户
			DbInterface di=DbFactory.getDb();
			String schema=tn.split("\\.")[0];
			di.createSchema(schema);
		}
		String sql=String.format("create table %s (\n%s\n);",tableName.getName(),columns.toString());
		if(comment!=null){
			tableComment=GenerateFactory.getGenerate().changeTableComment(tableName.getName(),comment.getComment());
		}
		String commentsSql=tmi.comments.toString();
		commentsSql=commentsSql.replaceAll("TN", tableName.getName());
		logger.info("\n"+sql+"\n"+tableComment+"\n"+commentsSql.toString());
		jdbcService.execute(sql+"\n"+tableComment+"\n"+commentsSql.toString());
	}
	
	public void createTable(TableName tableName, CreateTableCallback createTableCallback) throws MigrationException{
		createTable(tableName, null, createTableCallback);
	}
	
	public void addColumn(TableName tableName, ColumnName columnName,ColumnType columnType, ColumnDefine... define) throws MigrationException{
		String sql=this.handleColumn(HANDLE_COLUMN_TYPE_ADD, tableName, columnName, columnType, define);
		logger.info("\n"+sql);
		jdbcService.execute(sql);
	}
	
	public void changeColumn(TableName tableName, ColumnName columnName,ColumnDefine... define) throws MigrationException {
		changeColumn(tableName, columnName,null, define);
	}
{'fraction_non_alphanumeric': 0.13148976548732547, 'fraction_numerical': 0.0056933712891419274, 'mean_word_length': 5.676923076923077, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3139270', 'n_tokens_mistral': 2548, 'n_tokens_neox': 2397, 'n_words': 406}