All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.tinygroup.databasebuinstaller.impl.TableInstallProcessor Maven / Gradle / Ivy

There is a newer version: 2.2.3
Show newest version
/**
 *  Copyright (c) 1997-2013, www.tinygroup.org ([email protected]).
 *
 *  Licensed under the GPL, Version 3.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.gnu.org/licenses/gpl.html
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.tinygroup.databasebuinstaller.impl;

import org.tinygroup.database.config.table.Table;
import org.tinygroup.database.table.TableProcessor;
import org.tinygroup.logger.LogLevel;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * 
 * 功能说明:数据库表新建、字段更新、删除操作
 * 
 * 开发人员: renhui 
* 开发时间: 2013-8-15
*
*/ public class TableInstallProcessor extends AbstractInstallProcessor { private List tableList = new ArrayList
(); private TableProcessor tableProcessor; public TableProcessor getTableProcessor() { return tableProcessor; } public void setTableProcessor(TableProcessor tableProcessor) { this.tableProcessor = tableProcessor; } private void deal(String language, Table table, List sqls, Connection connect,boolean isFull) throws SQLException { if (tableList.contains(table)) { return; } tableList.add(table); installTable(language, table, sqls, connect,isFull); } private void installTable(String language, Table table, List sqls, Connection connect,boolean isFull) throws SQLException { logger.logMessage(LogLevel.INFO, "开始生成表格语句,表格 包:{0},名:{1}", table.getPackageName(), table.getName()); List tableSqls = null; //非全量且表格已经存在,需要生成增量sql if(!isFull && tableProcessor.checkTableExist(table, language, connect)) { tableSqls = tableProcessor.getUpdateSql(table, table.getPackageName(), language, connect); } else { tableSqls = tableProcessor.getCreateSql(table, table.getPackageName(), language); } if (tableSqls.size() != 0) { logger.logMessage(LogLevel.INFO, "生成sql:{0}", tableSqls); } else { logger.logMessage(LogLevel.INFO, "无需生成Sql"); } sqls.addAll(tableSqls); logger.logMessage(LogLevel.INFO, "生成表格语句完成,表格 包:{0},名:{1}", table.getPackageName(), table.getName()); } private List getSqls(String language, Connection con,boolean isFull) throws SQLException { logger.logMessage(LogLevel.INFO, "开始获取数据库表安装操作执行语句"); List
list = tableProcessor.getTables(); List sqls = new ArrayList(); for (Table table : list) { deal(language, table, sqls, con,isFull); } logger.logMessage(LogLevel.INFO, "获取数据库表安装操作执行语句结束"); return sqls; } public int getOrder() { return HIGHEST_PRECEDENCE; } public List getDealSqls(String language, Connection con) throws SQLException { return getUpdateSqls(language, con); } public List getFullSqls(String language, Connection con) throws SQLException{ return getSqls(language, con,true); } public List getUpdateSqls(String language, Connection con) throws SQLException { return getSqls(language, con,false); } }