Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/org/openbravo/ddlutils/util/DBSMException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
************************************************************************************
* Copyright (C) 2001-2020 Openbravo S.L.U.
* Licensed under the Apache Software License version 2.0
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
************************************************************************************
*/

package org.openbravo.ddlutils.util;

/**
* Exception specific to errors related to DB Source Manager (DBSM).
* <p>
* This exception extends {@link RuntimeException}, making it an unchecked exception
* that does not need to be declared in method signatures.
* </p>
*
* <p>
* It is used to wrap errors that occur during DB Source Manager operations,
* such as schema generation, validation, or script execution.
* </p>
*/
public class DBSMException extends RuntimeException {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion

Consider adding the default constructor and the constructor that accepts a Throwable cause.

public class DBSMException extends RuntimeException {

  public DBSMException() {
    super();
  }

  public DBSMException(Throwable cause) {
    super(cause);
  }

Rationale: Adding the default constructor and the constructor that accepts only a Throwable is a best practice for custom exceptions, allowing for greater flexibility when wrapping other exceptions without needing a custom message.

private static final long serialVersionUID = 1L;

/**
* Constructs a new {@code DBSMException} with the specified detail message.
*
* @param message the detail message describing the error
*/
public DBSMException(String message) {
super(message);
}

/**
* Constructs a new {@code DBSMException} with the specified detail message and cause.
*
* @param message the detail message describing the error
* @param cause the original cause of the exception
*/
public DBSMException(String message, Throwable cause) {
super(message, cause);
}
}
10 changes: 5 additions & 5 deletions src/org/openbravo/ddlutils/util/DBSMOBUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
import org.apache.log4j.Logger;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.openbravo.base.exception.OBException;

import org.openbravo.ddlutils.task.DatabaseUtils;

public class DBSMOBUtil {
Expand Down Expand Up @@ -648,17 +648,17 @@ private Connection getUnpooledConnection() {
File sslRootCertFile = new File(sslRootCert);
if (sslRootCertFile.exists() && sslRootCertFile.isFile()) {
if (!sslRootCertFile.canRead()) {
throw new OBException("SSL root certificate file is not readable: " + sslRootCertFile.getAbsolutePath());
throw new DBSMException("SSL root certificate file is not readable: " + sslRootCertFile.getAbsolutePath());
}
connProps.setProperty("sslrootcert", sslRootCertFile.getAbsolutePath());
} else {
throw new OBException("SSL root certificate file not found: " + sslRootCert);
throw new DBSMException("SSL root certificate file not found: " + sslRootCert);
}
} else {
// If the mode requires verification, the certificate is mandatory.
if (StringUtils.equals("verify-full", (connProps.getProperty(SSLMODE))) ||
StringUtils.equals("verify-ca", (connProps.getProperty(SSLMODE)))) {
throw new OBException("bbdd.sslrootcert property is required when bbdd.sslfactory is not set and sslmode is " + connProps.getProperty(
throw new DBSMException("bbdd.sslrootcert property is required when bbdd.sslfactory is not set and sslmode is " + connProps.getProperty(
SSLMODE));
}
}
Expand All @@ -677,7 +677,7 @@ private Connection getUnpooledConnection() {
errorMsg.append(", sslfactory=").append(sslFactory != null ? sslFactory : "not set");
errorMsg.append(", sslrootcert=").append(sslRootCert != null ? sslRootCert : "not set");
getLog().error("Error while retrieving an unpooled connection: " + errorMsg.toString(), e);
throw new OBException(errorMsg.toString(), e);
throw new DBSMException(errorMsg.toString(), e);
}
return connection;
}
Expand Down
Loading