点击上方“IT那活儿”公众号,关注后了解更多内容,不管IT什么活儿,干就完了!!!
磐维数据库(cmdb)是中国移动基于openGauss内核的面向ICT基础设施的自研数据库产品。我们现场有套平台是基于Hibernate ORM框架技术开发,运行在mysql 数据库上,需要对平台进行改造适配cmdb 数据库,本文介绍改造过程所碰到的问题及其对应的解决办法。
1. ojdbc 依赖问题
Batch update returned unexpected row count from update [0]; actual row count: 13; expected: 1
方案一:使用 JDBC 操作数据库。 方案二:不修改实体类,直接编写 SQL,通过 Hibernate 的 executeSql() 方法进行更新。
ERROR: function unix_timestamp(timestamp without time zone) does not exist
SELECT
sysuserlog0_.id AS id1_108_,
sysuserlog0_.description AS descript2_108_,
sysuserlog0_.ip AS ip3_108_,
sysuserlog0_.operator AS operator4_108_,
sysuserlog0_.parameter AS paramete5_108_,
sysuserlog0_.time AS time6_108_,
sysuserlog0_.type AS type7_108_,
sysuserlog0_.url AS url8_108_
FROM
sys_userlog sysuserlog0_
ORDER BY
unix_timestamp(sysuserlog0_.time) DESC
LIMIT ?
order by unix_timestamp(time) desc
-- 修改为
order by time desc
ERROR: function date_format(timestamp without time zone, unkown) does not exist
SELECT
DATE_FORMAT(dbc.flchecktime,
'%Y-%m-%d')
FROM
dmm_basejob_checkrecords dbc
date_format(column, '%Y-%m-%d')
-- 修改为
to_char(column, 'YYYY-MM-DD')
-- 或者修改为
to_date(left(column::text,10),'YYYY-MM-DD')
ERROR: function ifnull(numeric, integer) does not exist
SELECT
IFNULL(SUM(dtc.table_rows),
0)
FROM
dmm_node_table_result dntr,
dmm_table_capacity dtc
WHERE
dntr.attachmentid = dtc.flattachmentid
AND dntr.table_name = dtc.fltablename
AND dntr.flowchart_id = '-1'
ifnull
--修改为
coalesce
注意:当使用函数 coalesce 时,第一个参数为 timestamp 时,在 PostgreSQL 中第二个参数不能为 ''。
ERROR: function any_value(character varying) does not exist
select
b.id,
b. NAME,
COUNT(distinct c.dbid) db_cnt,
COUNT( distinct c.dbid, c. OWNER, c.table_name ) tb_cnt,
b.flowchart_id flowchart_id,
MAX(ck.flchecktime) flchecktime,
b.system_id,
any_value(dpm.flname)
from
dmm_business b,
dmm_business_flowchart_node a,
dmm_node_table_result c,
dmm_basejob_checkrecords ck,
dmm_pdm_modelsystem dpm
where
b.flowchart_defined = 1
and a.flowchart_id = b.flowchart_id
and c.node_id = a.node_id
and b.flowchart_id = c.flowchart_id
and ck.flid = c.checkrecordid
and b.system_id = dpm.flid
and c.checkrecordid in(10, 7, 4, 8, 24)
and b.flowchart_defined = 1
group by
b.id
order by
flchecktime desc
limit ?
any_value(dpm.flname)
-- 修改为
max(dpm.flname) flname
ERROR: function group_concat(text) does not exist
SELECT
count(*)
FROM
(
SELECT
dct.tablecode,
GROUP_CONCAT( CONCAT( dct.flstatus,
'(',
dct.fltableid,
')' )) tableIds
FROM
dmm_pdm_attachment dpa
INNER JOIN dmm_pdm_table dpt ON
dpa.flid = dpt.flattachmentid
LEFT JOIN dmm_collect_tables dct ON
dct.tablecode = dpt.flcode
AND dct.fldbid = dpa.fldbid
WHERE
dpa.flid IN (
SELECT
dbc1.flattachmentid flid
FROM
dmm_basejob_checkrecords dbc1,
(
SELECT
dbc2.fldbid,
max(dbc2.flid) flcheckrecordid
FROM
dmm_basejob_checkrecords dbc2
WHERE
dbc2.is_success = 1
GROUP BY
dbc2.fldbid ) tmp
WHERE
dbc1.fldbid = tmp.fldbid
AND dbc1.flid = tmp.flcheckrecordid )
AND dct.flstatus != 1
AND dpa.flsystypeid =:dmmSystemId
GROUP BY
dct.tablecode) aa
GROUP_CONCAT(CONCAT( dct.flstatus,'(',dct.fltableid,')' )) tableIds
-- 修改为
string_agg(CONCAT( dct.flstatus, '(', dct.fltableid, ')' ),',') tableIds
ERROR: function any_value(character varying) does not exist
select
b.id,
b. NAME,
COUNT(distinct c.dbid) db_cnt,
COUNT( distinct c.dbid, c. OWNER, c.table_name ) tb_cnt,
b.flowchart_id flowchart_id,
MAX(ck.flchecktime) flchecktime,
b.system_id,
any_value(dpm.flname)
from
dmm_business b,
dmm_business_flowchart_node a,
dmm_node_table_result c,
dmm_basejob_checkrecords ck,
dmm_pdm_modelsystem dpm
where
b.flowchart_defined = 1
and a.flowchart_id = b.flowchart_id
and c.node_id = a.node_id
and b.flowchart_id = c.flowchart_id
and ck.flid = c.checkrecordid
and b.system_id = dpm.flid
and c.checkrecordid in(10, 7, 4, 8, 24)
and b.flowchart_defined = 1
group by
b.id
order by
flchecktime desc
limit ?
any_value(dpm.flname)
-- 修改为
max(dpm.flname) flname

本文作者:长研架构小组(上海新炬中北团队)
本文来源:“IT那活儿”公众号

文章转载自IT那活儿,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。





