Search in sources :

Example 1 with InvalidPropertyValueException

use of org.firebirdsql.jaybird.props.InvalidPropertyValueException 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

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