IDEMPIERE-1347 2Pack: ColumnElementHandler should ensure column exists in database when IsSyncDatabase=Y. Remove unnecessary commit and packin log when there's no ddl action needed.
This commit is contained in:
parent
8052798bac
commit
6ec33a6eea
|
@ -174,14 +174,16 @@ public class ColumnElementHandler extends AbstractElementHandler {
|
||||||
if (!table.isView() && !mColumn.isVirtualColumn()) {
|
if (!table.isView() && !mColumn.isVirtualColumn()) {
|
||||||
success = createColumn(ctx, table, mColumn, recreateColumn);
|
success = createColumn(ctx, table, mColumn, recreateColumn);
|
||||||
|
|
||||||
X_AD_Package_Imp_Detail dbDetail = createImportDetail(ctx, "dbColumn", X_AD_Column.Table_Name, X_AD_Column.Table_ID);
|
if (success != 0) {
|
||||||
if (success == 1) {
|
X_AD_Package_Imp_Detail dbDetail = createImportDetail(ctx, "dbColumn", X_AD_Column.Table_Name, X_AD_Column.Table_ID);
|
||||||
logImportDetail(ctx, dbDetail, 1, mColumn.getColumnName(),
|
if (success == 1) {
|
||||||
mColumn.get_ID(), action);
|
logImportDetail(ctx, dbDetail, 1, mColumn.getColumnName(),
|
||||||
} else {
|
mColumn.get_ID(), action);
|
||||||
logImportDetail(ctx, dbDetail, 0, mColumn.getColumnName(),
|
} else {
|
||||||
mColumn.get_ID(), action);
|
logImportDetail(ctx, dbDetail, 0, mColumn.getColumnName(),
|
||||||
throw new DatabaseAccessException("Failed to create column or related constraint for " + mColumn.getColumnName());
|
mColumn.get_ID(), action);
|
||||||
|
throw new DatabaseAccessException("Failed to create column or related constraint for " + mColumn.getColumnName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -199,15 +201,11 @@ public class ColumnElementHandler extends AbstractElementHandler {
|
||||||
*/
|
*/
|
||||||
private int createColumn(PIPOContext ctx, MTable table, MColumn column, boolean doAlter) {
|
private int createColumn(PIPOContext ctx, MTable table, MColumn column, boolean doAlter) {
|
||||||
|
|
||||||
int no = 0;
|
|
||||||
|
|
||||||
String sql = null;
|
String sql = null;
|
||||||
ResultSet rst = null;
|
ResultSet rst = null;
|
||||||
ResultSet rsc = null;
|
ResultSet rsc = null;
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
Trx trx = Trx.get(getTrxName(ctx), true);
|
Trx trx = Trx.get(getTrxName(ctx), true);
|
||||||
if (!trx.commit())
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Find Column in Database
|
// Find Column in Database
|
||||||
|
@ -251,27 +249,32 @@ public class ColumnElementHandler extends AbstractElementHandler {
|
||||||
if (sql != null && sql.trim().length() > 0) {
|
if (sql != null && sql.trim().length() > 0) {
|
||||||
log.info(sql);
|
log.info(sql);
|
||||||
|
|
||||||
|
//make it consistent for oracle and postgresql
|
||||||
|
if (!trx.commit())
|
||||||
|
return -1;
|
||||||
|
|
||||||
if (sql.indexOf(DB.SQLSTATEMENT_SEPARATOR) == -1) {
|
if (sql.indexOf(DB.SQLSTATEMENT_SEPARATOR) == -1) {
|
||||||
no = DB.executeUpdate(sql, false, trx.getTrxName());
|
int ret = DB.executeUpdate(sql, false, trx.getTrxName());
|
||||||
if (no == -1)
|
if (ret == -1)
|
||||||
return 0;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
String statements[] = sql.split(DB.SQLSTATEMENT_SEPARATOR);
|
String statements[] = sql.split(DB.SQLSTATEMENT_SEPARATOR);
|
||||||
for (int i = 0; i < statements.length; i++) {
|
for (int i = 0; i < statements.length; i++) {
|
||||||
int count = DB.executeUpdate(statements[i], false,
|
int ret = DB.executeUpdate(statements[i], false,
|
||||||
trx.getTrxName());
|
trx.getTrxName());
|
||||||
if (count == -1) {
|
if (ret == -1) {
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
no += count;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
trx.commit(true);
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
trx.commit(true);
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||||
trx.rollback();
|
trx.rollback();
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue