From 10445847ed1bfa5755127e828b603a3cdd49c5e3 Mon Sep 17 00:00:00 2001 From: ?? ? <ulysseskao@ximple.com.tw> Date: Wed, 07 May 2008 12:58:22 +0800 Subject: [PATCH] update for EOFM-75 --- xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2ShpJob.java | 145 +++++++++++++++++++++++++++++++++++------------- 1 files changed, 106 insertions(+), 39 deletions(-) diff --git a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2ShpJob.java b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2ShpJob.java index bfeefe4..9a33e99 100644 --- a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2ShpJob.java +++ b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/OracleConvertDgn2ShpJob.java @@ -95,31 +95,42 @@ try { + logger.info("-- step:clearOutputDirectory --"); + clearOutputDirectory(); boolean bFirst = true; - for (String orgSchema : _orgSchema) + if (checkConvertDB()) { - OracleConvertJobContext jobContext = (OracleConvertJobContext) prepareJobContext(_filterPath); - jobContext.setConnectionInfo(_oracleHost, _oraclePort, _oracleInstance); - jobContext.setLogin(_username, _password); - jobContext.setShapeData(_dataPath); - jobContext.setConvertDB(_convertDB); - jobContext.setConvertFile(_convertFile); - jobContext.setExecutionContext(context); + logger.info("-- step:convertOracleDB --"); + for (String orgSchema : _orgSchema) + { + OracleConvertJobContext jobContext = (OracleConvertJobContext) prepareJobContext(_filterPath); + jobContext.setConnectionInfo(_oracleHost, _oraclePort, _oracleInstance); + jobContext.setLogin(_username, _password); + jobContext.setShapeData(_dataPath); + jobContext.setConvertDB(_convertDB); + jobContext.setConvertFile(_convertFile); + jobContext.setExecutionContext(context); - if (bFirst) - copyConnectivity(jobContext); - else - bFirst = false; + if (bFirst) + copyConnectivity(jobContext); + else + bFirst = false; - logger.info("----- start schema:" + orgSchema + " -----"); - exetcuteConvert(jobContext, orgSchema, _dataPath); + logger.info("----- start schema:" + orgSchema + " -----"); + exetcuteConvert(jobContext, orgSchema, _dataPath); - //close all open filewriter instance - jobContext.closeFeatureWrite(); + //close all open filewriter instance + jobContext.closeFeatureWrite(); + } } - convertIndexDesignFile(context); - convertOtherDesignFile(context); + if (checkConvertFile()) + { + logger.info("-- step:convertIndexDesignFile --"); + convertIndexDesignFile(context); + logger.info("-- step:convertOtherDesignFile --"); + convertOtherDesignFile(context); + } } catch (SQLException e) { logger.warn(e.getMessage(), e); @@ -129,10 +140,12 @@ logger.warn(ex.getMessage(), ex); throw new JobExecutionException("IO error. " + ex.getMessage(), ex); } + logger.info(jobName + " end at " + new Date()); } /** * Connectivity�ƻs�@�Ӫ����A�b�d�߹q�y��V�ɥΨӤ��OMS��Ʈw���q���s����(Connectivity) + * * @param jobContext * @throws SQLException */ @@ -219,25 +232,25 @@ { rs = stmt.executeQuery(fetchStmt); - while (rs.next()) - { - int size = rs.getMetaData().getColumnCount(); - Object[] values = new Object[size]; - - for (int i = 0; i < size; i++) + while (rs.next()) { - values[i] = rs.getObject(i + 1); + int size = rs.getMetaData().getColumnCount(); + Object[] values = new Object[size]; + + for (int i = 0; i < size; i++) + { + values[i] = rs.getObject(i + 1); + } + + Integer key = ((BigDecimal) values[0]).intValue(); + String name = (String) values[1]; + + Pair pair = (Pair) orderedMap.get(key); + if (pair == null) + orderedMap.put(key, new Pair(name, null)); + else + pair.first = name; } - - Integer key = ((BigDecimal) values[0]).intValue(); - String name = (String) values[1]; - - Pair pair = (Pair) orderedMap.get(key); - if (pair == null) - orderedMap.put(key, new Pair(name, null)); - else - pair.first = name; - } } catch (SQLException e) { logger.error(e.toString(), e); @@ -444,6 +457,7 @@ /** * �����ഫ�����ɪ��u�@ + * * @param context �u�@�������� */ private void convertIndexDesignFile(JobExecutionContext context) throws JobExecutionException @@ -471,10 +485,11 @@ for (File dgnFile : dgnFiles) { IndexDgnConvertJobContext convertContext = new IndexDgnConvertJobContext(getDataPath()); + logger.debug("--- start dgnfile-" + dgnFile.toString() + " ---"); try { convertContext.setExecutionContext(context); - String dgnPaths[] = StringUtils.splitToArray(dgnFile.toString(), File.pathSeparator); + String dgnPaths[] = StringUtils.splitToArray(dgnFile.toString(), File.separator); convertContext.setFilename(dgnPaths[dgnPaths.length - 1]); FileInputStream fs = new FileInputStream(dgnFile); @@ -485,6 +500,7 @@ scanIndexDgnElement(convertContext); convertContext.commitTransaction(); + System.gc(); } catch (FileNotFoundException e) { convertContext.rollbackTransaction(); @@ -568,6 +584,7 @@ /** * �����ഫ��L�]�p���ɪ��u�@ + * * @param context */ private void convertOtherDesignFile(JobExecutionContext context) throws JobExecutionException @@ -595,10 +612,11 @@ for (File dgnFile : dgnFiles) { GeneralDgnConvertJobContext convertContext = new GeneralDgnConvertJobContext(getDataPath()); + logger.info("--- start dgnfile-" + dgnFile.toString() + " ---"); try { convertContext.setExecutionContext(context); - String dgnPaths[] = StringUtils.splitToArray(dgnFile.toString(), File.pathSeparator); + String dgnPaths[] = StringUtils.splitToArray(dgnFile.toString(), File.separator); convertContext.setFilename(dgnPaths[dgnPaths.length - 1]); FileInputStream fs = new FileInputStream(dgnFile); @@ -683,9 +701,58 @@ private void processOtherElement(Element element, GeneralDgnConvertJobContext convertContext) throws IllegalAttributeException, SchemaException { - if (element instanceof TextElement) + convertContext.putFeatureCollection(element); + } + + private void clearOutputDirectory() + { + File outDataPath = new File(getDataPath(), OracleConvertJobContext.SHPOUTPATH); + if (outDataPath.exists() && outDataPath.isDirectory()) { - convertContext.putFeatureCollection(element); + deleteFilesInPath(outDataPath); + } + outDataPath = new File(getDataPath(), IndexDgnConvertJobContext.SHPOUTPATH); + if (outDataPath.exists() && outDataPath.isDirectory()) + { + deleteFilesInPath(outDataPath); + } + outDataPath = new File(getDataPath(), GeneralDgnConvertJobContext.SHPOUTPATH); + if (outDataPath.exists() && outDataPath.isDirectory()) + { + deleteFilesInPath(outDataPath); + } + } + + private void deleteFilesInPath(File outDataPath) + { + deleteFilesInPath(outDataPath, true); + } + private void deleteFilesInPath(File outDataPath, boolean removeSubDir) + { + if (!outDataPath.isDirectory()) + { + return; + } + File[] files = outDataPath.listFiles(); + for (File file : files) + { + if (file.isFile()) + { + if (!file.delete()) + { + logger.info("Cannot delete file-" + file.toString()); + } + } else if (file.isDirectory()) + { + deleteFilesInPath(file, removeSubDir); + if (removeSubDir) + { + if (file.delete()) + { + logger.info("Cannot delete dir-" + file.toString()); + } + } + } } } } -- Gitblit v0.0.0-SNAPSHOT