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()) {
|
||||
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);
|
||||
if (success == 1) {
|
||||
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.
|
||||
|
@ -199,15 +201,11 @@ public class ColumnElementHandler extends AbstractElementHandler {
|
|||
*/
|
||||
private int createColumn(PIPOContext ctx, MTable table, MColumn column, boolean doAlter) {
|
||||
|
||||
int no = 0;
|
||||
|
||||
String sql = null;
|
||||
ResultSet rst = null;
|
||||
ResultSet rsc = null;
|
||||
Connection conn = null;
|
||||
Trx trx = Trx.get(getTrxName(ctx), true);
|
||||
if (!trx.commit())
|
||||
return 0;
|
||||
|
||||
try {
|
||||
// Find Column in Database
|
||||
|
@ -251,27 +249,32 @@ public class ColumnElementHandler extends AbstractElementHandler {
|
|||
if (sql != null && sql.trim().length() > 0) {
|
||||
log.info(sql);
|
||||
|
||||
//make it consistent for oracle and postgresql
|
||||
if (!trx.commit())
|
||||
return -1;
|
||||
|
||||
if (sql.indexOf(DB.SQLSTATEMENT_SEPARATOR) == -1) {
|
||||
no = DB.executeUpdate(sql, false, trx.getTrxName());
|
||||
if (no == -1)
|
||||
return 0;
|
||||
int ret = DB.executeUpdate(sql, false, trx.getTrxName());
|
||||
if (ret == -1)
|
||||
return -1;
|
||||
} else {
|
||||
String statements[] = sql.split(DB.SQLSTATEMENT_SEPARATOR);
|
||||
for (int i = 0; i < statements.length; i++) {
|
||||
int count = DB.executeUpdate(statements[i], false,
|
||||
int ret = DB.executeUpdate(statements[i], false,
|
||||
trx.getTrxName());
|
||||
if (count == -1) {
|
||||
return 0;
|
||||
}
|
||||
no += count;
|
||||
if (ret == -1) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
trx.commit(true);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||
trx.rollback();
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue