执行流程:

1.从ftp判断文件是否存在

2.下载文件

3.创建ctl文件

4.创建可执行文件,bat或sh文件,文件中是sqlldr命令代码

5.备份表并创建临时表

6.执行文件,插入数据

7.检查数据完整性

8.创建主键和索引

9.将临时表修改为主表,删除临时表和备份表

1.

package com.iteye.aaa.job;

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.File;

import java.io.FileOutputStream;

import java.io.FileReader;

import java.io.FilenameFilter;

import java.io.IOException;

import java.io.OutputStreamWriter;

import java.text.SimpleDateFormat;

import java.util.ArrayList;

import java.util.Arrays;

import java.util.Calendar;

import java.util.List;

import org.apache.commons.logging.Log;

import org.apache.commons.logging.LogFactory;

import com.iteye.mobilevideo.core.util.ftp.FtpServer;

import com.iteye.mobilevideo.core.util.ftp.FtpTemplate;

import com.iteye.aaa.constants.AaaConstants;

import com.iteye.aaa.dao.AaaSyncTestDao;

import com.iteye.aaa.mq.WSyncObject;

import com.iteye.aaa.util.AaaSyncUtil;

public class SyncAllTestJob {

private Log log = LogFactory.getLog(this.getClass().getName());

private String pkgSeq = "";

private String day = "";

private String filePath = "";

private String permissionFile = "";

private FtpServer ftpServer = null;

private List fileList = null;

private List commandFileList = null;

private long total = 0L;

private boolean mainTableEdit = false;

private String dropOld = "DROP TABLE W_OLD PURGE";

private String alterMain2Old = "ALTER TABLE W RENAME TO W_OLD";

private String createMain = "CREATE TABLE W(WID NUMBER NOT NULL,PKGSEQ VARCHAR2(100) NOT NULL,MOBILE VARCHAR2(20) NOT NULL,SERVTYPE VARCHAR2(4) NOT NULL,SERVICEID VARCHAR2(20) NOT NULL,SERVICECODE VARCHAR2(30) NOT NULL,ECID VARCHAR2(30) NOT NULL,OPRCODE VARCHAR2(4) NOT NULL,RESULTCODE VARCHAR2(10),RESULTDESC VARCHAR2(200),STATUS VARCHAR2(4) NOT NULL,BATCHEVENTID VARCHAR2(60),CREATETIME TIMESTAMP(6) NOT NULL,CREATOR VARCHAR2(30) NOT NULL)";

private String createTmp = "CREATE TABLE W_TMP(WID NUMBER NOT NULL,PKGSEQ VARCHAR2(100) NOT NULL,MOBILE VARCHAR2(20) NOT NULL,SERVTYPE VARCHAR2(4) NOT NULL,SERVICEID VARCHAR2(20) NOT NULL,SERVICECODE VARCHAR2(30) NOT NULL,ECID VARCHAR2(30) NOT NULL,OPRCODE VARCHAR2(4) NOT NULL,RESULTCODE VARCHAR2(10),RESULTDESC VARCHAR2(200),STATUS VARCHAR2(4) NOT NULL,BATCHEVENTID VARCHAR2(60),CREATETIME TIMESTAMP(6) NOT NULL,CREATOR VARCHAR2(30) NOT NULL)";

private String dropMain = "DROP TABLE W PURGE";

private String alterOld2Main = "ALTER TABLE W_OLD RENAME TO W";

private String dropTmp = "DROP TABLE W_TMP PURGE";

private String alterTmp2Main = "ALTER TABLE W_TMP RENAME TO W";

private String idIndex = "alter table W_TMP add primary key (WID) USING index";

private String timeIndex = "create index I_WM_CREATETIME_%s on W_TMP (CREATETIME DESC)";

private String creatorIndex = "create index I_WM_CREATOR_%s on W_TMP (CREATOR)";

private String serviceCodeIndex = "create index I_WM_SERVICECODE_%s on W_TMP (SERVICECODE)";

public SyncAllTestJob() {

init(null);

}

public SyncAllTestJob(String dayVal) {

init(dayVal);

}

public void init(String dayVal) {

Calendar calendar = Calendar.getInstance();

boolean createDay = true;

if (dayVal != null && !dayVal.trim().equals("")) {

try {

System.out.println(new SimpleDateFormat("yyyyMMdd").parse(dayVal.trim()).toString());

day = dayVal.trim();

createDay = false;

} catch (Exception e) {

}

}

if (createDay) {

day = new SimpleDateFormat("yyyyMMdd").format(calendar.getTime());

}

log.info("Sync all white list2:sync day of " + day + ".");

pkgSeq = "syncall" + new SimpleDateFormat("yyyyMMddHHmmssSSS").format(calendar.getTime());

calendar.add(Calendar.DATE, -1);

filePath = AaaConstants.localFtpFilePath + AaaConstants.syncallPath + day + "/";

permissionFile = AaaConstants.localFtpFilePath + AaaConstants.syncallPath + AaaConstants.syncallPermissionFile;

ftpServer = new FtpServer();

ftpServer.setIp(AaaConstants.mmFtpIp);

ftpServer.setPort(AaaConstants.mmFtpPort);

ftpServer.setFtpuser(AaaConstants.mmFtpUser);

ftpServer.setFtppasswd(AaaConstants.mmFtpPassword);

ftpServer.setFtpurl(AaaConstants.mmFtpSourcePath + AaaConstants.mmFtpMPAll);

}

public void executeSyncAllTest() {

int flag = 0;

log.info("Sync all white list:sync start.");

try {

viewFiles();

if (fileList != null && fileList.size() > 0) {

if (downloadFiles()) {

if (createControlFile()) {

createPerformFiles();

if (commandFileList != null && commandFileList.size() > 0) {

if (alterTable()) {

flag = 1;

if (perform()) {

if (checkData()) {

flag = 2;

}

}

}

}

}

}

} else {

log.error("Sync all white list:no any file by " + day + ".");

}

} catch (Exception e) {

log.error("Sync all white list:sync error.");

}

if (flag == 2) {

log.error("Sync all white list:commit.");

createIndex();

copyData(1);

commitTable();

} else if (flag == 1) {

log.error("Sync all white list:rollback.");

copyData(2);

rollbackTable();

}

}

public boolean alterTable() {

log.info("Sync all white list:alter table start.");

boolean flag = false;

try {

AaaSyncTestDao.excuteSql(dropOld);

} catch (Exception e) {

}

try {

AaaSyncTestDao.excuteSql(dropTmp);

} catch (Exception e) {

}

try {

if (AaaSyncTestDao.excuteSql(alterMain2Old)) {

mainTableEdit = true;

if (AaaSyncTestDao.excuteSql(createMain)) {

if (AaaSyncTestDao.excuteSql(createTmp)) {

flag = true;

} else {

log.info("Sync all white list:create tmp table error.");

}

} else {

log.info("Sync all white list:create table error.");

}

} else {

log.info("Sync all white list:alter main table error.");

}

} catch (Exception e) {

log.info("Sync all white list:alter table error.", e);

}

if (!flag && mainTableEdit) {

rollbackTable();

}

return flag;

}

private void rollbackTable() {

try {

AaaSyncTestDao.excuteSql(dropMain);

} catch (Exception e) {

}

try {

AaaSyncTestDao.excuteSql(dropTmp);

} catch (Exception e) {

}

try {

if (!AaaSyncTestDao.excuteSql(alterOld2Main)) {

log.info("Sync all white list:alter old table to main table error.");

}

} catch (Exception e) {

log.info("Sync all white list:alter old table to main table error.", e);

}

}

private void createIndex() {

Calendar calendar = Calendar.getInstance();

String seq = new SimpleDateFormat("yyyyMMddHHmm").format(calendar.getTime());

try {

AaaSyncTestDao.excuteSql(idIndex);

log.info("Sync all white list:create id index success.");

} catch (Exception e) {

log.error("Sync all white list:create id index error.", e);

}

try {

AaaSyncTestDao.excuteSql(String.format(serviceCodeIndex, seq));

log.info("Sync all white list:create serviceCode index success.");

} catch (Exception e) {

log.error("Sync all white list:create serviceCode index error.", e);

}

try {

AaaSyncTestDao.excuteSql(String.format(timeIndex, seq));

log.info("Sync all white list:create createTime index success.");

} catch (Exception e) {

log.error("Sync all white list:create createTime index error.", e);

}

try {

AaaSyncTestDao.excuteSql(String.format(creatorIndex, seq));

log.info("Sync all white list:create creator index success.");

} catch (Exception e) {

log.error("Sync all white list:create creator index error.", e);

}

}

private void copyData(int val) {

boolean flag = false;

try {

String sql = "";

if (val == 1) {

sql = "INSERT INTO W_TMP SELECT W_SEQ.NEXTVAL, PKGSEQ, MOBILE, SERVTYPE, SERVICEID, SERVICECODE, ECID, OPRCODE, RESULTCODE, RESULTDESC, STATUS, BATCHEVENTID, CREATETIME, CREATOR FROM W";

} else {

sql = "INSERT INTO W_OLD SELECT W_SEQ.NEXTVAL, PKGSEQ, MOBILE, SERVTYPE, SERVICEID, SERVICECODE, ECID, OPRCODE, RESULTCODE, RESULTDESC, STATUS, BATCHEVENTID, CREATETIME, CREATOR FROM W";

}

if (AaaSyncTestDao.transTestMain2Other(sql)) {

flag = true;

AaaSyncTestDao.excuteSql(dropMain);

} else {

log.error("Sync all white list:cope data from main to tmp error.");

}

} catch (Exception e) {

}

if (!flag) {

Calendar calendar = Calendar.getInstance();

String seq = new SimpleDateFormat("yyyyMMddHHmm").format(calendar.getTime());

log.info("Sync all white list:cope data from main to tmp error,alter main table to W_" + seq);

AaaSyncTestDao.excuteSql("ALTER TABLE W_TMP RENAME TO W_" + seq);

}

}

private void commitTable() {

try {

AaaSyncTestDao.excuteSql(dropMain);

} catch (Exception e) {

}

try {

AaaSyncTestDao.excuteSql(dropOld);

} catch (Exception e) {

}

try {

if (!AaaSyncTestDao.excuteSql(alterTmp2Main)) {

log.info("Sync all white list:alter old table to main table error.");

}

} catch (Exception e) {

log.info("Sync all white list:alter old table to main table error.", e);

}

}

private void viewFiles() {

fileList = null;

try {

String[] files = FtpTemplate.listNames(ftpServer, "/");

if (files != null && files.length > 0) {

fileList = new ArrayList();

for (int i = 0; i < files.length; i++) {

String fileName = files[i].trim();

if (validateFileName(fileName, day) && !fileList.contains(fileName)) {

log.info("Sync all white list:add sync file " + fileName);

fileList.add(fileName);

}

}

if (fileList != null && fileList.size() > 0) {

if (!AaaSyncTestDao.insertWSyncFile(pkgSeq, day, "00")) {

log.error("Sync all white list:view files success,but insert data to db error.");

fileList = null;

}

}

}

} catch (Exception e) {

log.error("Sync all white list:view files error.", e);

fileList = null;

}

}

private boolean downloadFiles() {

int len = fileList.size();

int successLen = 0;

for (int i = 0; i < len; i++) {

WSyncObject so = new WSyncObject();

so.setPkgSeq(pkgSeq);

so.setFileName(fileList.get(i));

so.setCount(1);

log.info("Sync all white list:start download " + so.toString() + "," + Thread.currentThread().getName());

if (downloadFile(so, filePath)) {

successLen++;

log.info("Sync all white list:file " + so.getFileName() + " download finish.");

} else {

log.error("Sync all white list:file " + so.getFileName() + " download error.");

break;

}

}

if (successLen == len) {

if (!AaaSyncTestDao.updateWSyncFile(pkgSeq, "01")) {

log.info("Sync all white list:download success but update status to database fail.");

}

return true;

} else {

if (!AaaSyncTestDao.updateWSyncFile(pkgSeq, "10")) {

log.info("Sync all white list:download fail and update status to database fail.");

}

return false;

}

}

private boolean createControlFile() {

if (exportToFile(filePath, "control.ctl", AaaConstants.syncallControlFileList)) {

return true;

}

return false;

}

private void createPerformFiles() {

log.info("Sync all white list:start create perform files.");

try {

String fileType = AaaConstants.syncallType.equalsIgnoreCase("bat") ? ".bat" : ".sh";

commandFileList = new ArrayList();

String command = AaaConstants.syncallType.equalsIgnoreCase("bat") ? AaaConstants.syncallSqlldrBat : AaaConstants.syncallSqlldrSh;

int len = fileList.size();

int index = 1;

String content = "";

String fileName = "";

String path = "";

String toFileName = "";

List contentList = new ArrayList();

for (int i = 0; i < len; i++) {

fileName = fileList.get(i);

path = filePath + fileName.substring(0, fileName.length() - 4);

long line = readFirstLine(fileName);

if (line > 0) {

total += line;

content = String.format(command, path, filePath, path, path, line);

contentList.add(content);

if (AaaConstants.syncallType.equalsIgnoreCase("bat")) {

contentList.add("exit");

} else {

contentList.add("exit");

}

toFileName = "command" + index + fileType;

if (exportToFile(filePath, toFileName, contentList)) {

index++;

commandFileList.add(filePath + toFileName);

contentList.clear();

}

}

}

if (contentList.size() > 0) {

toFileName = "command" + index + fileType;

if (exportToFile(filePath, toFileName, contentList)) {

index++;

commandFileList.add(filePath + toFileName);

log.info("Sync all white list:create perform files finish.");

contentList.clear();

} else {

log.error("Sync all white list:create perform files error.");

commandFileList = null;

}

}

} catch (Exception e) {

log.error("Sync all white list:create perform files error.");

commandFileList = null;

}

}

private long readFirstLine(String fileName) {

long result = -1;

BufferedReader reader = null;

try {

reader = new BufferedReader(new FileReader(filePath + fileName));

String headerLine = reader.readLine();

if (headerLine == null) {

headerLine = "";

}

result = Long.parseLong(headerLine.split(",")[1].trim());

reader.close();

} catch (Exception e) {

result = -1;

log.error("Sync all white list:read " + (filePath + fileName) + " first line error.", e);

} finally {

if (reader != null) {

try {

reader.close();

} catch (IOException e) {

reader = null;

}

}

}

if (result != -1) {

return result;

} else {

throw new RuntimeException("Sync all white list:read " + (filePath + fileName) + " first line error.");

}

}

private boolean perform() {

log.info("Sync all white list:create perform files finish,start perform.");

boolean flag = false;

try {

if (AaaConstants.syncallType.equalsIgnoreCase("sh")) {

log.info("Sync all white list:chmod " + permissionFile + " " + filePath + "*.sh");

AaaSyncUtil.callSh(permissionFile + " " + filePath);

}

if (AaaConstants.importDataThreadPool == null) {

AaaConstants.importDataThreadPool = new ImportDataThreadPool();

}

for (int i = 0; i < commandFileList.size(); i++) {

AaaConstants.importDataThreadPool.execute(new ImportDataThreadPool.Task(commandFileList.get(i)));

}

while (AaaConstants.importDataThreadPool.getActiveCount() != 0) {

}

flag = true;

log.info("Sync all white list:perform all success.");

AaaConstants.importDataThreadPool.shutdown();

if (!AaaSyncTestDao.updateWSyncFile(pkgSeq, "02")) {

log.info("Sync all white list:perform all success but update status to database fail.");

}

} catch (Exception e) {

log.info("Sync all white list:perform files error.", e);

flag = false;

if (!AaaSyncTestDao.updateWSyncFile(pkgSeq, "20")) {

log.info("Sync all white list:perform fail but update status to database fail.");

}

}

return flag;

}

private boolean exportToFile(String filePath, String fileName, List contentList) {

boolean flag = false;

FileOutputStream fos = null;

OutputStreamWriter osw = null;

BufferedWriter bw = null;

try {

fos = new FileOutputStream(new File(filePath + fileName));

osw = new OutputStreamWriter(fos, "UTF-8");

bw = new BufferedWriter(osw);

String line = "";

for (int i = 0; i < contentList.size(); i++) {

line = contentList.get(i);

try {

bw.write(line + "\r\n");

} catch (IOException e) {

e.printStackTrace();

}

}

bw.close();

osw.close();

fos.close();

flag = true;

} catch (Exception e) {

e.printStackTrace();

} finally {

try {

if (bw != null) {

bw.close();

}

if (osw != null) {

osw.close();

}

if (fos != null) {

fos.close();

}

} catch (Exception ee) {

ee.printStackTrace();

}

}

return flag;

}

private boolean validateFileName(String fileName, String day) {

String perfix = AaaConstants.mpAll_file_perfix + day;

String suffix = AaaConstants.mpAll_file_suffix;

if (fileName != null && fileName.startsWith(perfix) && fileName.endsWith(suffix)) {

String middle = fileName.substring(perfix.length());

middle = middle.substring(0, middle.length() - suffix.length());

if (middle.length() == 6) {

char[] chars = middle.toCharArray();

if (chars.length == 6) {

if (chars[0] < '0' || chars[0] > '2') {

return false;

}

if (chars[1] < '0' || chars[1] > '9') {

return false;

}

if (chars[0] == '2' && chars[1] > '3') {

return false;

}

if (chars[2] != '_') {

return false;

}

for (int i = 3; i < 6; i++) {

if (chars[i] < '0' || chars[i] > '9') {

return false;

}

}

return true;

}

}

}

return false;

}

private boolean downloadFile(WSyncObject so, String filePath) {

FtpServer ftpServer = new FtpServer();

ftpServer.setIp(AaaConstants.mmFtpIp);

ftpServer.setPort(AaaConstants.mmFtpPort);

ftpServer.setFtpuser(AaaConstants.mmFtpUser);

ftpServer.setFtppasswd(AaaConstants.mmFtpPassword);

ftpServer.setFtpurl(AaaConstants.mmFtpSourcePath + AaaConstants.mmFtpMPAll);

// 下载文件

boolean downSuccessFlag = false;

try {

FtpTemplate.downLoadFilesByPath(ftpServer, "/" + so.getFileName(), filePath);

File f = new File(filePath + so.getFileName());

if (f.exists() && f.length() > 0) {

downSuccessFlag = true;

}

} catch (Exception e) {

downSuccessFlag = false;

e.printStackTrace();

}

// 处理下载失败文件

if (!downSuccessFlag) {

if (so.getCount() <= 3) {

log.info("Sync all white list:repeat download fail file " + (AaaConstants.mpAllDownInterval / 1000) + "S,for " + so.getCount() + ","

+ so.toString());

try {

Thread.sleep(AaaConstants.mpAllDownInterval);

} catch (InterruptedException e) {

e.printStackTrace();

}

so.setCount(so.getCount() + 1);

// 重新下载

downloadFile(so, filePath);

}

}

return downSuccessFlag;

}

static class SqlldrFilter implements FilenameFilter {

private String type;

public SqlldrFilter(String type) {

this.type = type;

}

public boolean accept(File dir, String name) {

return name.endsWith(type);

}

}

public boolean checkData() {

log.info("Sync all white list:check data.");

boolean flag = false;

File file = new File(filePath);

if (file.isDirectory()) {

SqlldrFilter filter = new SqlldrFilter(".bad");

String[] files = file.list(filter);

if (files == null || files.length == 0) {

long count = AaaSyncTestDao.countSql();

if (count == total) {

log.info("Sync all white list:check success,total=" + total);

return true;

} else {

log.info("Sync all white list:check fail,count=" + count + ",total=" + total);

}

} else {

log.info("Sync all white list:check fail,bad files " + Arrays.toString(files));

}

} else {

log.info("Sync all white list:check fail," + filePath + "is not a dir.");

}

return flag;

}

public static void main(String[] args) {

long start = System.currentTimeMillis();

String day = null;

if (args != null && args.length > 0) {

if (args[0] != null && args[0].trim().length() > 0) {

day = args[0].trim();

}

}

try {

AaaSyncUtil.init();

SyncAllTestJob job = null;

if (day == null) {

job = new SyncAllTestJob();

} else {

job = new SyncAllTestJob(day);

}

job.executeSyncAllTest();

} catch (Exception e) {

e.printStackTrace();

}

long end = System.currentTimeMillis();

System.out.println("Host:" + (end - start));

}

}

2.

package com.job;

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.util.concurrent.ArrayBlockingQueue;

import java.util.concurrent.ThreadPoolExecutor;

import java.util.concurrent.TimeUnit;

import org.apache.commons.logging.Log;

import org.apache.commons.logging.LogFactory;

import com.iteye.aaa.constants.AaaConstants;

public class ImportDataThreadPool extends ThreadPoolExecutor {

public ImportDataThreadPool() {

super(AaaConstants.syncallThread, AaaConstants.syncallThread, 5, TimeUnit.SECONDS, new ArrayBlockingQueue(2000),

new ThreadPoolExecutor.CallerRunsPolicy());

}

public static class Task implements Runnable {

private Log log = LogFactory.getLog(this.getClass().getName());

private String filePath;

public Task(String filePath) {

this.filePath = filePath;

}

@Override

public void run() {

log.info("Sync all white list:perform " + filePath);

if (AaaConstants.syncallType.equalsIgnoreCase("bat")) {

callBat(filePath);

} else {

callSh(filePath);

}

log.info("Sync all white list:perform " + filePath + " finish.");

}

public void callSh(String command) {

try {

Runtime rt = Runtime.getRuntime();

Process pcs = rt.exec(command);

BufferedReader br = new BufferedReader(new InputStreamReader(pcs.getInputStream()));

while (br.readLine() != null) {

}

try {

pcs.waitFor();

} catch (InterruptedException e) {

}

br.close();

pcs.exitValue();

log.info("Sync all white list:perform " + command + " success.");

} catch (Exception e) {

log.info("Sync all white list:perform " + command + " error.");

}

}

public void callBat(String command) {

command = AaaConstants.syncallPathPrefix + command;

try {

Process child = Runtime.getRuntime().exec("cmd.exe /C start " + command);

InputStream in = child.getInputStream();

while (in.read() != -1) {

}

in.close();

child.destroy();

log.info("Sync all white list:perform " + command + " success.");

} catch (IOException e) {

log.info("Sync all white list:perform " + command + " error.");

e.printStackTrace();

}

}

}

public static void main(String[] args) {

AaaConstants.syncallThread = 1;

AaaConstants.syncallType = "bat";

String cmd1 = "e:/usr/local/aaaservice/syncall/20130909/1.bat";

String cmd2 = "e:/usr/local/aaaservice/syncall/20130909/2.bat";

ImportDataThreadPool pool = new ImportDataThreadPool();

pool.execute(new ImportDataThreadPool.Task(cmd1));

pool.execute(new ImportDataThreadPool.Task(cmd2));

while (pool.getActiveCount() != 0) {

}

pool.shutdown();

System.out.println("down");

}

}

3.

package com.util;

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.net.UnknownHostException;

import org.apache.commons.logging.Log;

import org.apache.commons.logging.LogFactory;

import com.iteye.aaa.constants.AaaConstants;

public class AaaSyncUtil {

private static Log log = LogFactory.getLog(AaaSyncUtil.class.getName());

public static void init() throws UnknownHostException, IOException {

AaaConstants.conf = new Configuration("/config.properties");

org.hibernate.cfg.Configuration cfg = new org.hibernate.cfg.Configuration();

AaaConstants.sessionFactory = cfg.configure().buildSessionFactory();

AaaConstants.mmFtpIp = StringUtil.null2Str(AaaConstants.conf.getProperty("mmFtpIp"));

AaaConstants.mmFtpPort = StringUtil.nullToLong(AaaConstants.conf.getProperty("mmFtpPort"));

AaaConstants.mmFtpUser = StringUtil.null2Str(AaaConstants.conf.getProperty("mmFtpUser"));

AaaConstants.mmFtpPassword = StringUtil.null2Str(AaaConstants.conf.getProperty("mmFtpPassword"));

AaaConstants.mmFtpSourcePath = StringUtil.null2Str(AaaConstants.conf.getProperty("mmFtpSourcePath"));

AaaConstants.mmFtpMPAll = StringUtil.null2Str(AaaConstants.conf.getProperty("mmFtpMPAll"));

AaaConstants.localFtpFilePath = StringUtil.null2Str(AaaConstants.conf.getProperty("localFtpFilePath"));

AaaConstants.mpAllDownInterval = StringUtil.nullToInteger(AaaConstants.conf.getProperty("mpAllDownInterval"));

AaaConstants.mpAllDealInterval = StringUtil.nullToInteger(AaaConstants.conf.getProperty("mpAllDealInterval"));

AaaConstants.mpAllDealNumber = StringUtil.nullToInteger(AaaConstants.conf.getProperty("mpAllDealNumber"));

AaaConstants.serviceFlag = StringUtil.null2Str(AaaConstants.conf.getProperty("serviceFlag"));

AaaConstants.syncallSqlldrBat = StringUtil.null2Str(AaaConstants.conf.getProperty("syncallSqlldrBat"));

AaaConstants.syncallSqlldrSh = StringUtil.null2Str(AaaConstants.conf.getProperty("syncallSqlldrSh"));

AaaConstants.syncallType = StringUtil.null2Str(AaaConstants.conf.getProperty("syncallType"));

AaaConstants.syncallPathPrefix = StringUtil.null2Str(AaaConstants.conf.getProperty("syncallPathPrefix"));

AaaConstants.syncallPermissionFile = StringUtil.null2Str(AaaConstants.conf.getProperty("syncallPermissionFile"));

AaaConstants.syncallThread = StringUtil.nullToInteger(AaaConstants.conf.getProperty("syncallThread"));

}

public static void callSh(String command) {

try {

Runtime rt = Runtime.getRuntime();

Process pcs = rt.exec(command);

BufferedReader br = new BufferedReader(new InputStreamReader(pcs.getInputStream()));

while (br.readLine() != null) {

}

try {

pcs.waitFor();

} catch (InterruptedException e) {

}

br.close();

pcs.exitValue();

log.info("Sync all white list:perform " + command + " success.");

} catch (Exception e) {

log.info("Sync all white list:perform " + command + " error.");

}

}

}

4.

package com.constants;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import java.util.concurrent.ArrayBlockingQueue;

import java.util.concurrent.BlockingQueue;

import org.hibernate.SessionFactory;

import com.iteye.aaa.job.ImportDataThreadPool;

import com.iteye.aaa.mina.AaaMinaClient;

import com.iteye.aaa.protocol.AaaBaseProtocol;

import com.iteye.aaa.service.AaaInterfaceManager;

import com.iteye.aaa.util.Configuration;

public class AaaConstants {

public static String mmFtpIp;

public static long mmFtpPort;

public static String mmFtpUser;

public static String mmFtpPassword;

public static String mmFtpSourcePath;

public static String mmFtpMPReq;

public static String mmFtpMPRst;

public static String mmFtpMPAll;

public static String mmFtpPMReq;

public static String mmFtpPMRst;

public static String localFtpFilePath;

public static int retryCount = 3;

public static final String mpAll_file_perfix = "MP_wlist_all_sync_";

public static final String mpAll_file_suffix = ".req";

public static final String mpAll_file_insert_sql = "INSERT INTO W_SYNC_FILES(ID, PKGSEQ, FILENAME, STATUS) VALUES (W_SYNC_FILES_SEQ.NEXTVAL,'%s','%s','%s')";

public static final String mpAll_file_update_sql = "UPDATE W_SYNC_FILES SET STATUS='%s' WHERE PKGSEQ='%s' AND FILENAME='%s'";

public static int mpAllDownInterval;

public static int mpAllDealInterval;

public static int mpAllDealNumber;

public static String serviceFlag = "";

public static String syncallPath = "syncall/";

public static String syncallPermissionFile ="";

public static String syncallSqlldrBat = "";

public static String syncallSqlldrSh = "";

public static String syncallType = "";

public static String syncallPathPrefix = "";

public static int syncallThread = 5;

public static List syncallControlFileList = new ArrayList();

public static ImportDataThreadPool importDataThreadPool = null;

static {

syncallControlFileList.add("load data");

syncallControlFileList.add("append into table w_tmp");

syncallControlFileList.add("fields terminated by ',' optionally enclosed by '\"'");

syncallControlFileList.add("trailing nullcols");

syncallControlFileList.add("(");

syncallControlFileList.add("MOBILE,");

syncallControlFileList.add("SERVTYPE,");

syncallControlFileList.add("SERVICEID,");

syncallControlFileList.add("SERVICECODE,");

syncallControlFileList.add("ECID,");

syncallControlFileList.add("PKGSEQ \"to_char(sysdate,'yyyyMMddHH24missSSS') || '01' || W_PKGSEQ.nextval\",");

syncallControlFileList.add("OPRCODE CONSTANT '01',");

syncallControlFileList.add("STATUS CONSTANT '1',");

syncallControlFileList.add("CREATOR \":SERVICECODE\",");

syncallControlFileList.add("CREATETIME \"SYSTIMESTAMP-1\",");

syncallControlFileList.add("WID \"w_seq.nextval\"");

syncallControlFileList.add(")");

}

}

5.

ftpIp=192.168.1.133

ftpPort=21

ftpUser=aaa

ftpPassword=aaa

ftpSourcePath=/aaaservice

ftpMPReq=/aa/q

ftpMPRst=/aa/r

ftpMPAll=/aa/a

ftpPMReq=/bb/q

ftpPMRst=/bb/r

localFtpFilePath=/usr/local/aaaservice/

serviceFtpIp=192.168.1.100

serviceFtpPort=21

serviceFtpUser=aaa

serviceFtpPassword=bbb

serviceFtpSourcePath=/a/b

localServiceFtpFilePath=/a/c

retryCount=3

#activeTestInterval=60

activeTestRecivedInterval=60

activeTestNumber=3

mpAllDownInterval=5000

mpAllDealInterval=5000

mpAllDealNumber=10000

serviceFlag=01

syncallThread=5

syncallSqlldrBat=sqlldr userid=admin/admin@oracle data=%s.req control=%scontrol.ctl log=%s.log bad=%s.bad rows=2000 bindsize=6553600 load=%s skip=1 parallel=true

syncallSqlldrSh=sqlldr userid=admin/admin@oracle data=%s.req control=%scontrol.ctl log=%s.log bad=%s.bad rows=2000 bindsize=6553600 load=%s skip=1 parallel=true

syncallType=bat

syncallPathPrefix=e:

syncallPermissionFile=syncall.sh

6.Linux修改目录下所有SH文件权限

chmod 755 ${1}/*.sh

exit

7.ctl文件

load data

append into table w_tmp

fields terminated by ',' optionally enclosed by '"'

trailing nullcols

(

MOBILE,

SERVTYPE,

SERVICEID,

SERVICECODE,

ECID,

PKGSEQ "to_char(sysdate,'yyyyMMddHH24missSSS') || '01' || W_PKGSEQ.nextval",

OPRCODE CONSTANT '01',

STATUS CONSTANT '1',

CREATOR ":SERVICECODE",

CREATETIME "SYSTIMESTAMP-1",

WID "w_seq.nextval"

)

java 生成.sh文件,Java 生成Bat或SH文件,调用Sqlldr安插数据到Oracle相关推荐

  1. Windows垃圾文件清理(批处理BAT清理垃圾文件)

    垃圾文件的定义 1. 软件安装过程中产生的临时文件 许多软件在安装时,首先要把自身的安装文件解压缩到一个临时目录(一般为 Windows文件夹下的Temp目录),如WinZip等工具,然后再进行安装. ...

  2. 【Android 安全】DEX 加密 ( Java 工具开发 | 解压 apk 文件 | 加密生成 dex 文件 | 打包未签名 apk 文件 | 文件解压缩相关代码 )

    文章目录 一.解压 apk 文件 二.加密生成 dex 文件 三.打包未签名 apk 文件 四.完整代码示例 五.文件解压缩相关代码 六.执行结果 参考博客 : [Android 安全]DEX 加密 ...

  3. 【Android 安全】DEX 加密 ( Java 工具开发 | 生成 dex 文件 | Java 命令行执行 )

    文章目录 一.生成 dex 文件 二.生成 dex 文件代码示例 三.生成 dex 结果 参考博客 : [Android 安全]DEX 加密 ( 常用 Android 反编译工具 | apktool ...

  4. Java生成PDF文件,java面试题,java初级笔试题

    写在最前面,我总结出了很多互联网公司的面试题及答案,并整理成了文档,以及各种学习的进阶学习资料,免费分享给大家.扫码加微信好友进[程序员面试学习交流群],免费领取.也欢迎各位一起在群里探讨技术. 一. ...

  5. JAVA项目的打包及生成.exe文件或者打包安装软件

    总体思路是先打成jar再把jar打成exe.主要看1.3和2.3里的内容就可以了. 1.将项目打成jar: 1.1要将项目打包成jar文件,方法很多,可以用Eclipse自带的打包工具Ant打包,也可 ...

  6. FISCO BCOS 控制台 console solidity合约编译工具 生成abi bin java文件

    下载控制台 https://fisco-bcos-documentation.readthedocs.io/zh_CN/latest/docs/console/console_of_java_sdk. ...

  7. java servlet html文件_Servlet生成html页面

    Servlet(Server Applet)是Java Servlet的简称,称为小服务程序或服务连接器,用Java编写的服务器端程序,主要功能在于交互式地浏览和修改数据,生成动态Web内容. 该Se ...

  8. r.java没有生成_r.java文件没有生成

    最近几天学习android ,学习时候难免要导入一些示例,目的为了更加了解android各种API用法,顺便也可以学习下别人代码的写法.可是导入android源码后,基本都有错误,R.java也不会自 ...

  9. java发送html文件_Java生成HTML文件

    实例HTML文件 ###title### ###title### ###author### ###content######html### Java代码: package com.util; impo ...

最新文章

  1. Paper1:HoPE: Horizontal Plane Extractor for Cluttered
  2. ping -c3 baidu.com  ping过去是这样,代表网络畅通
  3. 64位浮点数_浮点数运算的机器误差分析
  4. 【OFDM频域同步】基于OFDM数字电视地面广播系统中频域同步技术matlab仿真
  5. linux 挂载u盘区别不到,linux系统下为什么不能挂载U盘
  6. C++圆形线性链表Cicular Linear Linked List算法(附完整源码)
  7. VUE2 第五天学习--过渡效果
  8. 管理工作中的50点感悟
  9. 移动项目开发笔记(管理不同解决方案下的DLL文件相互引用之心得体会)
  10. MySQL将一张表数据插入到另一张表
  11. 万字长文+思维导图帮你梳理 Java IO 流,还学不会你来打我(值得收藏)
  12. 超级复制shadowcopy
  13. 【清华大学】深入理解操作系统(陈渝) 第一章
  14. Java将 PDF 拆分为多个 PDF 文件
  15. 安卓 TextView显示温度符号
  16. 如何设置word为只读
  17. Matlab根据椭圆参数圆心,长轴,短轴,倾斜角画椭圆
  18. 2022骨传导耳机品牌那个好、排名前十的好用的骨传导耳机
  19. 【matlab】spm数据处理
  20. vue快捷导出excel插件

热门文章

  1. nginx 知识点 :ctx_index and index
  2. FLV封装格式分析器
  3. Linux共享库路径配置
  4. GitHub vs. Bitbucket 不只是功能不同
  5. 视觉目标检测和识别之过去,现在及可能
  6. Android常用开源框架
  7. win7 VS2008 编译luabind-0.9.1 动态库 静态库
  8. mybatis实现一对多关系《DeptEmp》
  9. HotSpot源码(一):Docker与虚拟机的区别,class字节码解析,linux内核源码下载地址,Yacc与Lex快速入门
  10. 【广义找零钱问题】 贪心算法求解进制转换问题