Skip to content

Commit 12eb54b

Browse files
committed
Make jdbc:default:connection work after temporary disallowing JNA connections in the Jaybird fork (http://github.com/asfernandes/jaybird).
1 parent 7a7c98b commit 12eb54b

File tree

1 file changed

+37
-20
lines changed

1 file changed

+37
-20
lines changed

src/fbjava/src/main/java/org/firebirdsql/fbjava/impl/InternalDatabaseFactory.java

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
*/
1919
package org.firebirdsql.fbjava.impl;
2020

21+
import java.security.AccessController;
22+
import java.security.PrivilegedActionException;
23+
import java.security.PrivilegedExceptionAction;
2124
import java.sql.SQLException;
2225

2326
import org.firebirdsql.gds.DatabaseParameterBuffer;
@@ -48,29 +51,43 @@ public JnaDatabase connect(IConnectionProperties connectionProperties) throws SQ
4851

4952
Main.library.fb_get_database_handle(statusVector, attachmentHandle, internalContext.getAttachment());
5053

51-
JnaDatabaseConnection jnaDatabaseConnection = new JnaDatabaseConnection(
52-
getClientLibrary(), connectionProperties)
54+
try
5355
{
54-
@Override
55-
public JnaDatabase identify() throws SQLException
56+
JnaDatabaseConnection jnaDatabaseConnection =
57+
AccessController.doPrivileged(new PrivilegedExceptionAction<JnaDatabaseConnection>()
5658
{
57-
return new JnaDatabase(this) {
58-
@Override
59-
protected void attachOrCreate(DatabaseParameterBuffer dpb, boolean create) throws SQLException
60-
{
61-
handle.setValue(attachmentHandle.getValue());
62-
setAttached();
63-
afterAttachActions();
64-
}
59+
@Override
60+
public JnaDatabaseConnection run() throws Exception
61+
{
62+
return new JnaDatabaseConnection(getClientLibrary(), connectionProperties) {
63+
@Override
64+
public JnaDatabase identify() throws SQLException
65+
{
66+
return new JnaDatabase(this) {
67+
@Override
68+
protected void attachOrCreate(DatabaseParameterBuffer dpb, boolean create)
69+
throws SQLException
70+
{
71+
handle.setValue(attachmentHandle.getValue());
72+
setAttached();
73+
afterAttachActions();
74+
}
6575

66-
@Override
67-
protected void internalDetach()
68-
{
69-
}
70-
};
71-
}
72-
};
76+
@Override
77+
protected void internalDetach()
78+
{
79+
}
80+
};
81+
}
82+
};
83+
}
84+
});
7385

74-
return jnaDatabaseConnection.identify();
86+
return jnaDatabaseConnection.identify();
87+
}
88+
catch (PrivilegedActionException e)
89+
{
90+
throw new SQLException(e.getCause());
91+
}
7592
}
7693
}

0 commit comments

Comments
 (0)