Object pgconn = ((com.caucho.sql.UserConnection) userconn).getConnection();
Object pgconn = ((UserConnection) userconn).getConnection();
  public static Object pg_lo_open(Env env,                                  @NotNull Postgres conn,                                  int oid,                                  String mode)  {    try {      Object largeObject = null;      // LargeObjectManager lobManager;      Object lobManager;      //org.postgresql.largeobject.LargeObjectManager      Class cl = Class.forName("org.postgresql.PGConnection");      Method method = cl.getDeclaredMethod("getLargeObjectAPI", null);      Object userconn = conn.getConnection();      Object pgconn = ((com.caucho.sql.UserConnection) userconn).getConnection();      lobManager = method.invoke(pgconn, new Object[] {});      cl = Class.forName("org.postgresql.largeobject.LargeObjectManager");      method = cl.getDeclaredMethod("open", new Class[] {Integer.TYPE, Integer.TYPE});      boolean write = mode.indexOf("w") >= 0;      boolean read = mode.indexOf("r") >= 0;      int modeREAD = cl.getDeclaredField("READ").getInt(null);      int modeREADWRITE = cl.getDeclaredField("READWRITE").getInt(null);      int modeWRITE = cl.getDeclaredField("WRITE").getInt(null);      int intMode = modeREAD;      if (read) {        if (write) {          intMode = modeREADWRITE;        }      } else if (write) {        intMode = modeWRITE;      }      largeObject = method.invoke(lobManager, new Object[] {oid, intMode});      return largeObject;    } catch (Exception ex) {      log.log(Level.FINE, ex.toString(), ex);      return null;    }  }