Skip to content

Commit

Permalink
not directly related cleanups:
Browse files Browse the repository at this point in the history
* AbstractTrxManager: user wrapIfNeeded which can return a more specific
DBException subclass
* Trx: remove unneeded ifs
* TimeUtil and DBException: minor, see for yourself


Prevent users from creating duplicate main prices #2510
  • Loading branch information
metas-ts committed Sep 20, 2017
1 parent 9fb84b7 commit e5c80c7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 25 deletions.
Expand Up @@ -20,6 +20,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

import org.adempiere.util.Check;
import org.adempiere.util.exceptions.IExceptionWrapper;
Expand Down Expand Up @@ -327,7 +328,7 @@ else if (e instanceof DBException)
public static final boolean isSQLState(final Throwable e, final String sqlState)
{
final String exceptionSQLState = extractSQLStateOrNull(e);
return Check.equals(exceptionSQLState, sqlState);
return Objects.equals(exceptionSQLState, sqlState);
}

/**
Expand Down
Expand Up @@ -1072,7 +1072,9 @@ public static Timestamp trunc(final Date dayTime, final String trunc)
return new Timestamp(truncToMillis(dayTime, trunc));
}

public static long truncToMillis(Date dayTime, final String trunc)
public static long truncToMillis(
@Nullable Date dayTime,
final String trunc)
{
if (dayTime == null)
{
Expand Down
Expand Up @@ -259,32 +259,22 @@ protected boolean rollbackNative(boolean throwException) throws SQLException
}

// Case: we really have something to rollback (because connection was acquired and used)
if (connection != null)
try
{
try
{
connection.rollback();
log.debug("rollbackNative: OK - {}", trxName);
return true;
}
catch (SQLException e)
{
log.error("rollbackNative: FAILED - {} (throwException={})", trxName, throwException, e);
if (throwException)
{
throw e;
}
return false;
}
connection.rollback();
log.debug("rollbackNative: OK - {}", trxName);
return true;
}
//
// Case: nothing was done on this transaction (because connection is null, so it was not acquired)
else
catch (final SQLException e)
{
// => consider this a success because if nothing was done then there is nothing to rollback
return true;
log.error("rollbackNative: FAILED - {} (throwException={})", trxName, throwException, e);
if (throwException)
{
throw e;
}
return false;
}
} // rollback
}

@Override
protected boolean rollbackNative(ITrxSavepoint savepoint) throws SQLException
Expand Down
Expand Up @@ -983,7 +983,7 @@ public void commit(final String trxName)
}
catch (final Exception e)
{
throw new DBException(e);
throw DBException.wrapIfNeeded(e);
}
}

Expand Down

0 comments on commit e5c80c7

Please sign in to comment.