Hello, I would like to migrate my current code from BaseX 7.3 to the latest version, but when I compile with the new library I get errors at Context.pin(...) and Context.unpin(...). I have some difficulties in finding out how to change the "pin" management. If you don't mind, I'd post two of my class's methods and I would ask you to give me some instructions how to update them. Thank you William
public synchronized Data openOrCreateContainer( Context ctx, final String path) throws IOException {
final IO io = IO.get("file:/"+ getDataDir().getAbsolutePath()); final String name = path;
// check if database is already opened *final Data data = ctx.pin(name);* if(data != null) { final IO in = data.meta.path; if(in.eq(io) && io.timeStamp() == in.timeStamp()) { // check permissions if(ctx.perm(Perm.READ, data.meta)) return data; throw new IOException(Util.info(Text.PERM_REQUIRED_X, Perm.READ)); } *ctx.unpin(data);* } // if found, an existing database is opened final Data ret; if (ctx.mprop.dbexists(name)) { ret = Open.open(name, ctx); ctx.openDB(ret); } else { new CreateDB(name).execute(ctx); ret = ctx.data(); ctx.openDB(ret); } buildIndex(); return ret; }
public boolean loadDocumentFromInputStream(InputStream stream, String docName) throws EtlException { Data cont = null; try { String containerName = docName; cont = openOrCreateContainer(CONTEXT, containerName);
IntList docs = cont.resources.docs(docName); for(final int pre : docs.toArray()) { cont.delete(pre); } Add cmd = new Add(docName); cmd.setInput(stream); cmd.execute(CONTEXT); buildIndex(); return true; } catch (Exception e) { log.error(e); throw new EtlException(e); } finally { if (cont != null) { *CONTEXT.unpin(cont);* cont.close(); } } }