Search in sources :

Example 1 with GDSException

use of org.firebirdsql.gds.GDSException in project jaybird by FirebirdSQL.

the class NativeGDSFactoryPlugin method getDatabasePath.

public String getDatabasePath(String server, Integer port, String path) throws GDSException {
    if (server == null)
        throw new GDSException("Server name/address is required " + "for native implementation.");
    if (path == null)
        throw new GDSException("Database name/path is required.");
    StringBuilder sb = new StringBuilder();
    sb.append(server);
    if (port != null)
        sb.append('/').append(port.intValue());
    sb.append(':').append(path);
    return sb.toString();
}
Also used : GDSException(org.firebirdsql.gds.GDSException)

Example 2 with GDSException

use of org.firebirdsql.gds.GDSException in project jaybird by FirebirdSQL.

the class FBSQLException method getSqlErrorCode.

/**
 * Helper method to get the SQL vendor code (or in the case of Firebird: the
 * isc errorcode).
 *
 * @param ex
 *            ResourceException
 * @return isc errorcode, or 0
 */
private static int getSqlErrorCode(ResourceException ex) {
    Throwable cause = resolveCause(ex);
    if (cause instanceof GDSException) {
        return ((GDSException) cause).getIntParam();
    }
    if (cause instanceof SQLException) {
        return ((SQLException) cause).getErrorCode();
    }
    if (cause instanceof FBXAException) {
        FBXAException fbXaException = (FBXAException) cause;
        Throwable cause2 = fbXaException.getCause();
        if (cause2 instanceof SQLException) {
            return ((SQLException) cause2).getErrorCode();
        }
    }
    return 0;
}
Also used : SQLException(java.sql.SQLException) GDSException(org.firebirdsql.gds.GDSException) FBXAException(org.firebirdsql.jca.FBXAException)

Example 3 with GDSException

use of org.firebirdsql.gds.GDSException in project jaybird by FirebirdSQL.

the class OOGDSFactoryPlugin method getDatabasePath.

public String getDatabasePath(String server, Integer port, String path) throws GDSException {
    if (server == null)
        throw new GDSException("Server name/address is required for pure Java implementation.");
    if (path == null)
        throw new GDSException("Database name/path is required.");
    StringBuilder sb = new StringBuilder();
    sb.append(server);
    if (port != null)
        sb.append('/').append(port.intValue());
    sb.append(':').append(path);
    return sb.toString();
}
Also used : GDSException(org.firebirdsql.gds.GDSException)

Example 4 with GDSException

use of org.firebirdsql.gds.GDSException in project jaybird by FirebirdSQL.

the class FBDriver method connect.

@Override
public Connection connect(String url, final Properties info) throws SQLException {
    if (url == null) {
        throw new SQLException("url is null");
    }
    final GDSType type = GDSFactory.getTypeForProtocol(url);
    if (type == null) {
        return null;
    }
    final Map<String, String> mergedProperties = mergeProperties(url, info);
    try {
        int qMarkIndex = url.indexOf('?');
        if (qMarkIndex != -1) {
            url = url.substring(0, qMarkIndex);
        }
        FBManagedConnectionFactory mcf = new FBManagedConnectionFactory(type);
        String databaseURL = GDSFactory.getDatabasePath(type, url);
        // NOTE: occurrence of an explicit connection property may override this
        mcf.setDatabaseName(databaseURL);
        for (Map.Entry<String, String> entry : mergedProperties.entrySet()) {
            try {
                mcf.setProperty(entry.getKey(), entry.getValue());
            } catch (InvalidPropertyValueException e) {
                throw e.asSQLException();
            }
        }
        FBTpbMapper.processMapping(mcf, mergedProperties);
        mcf = mcf.canonicalize();
        FBDataSource dataSource = createDataSource(mcf);
        return dataSource.getConnection(mcf.getUser(), mcf.getPassword());
    } catch (GDSException e) {
        throw new FBSQLException(e);
    }
}
Also used : FBManagedConnectionFactory(org.firebirdsql.jaybird.xca.FBManagedConnectionFactory) InvalidPropertyValueException(org.firebirdsql.jaybird.props.InvalidPropertyValueException) GDSException(org.firebirdsql.gds.GDSException) GDSType(org.firebirdsql.gds.impl.GDSType) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

GDSException (org.firebirdsql.gds.GDSException)4 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 GDSType (org.firebirdsql.gds.impl.GDSType)1 InvalidPropertyValueException (org.firebirdsql.jaybird.props.InvalidPropertyValueException)1 FBManagedConnectionFactory (org.firebirdsql.jaybird.xca.FBManagedConnectionFactory)1 FBXAException (org.firebirdsql.jca.FBXAException)1