Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
suliangchun
dbeaver
提交
f01e9a37
D
dbeaver
项目概览
suliangchun
/
dbeaver
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dbeaver
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f01e9a37
编写于
10月 08, 2019
作者:
S
Serge Rider
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#6745 Data type mapping fixed. Script execution logging fixed
Former-commit-id:
dc156e33
上级
22f15831
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
98 addition
and
74 deletion
+98
-74
plugins/org.jkiss.dbeaver.data.transfer/src/org/jkiss/dbeaver/tools/transfer/database/DatabaseMappingAttribute.java
...ver/tools/transfer/database/DatabaseMappingAttribute.java
+1
-69
plugins/org.jkiss.dbeaver.ext.postgresql.ui/src/org/jkiss/dbeaver/ext/postgresql/tools/fdw/PostgreFDWConfigWizard.java
...aver/ext/postgresql/tools/fdw/PostgreFDWConfigWizard.java
+5
-2
plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/exec/DBExecUtils.java
...r.model/src/org/jkiss/dbeaver/model/exec/DBExecUtils.java
+1
-1
plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/struct/DBStructUtils.java
...del/src/org/jkiss/dbeaver/model/struct/DBStructUtils.java
+91
-2
未找到文件。
plugins/org.jkiss.dbeaver.data.transfer/src/org/jkiss/dbeaver/tools/transfer/database/DatabaseMappingAttribute.java
浏览文件 @
f01e9a37
...
...
@@ -23,13 +23,9 @@ import org.jkiss.dbeaver.model.data.DBDAttributeBinding;
import
org.jkiss.dbeaver.model.impl.DBObjectNameCaseTransformer
;
import
org.jkiss.dbeaver.model.runtime.DBRProgressMonitor
;
import
org.jkiss.dbeaver.model.runtime.VoidProgressMonitor
;
import
org.jkiss.dbeaver.model.sql.SQLDataSource
;
import
org.jkiss.dbeaver.model.sql.SQLDialect
;
import
org.jkiss.dbeaver.model.struct.*
;
import
org.jkiss.utils.CommonUtils
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
/**
...
...
@@ -196,71 +192,7 @@ public class DatabaseMappingAttribute implements DatabaseMappingObject {
// Current solution looks like hack
String
typeName
=
source
.
getTypeName
();
DBPDataKind
dataKind
=
source
.
getDataKind
();
if
(
targetDataSource
instanceof
DBPDataTypeProvider
)
{
DBPDataTypeProvider
dataTypeProvider
=
(
DBPDataTypeProvider
)
targetDataSource
;
DBSDataType
dataType
=
dataTypeProvider
.
getLocalDataType
(
typeName
);
if
(
dataType
==
null
&&
typeName
.
equals
(
"DOUBLE"
))
{
dataType
=
dataTypeProvider
.
getLocalDataType
(
"DOUBLE PRECISION"
);
if
(
dataType
!=
null
)
{
typeName
=
dataType
.
getTypeName
();
}
}
if
(
dataType
!=
null
&&
!
DBPDataKind
.
canConsume
(
dataKind
,
dataType
.
getDataKind
()))
{
// Type mismatch
dataType
=
null
;
}
if
(
dataType
==
null
)
{
// Type not supported by target database
// Let's try to find something similar
List
<
DBSDataType
>
possibleTypes
=
new
ArrayList
<>();
for
(
DBSDataType
type
:
dataTypeProvider
.
getLocalDataTypes
())
{
if
(
type
.
getDataKind
()
==
dataKind
)
{
possibleTypes
.
add
(
type
);
}
}
DBSDataType
targetType
=
null
;
if
(!
possibleTypes
.
isEmpty
())
{
// Try to get any partial match
for
(
DBSDataType
type
:
possibleTypes
)
{
if
(
type
.
getName
().
equalsIgnoreCase
(
typeName
))
{
targetType
=
type
;
break
;
}
}
}
if
(
targetType
==
null
)
{
typeName
=
DBUtils
.
getDefaultDataTypeName
(
targetDataSource
,
dataKind
);
if
(!
possibleTypes
.
isEmpty
())
{
for
(
DBSDataType
type
:
possibleTypes
)
{
if
(
type
.
getName
().
equalsIgnoreCase
(
typeName
))
{
targetType
=
type
;
break
;
}
}
}
}
if
(
targetType
==
null
&&
!
possibleTypes
.
isEmpty
())
{
targetType
=
possibleTypes
.
get
(
0
);
}
if
(
targetType
!=
null
)
{
typeName
=
targetType
.
getTypeName
();
}
}
if
(
dataType
!=
null
)
{
dataKind
=
dataType
.
getDataKind
();
}
}
// Get type modifiers from target datasource
if
(
source
!=
null
&&
targetDataSource
instanceof
SQLDataSource
)
{
SQLDialect
dialect
=
((
SQLDataSource
)
targetDataSource
).
getSQLDialect
();
String
modifiers
=
dialect
.
getColumnTypeModifiers
(
targetDataSource
,
source
,
typeName
,
dataKind
);
if
(
modifiers
!=
null
)
{
typeName
+=
modifiers
;
}
}
return
typeName
;
return
DBStructUtils
.
mapTargetDataType
(
targetDataSource
,
source
);
}
public
void
setTargetType
(
String
targetType
)
...
...
plugins/org.jkiss.dbeaver.ext.postgresql.ui/src/org/jkiss/dbeaver/ext/postgresql/tools/fdw/PostgreFDWConfigWizard.java
浏览文件 @
f01e9a37
...
...
@@ -38,8 +38,10 @@ import org.jkiss.dbeaver.model.navigator.DBNDataSource;
import
org.jkiss.dbeaver.model.navigator.DBNDatabaseNode
;
import
org.jkiss.dbeaver.model.navigator.DBNModel
;
import
org.jkiss.dbeaver.model.runtime.DBRProgressMonitor
;
import
org.jkiss.dbeaver.model.sql.SQLUtils
;
import
org.jkiss.dbeaver.model.struct.DBSEntity
;
import
org.jkiss.dbeaver.model.struct.DBSEntityAttribute
;
import
org.jkiss.dbeaver.model.struct.DBStructUtils
;
import
org.jkiss.dbeaver.model.virtual.DBVContainer
;
import
org.jkiss.dbeaver.model.virtual.DBVEntity
;
import
org.jkiss.dbeaver.model.virtual.DBVEntityForeignKey
;
...
...
@@ -326,8 +328,9 @@ class PostgreFDWConfigWizard extends BaseWizard implements DBPContextProvider {
PostgreTableColumn
newColumn
=
columnManager
.
createNewObject
(
monitor
,
commandContext
,
pgTable
,
null
,
options
);
assert
newColumn
!=
null
;
newColumn
.
setName
(
attr
.
getName
());
String
defTypeName
=
database
.
getDefaultDataTypeName
(
attr
.
getDataKind
());
PostgreDataType
dataType
=
database
.
getDataType
(
monitor
,
defTypeName
);
String
defTypeName
=
DBStructUtils
.
mapTargetDataType
(
database
.
getDataSource
(),
attr
);
String
plainTargetTypeName
=
SQLUtils
.
stripColumnTypeModifiers
(
defTypeName
);
PostgreDataType
dataType
=
database
.
getDataType
(
monitor
,
plainTargetTypeName
);
newColumn
.
setDataType
(
dataType
);
}
...
...
plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/exec/DBExecUtils.java
浏览文件 @
f01e9a37
...
...
@@ -231,7 +231,7 @@ public class DBExecUtils {
}
String
script
=
action
.
getScript
();
if
(!
CommonUtils
.
isEmpty
(
script
))
{
try
(
final
Statement
statement
=
((
JDBCSession
)
session
).
getOriginal
().
createStatement
())
{
try
(
final
Statement
statement
=
((
JDBCSession
)
session
).
createStatement
())
{
statement
.
execute
(
script
);
}
}
...
...
plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/struct/DBStructUtils.java
浏览文件 @
f01e9a37
...
...
@@ -19,13 +19,14 @@ package org.jkiss.dbeaver.model.struct;
import
org.jkiss.code.NotNull
;
import
org.jkiss.dbeaver.DBException
;
import
org.jkiss.dbeaver.Log
;
import
org.jkiss.dbeaver.model.DBPScriptObject
;
import
org.jkiss.dbeaver.model.DBPScriptObjectExt2
;
import
org.jkiss.dbeaver.model.*
;
import
org.jkiss.dbeaver.model.edit.DBEPersistAction
;
import
org.jkiss.dbeaver.model.edit.DBERegistry
;
import
org.jkiss.dbeaver.model.impl.sql.edit.SQLObjectEditor
;
import
org.jkiss.dbeaver.model.impl.sql.edit.struct.SQLTableManager
;
import
org.jkiss.dbeaver.model.runtime.DBRProgressMonitor
;
import
org.jkiss.dbeaver.model.sql.SQLDataSource
;
import
org.jkiss.dbeaver.model.sql.SQLDialect
;
import
org.jkiss.dbeaver.model.sql.SQLUtils
;
import
org.jkiss.dbeaver.model.struct.rdb.DBSTable
;
import
org.jkiss.dbeaver.model.struct.rdb.DBSView
;
...
...
@@ -184,4 +185,92 @@ public final class DBStructUtils {
cyclicTables
.
addAll
(
realTables
);
}
public
static
String
mapTargetDataType
(
DBPDataSource
targetDataSource
,
DBSTypedObject
typedObject
)
{
String
typeName
=
typedObject
.
getTypeName
();
String
typeNameLower
=
typeName
.
toLowerCase
(
Locale
.
ENGLISH
);
DBPDataKind
dataKind
=
typedObject
.
getDataKind
();
if
(
targetDataSource
instanceof
DBPDataTypeProvider
)
{
DBPDataTypeProvider
dataTypeProvider
=
(
DBPDataTypeProvider
)
targetDataSource
;
DBSDataType
dataType
=
dataTypeProvider
.
getLocalDataType
(
typeName
);
if
(
dataType
==
null
&&
typeNameLower
.
equals
(
"double"
))
{
dataType
=
dataTypeProvider
.
getLocalDataType
(
"DOUBLE PRECISION"
);
if
(
dataType
!=
null
)
{
typeName
=
dataType
.
getTypeName
();
}
}
if
(
dataType
!=
null
&&
!
DBPDataKind
.
canConsume
(
dataKind
,
dataType
.
getDataKind
()))
{
// Type mismatch
dataType
=
null
;
}
if
(
dataType
==
null
)
{
// Type not supported by target database
// Let's try to find something similar
Map
<
String
,
DBSDataType
>
possibleTypes
=
new
HashMap
<>();
for
(
DBSDataType
type
:
dataTypeProvider
.
getLocalDataTypes
())
{
if
(
type
.
getDataKind
()
==
dataKind
)
{
possibleTypes
.
put
(
type
.
getTypeName
().
toLowerCase
(
Locale
.
ENGLISH
),
type
);
}
}
DBSDataType
targetType
=
null
;
if
(!
possibleTypes
.
isEmpty
())
{
// Try to get any partial match
targetType
=
possibleTypes
.
get
(
typeNameLower
);
if
(
targetType
==
null
&&
dataKind
==
DBPDataKind
.
NUMERIC
)
{
// Try to find appropriate type with the same scale/precision
for
(
DBSDataType
type
:
possibleTypes
.
values
())
{
if
(
CommonUtils
.
equalObjects
(
type
.
getScale
(),
typedObject
.
getScale
())
&&
CommonUtils
.
equalObjects
(
type
.
getPrecision
(),
typedObject
.
getPrecision
()))
{
targetType
=
type
;
break
;
}
}
if
(
targetType
==
null
)
{
if
(
typeNameLower
.
contains
(
"float"
))
{
for
(
String
psn
:
possibleTypes
.
keySet
())
{
if
(
psn
.
contains
(
"float"
))
{
targetType
=
possibleTypes
.
get
(
psn
);
break
;
}
}
}
else
if
(
typeNameLower
.
contains
(
"double"
))
{
for
(
String
psn
:
possibleTypes
.
keySet
())
{
if
(
psn
.
contains
(
"double"
))
{
targetType
=
possibleTypes
.
get
(
psn
);
break
;
}
}
}
}
}
}
if
(
targetType
==
null
)
{
typeName
=
DBUtils
.
getDefaultDataTypeName
(
targetDataSource
,
dataKind
);
typeNameLower
=
typeName
.
toLowerCase
(
Locale
.
ENGLISH
);
if
(!
possibleTypes
.
isEmpty
())
{
targetType
=
possibleTypes
.
get
(
typeNameLower
);
}
}
if
(
targetType
==
null
&&
!
possibleTypes
.
isEmpty
())
{
targetType
=
possibleTypes
.
values
().
iterator
().
next
();
}
if
(
targetType
!=
null
)
{
typeName
=
targetType
.
getTypeName
();
}
}
if
(
dataType
!=
null
)
{
dataKind
=
dataType
.
getDataKind
();
}
}
// Get type modifiers from target datasource
if
(
targetDataSource
instanceof
SQLDataSource
)
{
SQLDialect
dialect
=
((
SQLDataSource
)
targetDataSource
).
getSQLDialect
();
String
modifiers
=
dialect
.
getColumnTypeModifiers
(
targetDataSource
,
typedObject
,
typeName
,
dataKind
);
if
(
modifiers
!=
null
)
{
typeName
+=
modifiers
;
}
}
return
typeName
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录