MCPcopy Create free account
hub / github.com/SWI-Prolog/packages-jpl / close

Method close

src/main/java/org/jpl7/Query.java:616–650  ·  view source on GitHub ↗

This method can be used to close an open query before its solutions are exhausted. It is called automatically when solutions are exhausted. Calling close() on an already closed Query has no effect. Here is one way to get the first three solutions to a Query: Query q = new Query(predicate

()

Source from the content-addressed store, hash-verified

614 * </pre>
615 */
616 public final void close() {
617 if (!open) {
618 return; // it is not an error to attempt to close a closed Query
619 }
620 if (Prolog.thread_self() == -1) {
621 throw new JPLException("no engine is attached to this thread");
622 }
623 if (Prolog.current_engine().value != engine.value) {
624 throw new JPLException("this Query's engine is not that which is attached to this thread");
625 }
626 qid_t topmost = Prolog.current_query();
627 if (topmost.value != this.qid.value) {
628 throw new JPLException("this Query (" + this.hashCode() + ":" + this.toString() + ") is not topmost ("
629 + topmost.hashCode() + ":" + topmost.toString() + ") within its engine[" + engine.value + "]");
630 }
631 Prolog.close_query(qid);
632 qid = null; // for tidiness
633 org.jpl7.fli.Prolog.discard_foreign_frame(fid);
634 fid = null; // for tidiness
635 if (Prolog.current_query() == null) { // only Query open in this engine?
636 if (Prolog.current_engine_is_pool()) { // this (Query's) engine is
637 // from the pool?
638 Prolog.release_pool_engine();
639 // System.out.println("JPL releasing engine[" + engine.value +
640 // "]");
641 } else {
642 // System.out.println("JPL leaving engine[" + engine.value +
643 // "]");
644 }
645 } else {
646 // System.out.println("JPL retaining engine[" + engine.value + "]
647 }
648 open = false; // this Query is now closed
649 engine = null; // this Query, being closed, is no longer associated with any Prolog engine
650 }
651
652 /**
653 * calls the Query's goal to exhaustion and returns an array of zero or more

Callers 4

resetMethod · 0.95
fetchNextSolutionMethod · 0.95
oneSolutionMethod · 0.95
textToTermMethod · 0.95

Calls 9

thread_selfMethod · 0.95
current_engineMethod · 0.95
current_queryMethod · 0.95
toStringMethod · 0.95
close_queryMethod · 0.95
release_pool_engineMethod · 0.95
discard_foreign_frameMethod · 0.80
hashCodeMethod · 0.45

Tested by

no test coverage detected