mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-02 19:27:57 +08:00
Oracle soft deletion support. #PL-2197
This commit is contained in:
parent
b6698aa88e
commit
b864730d79
@ -12,6 +12,7 @@ import com.haulmont.cuba.core.entity.EntityStatistics;
|
||||
import com.haulmont.cuba.core.global.Configuration;
|
||||
import com.haulmont.cuba.core.global.Metadata;
|
||||
import com.haulmont.cuba.core.sys.DbUpdater;
|
||||
import com.haulmont.cuba.core.sys.persistence.DbmsType;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
@ -100,17 +101,24 @@ public class PersistenceManager implements PersistenceManagerAPI {
|
||||
conn = datasource.getConnection();
|
||||
DatabaseMetaData metaData = conn.getMetaData();
|
||||
|
||||
ResultSet tables = metaData.getTables(null, null, null, new String[]{"TABLE"});
|
||||
while (tables.next()) {
|
||||
String table = tables.getString("TABLE_NAME");
|
||||
if (table != null) {
|
||||
ResultSet columns = metaData.getColumns(
|
||||
null, null, table, persistence.getDbDialect().getDeleteTsColumn());
|
||||
if (columns.next()) {
|
||||
set.add(table.toLowerCase());
|
||||
}
|
||||
String schema = DbmsType.getCurrent() == DbmsType.ORACLE ? metaData.getUserName() : null;
|
||||
log.trace("[initSoftDeleteTables] schema=" + schema);
|
||||
|
||||
ResultSet tables = metaData.getTables(null, schema, null, new String[]{"TABLE"});
|
||||
while (tables.next()) {
|
||||
String table = tables.getString("TABLE_NAME");
|
||||
log.trace("[initSoftDeleteTables] found table " + table);
|
||||
|
||||
if (table != null) {
|
||||
String deleteTsColumn = persistence.getDbDialect().getDeleteTsColumn();
|
||||
ResultSet columns = metaData.getColumns(null, schema, table, deleteTsColumn);
|
||||
if (columns.next()) {
|
||||
log.trace("[initSoftDeleteTables] table " + table + " has column " + deleteTsColumn);
|
||||
set.add(table.toLowerCase());
|
||||
}
|
||||
columns.close();
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
|
@ -8,8 +8,10 @@ package com.haulmont.cuba.core.sys.persistence;
|
||||
|
||||
import org.apache.openjpa.jdbc.kernel.exps.FilterValue;
|
||||
import org.apache.openjpa.jdbc.schema.Column;
|
||||
import org.apache.openjpa.jdbc.sql.Join;
|
||||
import org.apache.openjpa.jdbc.sql.OracleDictionary;
|
||||
import org.apache.openjpa.jdbc.sql.SQLBuffer;
|
||||
import org.apache.openjpa.jdbc.sql.Select;
|
||||
|
||||
/**
|
||||
* @author degtyarjov
|
||||
@ -17,6 +19,16 @@ import org.apache.openjpa.jdbc.sql.SQLBuffer;
|
||||
*/
|
||||
public class CubaOracleDictionary extends OracleDictionary {
|
||||
|
||||
@Override
|
||||
public SQLBuffer toTraditionalJoin(Join join) {
|
||||
return DBDictionaryUtils.toTraditionalJoin(this, join);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SQLBuffer getWhere(Select sel, boolean forUpdate) {
|
||||
return DBDictionaryUtils.getWhere(this, sel, forUpdate, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeName(Column col) {
|
||||
return super.getTypeName(col);
|
||||
|
@ -40,16 +40,16 @@ public class OracleDbDialect extends DbDialect implements SequenceSupport {
|
||||
|
||||
@Override
|
||||
public String getIdColumn() {
|
||||
return "id";
|
||||
return "ID";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDeleteTsColumn() {
|
||||
return "delete_ts";
|
||||
return "DELETE_TS";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUniqueConstraintViolationPattern() {
|
||||
return "ERROR: duplicate key value violates unique constraint \"(.+)\"";
|
||||
return "unique constraint \\((.+)\\) violated";
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user