PostgresLargeObjectManager { public final Long createLO(Connection connection) throws SQLException { if (shouldUseReflection) { Object largeObjectManager = getLargeObjectManager(connection); try { Method method = largeObjectManager.getClass().getMethod("createLO"); return (Long) method.invoke(largeObjectManager); } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { throw new SQLException("Couldn't access org.postgresql.largeobject.LargeObjectManager", ex); } } else { return ((PGConnection) unwrap(connection)).getLargeObjectAPI().createLO(); } } PostgresLargeObjectManager(); final Long createLO(Connection connection); Object open(Connection connection, long oid, int mode); int size(Object largeObject); void close(Object largeObject); byte[] read(Object largeObject, int length); void write(Object largeObject, byte[] data); void seek(Object largeObject, int position); void truncate(Object largeObject, int position); final Connection unwrap(Connection connection); static final int WRITE; static final int READ; static final int READWRITE; }
@Test public void testShouldNotUseReflection() throws SQLException { PostgresLargeObjectManager manager = new PostgresLargeObjectManager(); try { manager.createLO(new MockConnection()); fail("Shouldn't be using reflection"); } catch (ClassCastException ex) { } }