Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MaxKey单点登录官方
Blazer
提交
9eceabc3
B
Blazer
项目概览
MaxKey单点登录官方
/
Blazer
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
Blazer
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
9eceabc3
编写于
3月 24, 2020
作者:
MaxKey单点登录官方
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
u
上级
e994a2d4
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
0 addition
and
224 deletion
+0
-224
blazer-trans/src/main/java/com/blazer/export/file/TransDataExport.java
...src/main/java/com/blazer/export/file/TransDataExport.java
+0
-6
blazer-trans/src/main/java/com/blazer/export/file/runner/TransDataExport2Sql.java
...va/com/blazer/export/file/runner/TransDataExport2Sql.java
+0
-218
未找到文件。
blazer-trans/src/main/java/com/blazer/export/file/TransDataExport.java
浏览文件 @
9eceabc3
...
@@ -21,7 +21,6 @@ import org.slf4j.Logger;
...
@@ -21,7 +21,6 @@ import org.slf4j.Logger;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
com.blazer.export.file.runner.TransDataExport2Csv
;
import
com.blazer.export.file.runner.TransDataExport2Csv
;
import
com.blazer.export.file.runner.TransDataExport2Sql
;
import
com.blazer.export.file.runner.TransDataExport2Xlsx
;
import
com.blazer.export.file.runner.TransDataExport2Xlsx
;
import
com.blazer.pipeline.PipeLineTask
;
import
com.blazer.pipeline.PipeLineTask
;
...
@@ -310,11 +309,6 @@ public class TransDataExport extends BasicConfigure implements PipeLineTask{
...
@@ -310,11 +309,6 @@ public class TransDataExport extends BasicConfigure implements PipeLineTask{
commitNumber
,
threadNumber
,
commitNumber
,
threadNumber
,
tableName
,
outFileName
,
fileNameSuffix
,
tableName
,
outFileName
,
fileNameSuffix
,
terminatedString
,
threadSql
,
exportFilePath
,
limitTextSize
);
terminatedString
,
threadSql
,
exportFilePath
,
limitTextSize
);
}
if
(
this
.
fileType
.
equalsIgnoreCase
(
"sql"
))
{
transThread
=
new
TransDataExport2Sql
(
sourceDataSource
,
commitNumber
,
threadNumber
,
tableName
,
outFileName
,
fileNameSuffix
,
terminatedString
,
threadSql
,
exportFilePath
,
limitTextSize
);
}
else
{
}
else
{
transThread
=
new
TransDataExport2Xlsx
(
sourceDataSource
,
transThread
=
new
TransDataExport2Xlsx
(
sourceDataSource
,
...
...
blazer-trans/src/main/java/com/blazer/export/file/runner/TransDataExport2Sql.java
已删除
100644 → 0
浏览文件 @
e994a2d4
/**
*
*/
package
com.blazer.export.file.runner
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.Reader
;
import
java.sql.Connection
;
import
java.sql.ResultSet
;
import
java.sql.ResultSetMetaData
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.util.ArrayList
;
import
javax.sql.DataSource
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
com.blazer.db.TableColumns
;
import
com.blazer.export.file.BasicConfigure
;
import
com.blazer.export.file.TransDataExport
;
/**
* @author mhshi
*
*/
public
class
TransDataExport2Sql
extends
BasicConfigure
implements
Runnable
{
private
static
final
Logger
_logger
=
LoggerFactory
.
getLogger
(
TransDataExport2Sql
.
class
);
String
selectSqlString
;
int
threadNumber
=
1
;
FileOutputStream
fop
=
null
;
long
commitCount
=
0
;
ArrayList
<
TableColumns
>
listTableColumns
;
public
TransDataExport2Sql
(
DataSource
sourceDataSource
,
int
commitNumber
,
int
threadNumber
,
String
tableName
,
String
outFileName
,
String
fileNameSuffix
,
String
terminatedString
,
String
selectSqlString
,
String
exportFilePath
,
int
limitTextSize
)
{
super
();
this
.
commitNumber
=
commitNumber
;
this
.
threadNumber
=
threadNumber
;
this
.
tableName
=
tableName
;
this
.
outFileName
=
outFileName
;
this
.
fileNameSuffix
=
fileNameSuffix
;
this
.
terminatedString
=
terminatedString
;
this
.
selectSqlString
=
selectSqlString
;
this
.
exportFilePath
=
exportFilePath
;
this
.
sourceDataSource
=
sourceDataSource
;
this
.
limitTextSize
=
limitTextSize
;
}
@Override
public
void
run
()
{
// TODO Auto-generated method stub
File
exportFilePathName
=
new
File
(
exportFilePath
+
outFileName
+
"_"
+
threadNumber
+
fileNameSuffix
);
try
{
if
(
exportFilePathName
.
exists
()){
exportFilePathName
.
delete
();
}
exportFilePathName
.
createNewFile
();
this
.
fop
=
new
FileOutputStream
(
exportFilePathName
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
listTableColumns
=
new
ArrayList
<
TableColumns
>();
try
{
Connection
sourcConn
=
sourceDataSource
.
getConnection
();
Statement
sourcStmt
=
sourcConn
.
createStatement
();
ResultSet
sourceRs
=
sourcStmt
.
executeQuery
(
selectSqlString
);
buildMetaData
(
sourceRs
);
batchWrite
(
sourceRs
);
sourceRs
.
close
();
sourcStmt
.
close
();
sourcConn
.
close
();
fop
.
close
();
Thread
.
sleep
(
2000
);
successThread
();
}
catch
(
Exception
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
_logger
.
info
(
"--thread "
+
threadNumber
+
" -- Fail ."
);
_logger
.
error
(
"导出数据错误"
,
e
);
}
TransDataExport
.
mCountDownLatch
.
countDown
();
}
//TODO
public
synchronized
void
successThread
()
{
TransDataExport
.
successThread
[
threadNumber
-
1
]=
commitCount
;
_logger
.
info
(
"--thread "
+
threadNumber
+
" data count "
+
TransDataExport
.
successThread
[
threadNumber
-
1
]+
" -- Complete ."
);
}
public
void
batchWrite
(
ResultSet
rs
)
throws
Exception
{
long
insertNum
=
0
;
StringBuffer
stringBufferLines
=
new
StringBuffer
(
""
);
while
(
rs
.
next
()){
for
(
int
ccount
=
0
;
ccount
<
listTableColumns
.
size
();
ccount
++){
TableColumns
tc
=
listTableColumns
.
get
(
ccount
);
//_logger.info("--column "+tc.getColumnName()+" , "+tc.getDataType() );
if
(
tc
.
getDataType
().
equalsIgnoreCase
(
"VARCHAR2"
)||
tc
.
getDataType
().
equalsIgnoreCase
(
"VARCHAR"
)||
tc
.
getDataType
().
equalsIgnoreCase
(
"NVARCHAR2"
)||
tc
.
getDataType
().
equalsIgnoreCase
(
"CHAR"
)||
tc
.
getDataType
().
equalsIgnoreCase
(
"RAW"
)
){
//_logger.info("==="+tc.getColumnName());
String
strColumnValue
=
rs
.
getString
(
tc
.
getColumnName
());
//长度大于limitTextSize,进行截取
if
(
strColumnValue
!=
null
&&
0
<
this
.
limitTextSize
&&
limitTextSize
<
strColumnValue
.
length
())
{
strColumnValue
=
strColumnValue
.
substring
(
0
,
limitTextSize
);
}
//回车、换行替换成ASCII char 26/SUB,在导入到数据库中需要替换成char13
stringBufferLines
.
append
(
strColumnValue
==
null
?
""
:
strColumnValue
.
trim
().
replaceAll
(
"\r"
,
(
char
)
26
+
""
).
replaceAll
(
"\n"
,
(
char
)(
26
)+
""
));
}
else
if
(
tc
.
getDataType
().
equalsIgnoreCase
(
"NUMBER"
)){
if
(
tc
.
getDataLength
()==
22
&&
tc
.
getDataScale
()>
0
){
//NUMBER
stringBufferLines
.
append
(
rs
.
getLong
(
tc
.
getColumnName
()));
//targetPstmt.setLong(pos, rs.getLong(tc.getColumnName()));
}
else
if
(
tc
.
getDataLength
()==
22
&&
tc
.
getDataScale
()==
0
){
//INTEGER
stringBufferLines
.
append
(
rs
.
getInt
(
tc
.
getColumnName
()));
//targetPstmt.setInt(pos, rs.getInt(tc.getColumnName()));
}
else
if
(
tc
.
getDataPrecision
()==
0
||
tc
.
getDataScale
()==
0
||
tc
.
getDataScale
()==
0
){
//LONG
stringBufferLines
.
append
(
rs
.
getLong
(
tc
.
getColumnName
()));
//targetPstmt.setLong(pos, rs.getLong(tc.getColumnName()));
}
else
{
//DOUBLE
stringBufferLines
.
append
(
rs
.
getDouble
(
tc
.
getColumnName
()));
//targetPstmt.setDouble(pos, rs.getDouble(tc.getColumnName()));
}
}
else
if
(
tc
.
getDataType
().
equalsIgnoreCase
(
"blob"
)){
stringBufferLines
.
append
(
getBlob
(
rs
,
tc
.
getColumnName
()));
}
else
if
(
tc
.
getDataType
().
equalsIgnoreCase
(
"clob"
)||
tc
.
getDataType
().
equalsIgnoreCase
(
"NCLOB"
)){
String
lobString
=
getClob
(
rs
,
tc
.
getColumnName
());
//_logger.info(lobString);
if
(
0
<
this
.
limitTextSize
&&
limitTextSize
<
lobString
.
length
())
lobString
=
lobString
.
substring
(
0
,
limitTextSize
);
stringBufferLines
.
append
(
lobString
==
null
?
""
:
lobString
.
replaceAll
(
"\r"
,
(
char
)(
26
)+
""
).
replaceAll
(
"\n"
,
(
char
)
26
+
""
));
}
else
if
(
tc
.
getDataType
().
equalsIgnoreCase
(
"DATE"
)){
stringBufferLines
.
append
(
rs
.
getDate
(
tc
.
getColumnName
()));
//targetPstmt.setDate(pos, rs.getDate(tc.getColumnName()));
}
else
{
stringBufferLines
.
append
(
rs
.
getObject
(
tc
.
getColumnName
()));
}
if
(
ccount
!=
listTableColumns
.
size
()-
1
){
stringBufferLines
.
append
(
terminatedString
);
}
else
{
stringBufferLines
.
append
(
"\r\n"
);
}
}
commitCount
++;
insertNum
+=
1
;
if
(
insertNum
>=
this
.
commitNumber
)
{
insertNum
=
0
;
_logger
.
info
(
"--thread "
+
threadNumber
+
"--Commit Count "
+
commitCount
);
fop
.
write
(
stringBufferLines
.
toString
().
getBytes
());
stringBufferLines
=
new
StringBuffer
(
""
);
}
}
if
(
insertNum
>
0
){
_logger
.
info
(
"--thread "
+
threadNumber
+
"--Commit Count "
+
commitCount
+
" Complete ."
);
fop
.
write
(
stringBufferLines
.
toString
().
getBytes
());
}
}
public
String
getClob
(
ResultSet
sourceRs
,
String
column
)
throws
Exception
{
oracle
.
sql
.
CLOB
sb
=(
oracle
.
sql
.
CLOB
)
sourceRs
.
getClob
(
column
);
if
(
sb
==
null
)
return
""
;
Reader
is
=
sb
.
getCharacterStream
();
char
[]
data
=
new
char
[(
int
)
sb
.
length
()];
is
.
read
(
data
);
is
.
close
();
return
new
String
(
data
);
}
public
String
getBlob
(
ResultSet
sourceRs
,
String
column
)
throws
Exception
{
oracle
.
sql
.
BLOB
sb
=(
oracle
.
sql
.
BLOB
)
sourceRs
.
getBlob
(
column
);
if
(
sb
==
null
)
return
""
;
InputStream
is
=
sb
.
getBinaryStream
();
byte
[]
data
=
new
byte
[(
int
)
sb
.
length
()];
is
.
read
(
data
);
is
.
close
();
return
new
String
(
data
);
}
public
void
buildMetaData
(
ResultSet
rs
)
throws
SQLException
{
ResultSetMetaData
metaData
=
rs
.
getMetaData
();
_logger
.
debug
(
"--thread "
+
threadNumber
+
"--column Count "
+
metaData
.
getColumnCount
()
);
for
(
int
i
=
1
;
i
<=
metaData
.
getColumnCount
();
i
++)
{
TableColumns
tc
=
new
TableColumns
();
tc
.
setColumnName
(
metaData
.
getColumnName
(
i
));
tc
.
setDataType
(
metaData
.
getColumnTypeName
(
i
));
tc
.
setTableName
(
metaData
.
getTableName
(
i
));
tc
.
setDataPrecision
(
metaData
.
getPrecision
(
i
));
tc
.
setDataScale
(
metaData
.
getScale
(
i
));
_logger
.
debug
(
"--thread "
+
threadNumber
+
"--No. "
+
i
+
" , Column "
+
tc
.
getColumnName
()+
" , DataType "
+
tc
.
getDataType
()
);
listTableColumns
.
add
(
tc
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录