com.aspire.nm.component.common.mobile.Strategy.Impl.MySqlLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of commonUtil Show documentation
Show all versions of commonUtil Show documentation
commonUtil is a dajiangnan's java utils
package com.aspire.nm.component.common.mobile.Strategy.Impl;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import com.aspire.nm.component.common.mobile.MobileUtil;
import com.aspire.nm.component.common.mobile.Strategy.LoadStrategy;
import com.aspire.nm.component.common.mobile.Strategy.Impl.db.black.Black;
import com.aspire.nm.component.common.mobile.Strategy.Impl.db.legalPerfix.LegalPerfix;
import com.aspire.nm.component.common.mobile.Strategy.Impl.db.segment.SegMent;
import com.aspire.nm.component.common.mobile.Strategy.Impl.db.switchs.Swithchs;
import com.aspire.nm.component.common.mobile.Strategy.Impl.db.update.UpdateTimes;
import com.aspire.nm.component.commonUtil.constants.ConstantConfig;
import com.aspire.nm.component.commonUtil.date.DateUtil;
import com.aspire.nm.component.commonUtil.db.DBConnectionManager;
import com.aspire.nm.component.commonUtil.db.Db;
import com.aspire.nm.component.commonUtil.log.BootLogger;
public class MySqlLoader implements LoadStrategy{
private static DBConnectionManager dBConnectionManager = null;
private static Db db = new Db();
private static Logger logger = Logger.getLogger(MobileUtil.class);
private static Logger bootLogger = Logger.getLogger(BootLogger.class);
public MySqlLoader(String jdbcConfigPath){
dBConnectionManager = new DBConnectionManager(jdbcConfigPath);
Connection con = dBConnectionManager.getConnection("mysql");
try{
db.saveOrUpdateOrDelete(ConstantConfig.getContentValue("config/sql/create/updateMobile.sql"), null, con);
bootLogger.debug("create updateMobile");
db.saveOrUpdateOrDelete("insert common_update_mobile(table_name,update_time) values ('"+UpdateTimes.TABLE_NAME_BLACK+"',?)", new Object[]{DateUtil.getCurDateTime()}, con);
db.saveOrUpdateOrDelete("insert common_update_mobile(table_name,update_time) values ('"+UpdateTimes.TABLE_NAME_LEGALPERFIX+"',?)", new Object[]{DateUtil.getCurDateTime()}, con);
db.saveOrUpdateOrDelete("insert common_update_mobile(table_name,update_time) values ('"+UpdateTimes.TABLE_NAME_SEGMENT+"',?)", new Object[]{DateUtil.getCurDateTime()}, con);
db.saveOrUpdateOrDelete("insert common_update_mobile(table_name,update_time) values ('"+UpdateTimes.TABLE_NAME_SWITCH+"',?)", new Object[]{DateUtil.getCurDateTime()}, con);
bootLogger.debug("init updateMobile");
}catch(Exception e){
if(e.toString().indexOf("already exists") != -1){
bootLogger.debug("exist update");
}else{
bootLogger.error(e);
e.printStackTrace();
}
}
try{
db.saveOrUpdateOrDelete(ConstantConfig.getContentValue("config/sql/create/legalperfix.sql"), null, con);
bootLogger.debug("create legalperfix");
db.saveOrUpdateOrDelete("insert common_mobile_legalperfix(mobile,cmcc_mobile,ctcc_mobile,cucc_mobile) values (?,?,?,?)",
new Object[]{"13,14,15,18","134,135,136,137,138,139,147,150,151,152,157,158,159,178,182,183,187,188","133,153,177,180,189,181","130,131,132,145,155,156,176,185,186"}, con);
bootLogger.debug("init legalperfix");
}catch(Exception e){
if(e.toString().indexOf("already exists") != -1){
bootLogger.debug("exist legalperfix");
}else{
bootLogger.error(e);
e.printStackTrace();
}
}
try{
db.saveOrUpdateOrDelete(ConstantConfig.getContentValue("config/sql/create/segment.sql"), null, con);
bootLogger.debug("create segment");
}catch(Exception e){
if(e.toString().indexOf("already exists") != -1){
bootLogger.debug("exist segment");
}else{
bootLogger.error(e);
e.printStackTrace();
}
}
try{
db.saveOrUpdateOrDelete(ConstantConfig.getContentValue("config/sql/create/black.sql"), null, con);
bootLogger.debug("create black");
}catch(Exception e){
if(e.toString().indexOf("already exists") != -1){
bootLogger.debug("exist black");
}else{
bootLogger.error(e);
e.printStackTrace();
}
}
try{
db.saveOrUpdateOrDelete(ConstantConfig.getContentValue("config/sql/create/switch.sql"), null, con);
bootLogger.debug("create switch");
}catch(Exception e){
if(e.toString().indexOf("already exists") != -1){
bootLogger.debug("exist switch");
}else{
logger.error(e);
e.printStackTrace();
}
}
dBConnectionManager.freeConnection("mysql", con);
}
@Override
public UpdateTimes getUpdateTimes() {
UpdateTimes updateTimes = new UpdateTimes();
Connection con = dBConnectionManager.getConnection("mysql");
List