codingapi / codingapi/tx-lcn

txc模式,不兼容postgresql的原因

Aperta
#314 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub
features/postgreSQL
Lingua principale
Java
Stelle
4.2k
Fork
1.4k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

我们公司用的是postgresql , 我用了txc 模式,无论换任何数据源和驱动,在插入数据的时候
都会报 ResultSet 已经关闭的错误

后来检查了lcn 的代码,发现了问题

模块: txlcn-tc
类 TxcServiceImpl

方法截图
@Override
public void resolveInsertImage(InsertImageParams insertImageParams) throws TxcLogicException {
List primaryKeys = new ArrayList<>();
FieldCluster fieldCluster = new FieldCluster();
fieldCluster.setPrimaryKeys(primaryKeys);
ResultSet resultSet = null;
try {
resultSet = insertImageParams.getStatement().getGeneratedKeys();
} catch (SQLException ignored) {
// ignored non gen key.
}
try {
for (int i = 0; i < insertImageParams.getPrimaryKeyValuesList().size(); i++) {
Map pks = insertImageParams.getPrimaryKeyValuesList().get(i);
for (String key : insertImageParams.getFullyQualifiedPrimaryKeys()) {
FieldValue fieldValue = new FieldValue();
fieldValue.setFieldName(key);
if (pks.containsKey(key)) {
fieldValue.setValue(pks.get(key));
} else if (Objects.nonNull(resultSet)) {
try {
resultSet.next();
fieldValue.setValue(resultSet.getObject(1));
} catch (SQLException ignored) {
}
}
primaryKeys.add(fieldValue);
}
}
} finally {
try {
DbUtils.close(resultSet);
} catch (SQLException ignored) {
}
}

// save to db
TableRecordList tableRecords = new TableRecordList();
tableRecords.getTableRecords().add(new TableRecord(insertImageParams.getTableName(), fieldCluster));
saveUndoLog(DTXLocalContext.cur().getGroupId(), DTXLocalContext.cur().getUnitId(), SqlUtils.SQL_TYPE_INSERT, tableRecords);
}

修改过程:
把下面这段注释了,就解决问题了
try {
DbUtils.close(resultSet);
} catch (SQLException ignored) {
}

原因: postgresql 的 metacheck ,会去检查ResultSet 的状态,mysql 则不会
以上代码close 的是 insert 上下文带来的ResultSet,因此可能是这个报错

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Inizia in txlcn-tc, in TxcServiceImpl.resolveInsertImage, concentrandoti su getGeneratedKeys(), sull'elaborazione di ResultSet e sul blocco DbUtils.close(resultSet). Riproduci un insert con PostgreSQL e verifica che l'operazione venga completata senza un errore ResultSet-closed e che la gestione della chiave generata e il salvataggio dell'undo-log continuino a funzionare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
java, postgresql
Ambito
databases, distributed-systems
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.