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();
}
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;
}
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();
}
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);
}
}
Aggregations