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,6 +174,7 @@ 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);
|
||||||
|
|
||||||
|
if (success != 0) {
|
||||||
X_AD_Package_Imp_Detail dbDetail = createImportDetail(ctx, "dbColumn", X_AD_Column.Table_Name, X_AD_Column.Table_ID);
|
X_AD_Package_Imp_Detail dbDetail = createImportDetail(ctx, "dbColumn", X_AD_Column.Table_Name, X_AD_Column.Table_ID);
|
||||||
if (success == 1) {
|
if (success == 1) {
|
||||||
logImportDetail(ctx, dbDetail, 1, mColumn.getColumnName(),
|
logImportDetail(ctx, dbDetail, 1, mColumn.getColumnName(),
|
||||||
|
@ -185,6 +186,7 @@ public class ColumnElementHandler extends AbstractElementHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if column exists in database and modify. If not create column.
|
* Check if column exists in database and modify. If not create column.
|
||||||
|
@ -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);
|
trx.commit(true);
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
} 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