Hi William,
I guess your code is too incomplete in order to tell what may be wrong. Somme spontaneous comments:
• I wonder if both methods use the same context (ctx/CONTEXT)? • It looks dangerous to me to mix static functions (e.g. Open.open) and instance functions (e.g. new CreateDB(name).execute) • A database won’t be unpinned when throwing the IOException in the first function • Why do you use the pin functions at all? If you want to do so, please ensure that pinned databases will always be unpinned.
Christian
On Mon, Dec 23, 2013 at 10:49 AM, William Sandri wsandri@bpeng.com wrote:
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(); } } }
-- William Sandri Business Process Engineering S.r.l. 38068 Rovereto (TN) Via Per Marco 12/A tel: +39 0464 07 60 23 fax: +39 0464 07 20 09 web phone: sip:wsandri@mail.bpeng.com web site:http://www.bpeng.com email:wsandri@bpeng.com
BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk