[ 
https://issues.apache.org/jira/browse/JENA-1146?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15175396#comment-15175396
 ] 

Joël Kuiper edited comment on JENA-1146 at 3/2/16 10:28 AM:
------------------------------------------------------------

Yep this makes sense to me! For completeness sake the (Clojure code) we use 
right now. But it's pretty much identical. 

{code:none}
(defn build-text-index!
  "Builds text index from dataset in TDB identified by assembler-file.
  Returns nil. Accesses internals of textindexer class.
  
https://github.com/apache/jena/blob/master/jena-text/src/main/java/jena/textindexer.java";
  [assembler-file]
  (info "Building text index on TDB")
  (let [params [(Class/forName "[Ljava.lang.String;")]
        args (into-array String [(str "--desc=" assembler-file)])
        instance (du/call-constructor jena.textindexer params args)]
    (.mainRun instance)
    (.close (du/get-field jena.textindexer "textIndex" instance))
    (.close (du/get-field jena.textindexer "dataset" instance))
    nil))

(defn call-constructor
  "Calls a private or public sonstructor of klass that has
  given params (a collection of classes), passing args as argument
  list into constructor."
  [klass params & args]
  (-> klass (.getDeclaredConstructor (into-array Class params))
      (doto (.setAccessible true))
      (.newInstance (into-array Object args))))

(defn get-field
  "Returns obj's private or public field with given field-name,
  defined in klass. Pass nil into obj for static fields."
  [klass field-name obj]
  (-> klass (.getDeclaredField (name field-name))
      (doto (.setAccessible true))
      (.get obj)))
{code}


was (Author: joelkuiper):
Yep this makes sense to me! For completeness sake the (Clojure code) we use 
right now. But it's pretty much identical. 

{code:clojure}
(defn build-text-index!
  "Builds text index from dataset in TDB identified by assembler-file.
  Returns nil. Accesses internals of textindexer class.
  
https://github.com/apache/jena/blob/master/jena-text/src/main/java/jena/textindexer.java";
  [assembler-file]
  (info "Building text index on TDB")
  (let [params [(Class/forName "[Ljava.lang.String;")]
        args (into-array String [(str "--desc=" assembler-file)])
        instance (du/call-constructor jena.textindexer params args)]
    (.mainRun instance)
    (.close (du/get-field jena.textindexer "textIndex" instance))
    (.close (du/get-field jena.textindexer "dataset" instance))
    nil))

(defn call-constructor
  "Calls a private or public sonstructor of klass that has
  given params (a collection of classes), passing args as argument
  list into constructor."
  [klass params & args]
  (-> klass (.getDeclaredConstructor (into-array Class params))
      (doto (.setAccessible true))
      (.newInstance (into-array Object args))))

(defn get-field
  "Returns obj's private or public field with given field-name,
  defined in klass. Pass nil into obj for static fields."
  [klass field-name obj]
  (-> klass (.getDeclaredField (name field-name))
      (doto (.setAccessible true))
      (.get obj)))
{code}

> jena.textindexer does not close resources 
> ------------------------------------------
>
>                 Key: JENA-1146
>                 URL: https://issues.apache.org/jira/browse/JENA-1146
>             Project: Apache Jena
>          Issue Type: Bug
>          Components: Cmd line tools, Jena, Text
>    Affects Versions: Jena 3.0.1
>            Reporter: Joël Kuiper
>            Assignee: Osma Suominen
>            Priority: Minor
>             Fix For: Jena 3.1.0
>
>
> This is a bit of a minor issue since the jena.textindexer is meant to be ran 
> from the command line. But in our app we call it directly from the JVM 
> process and then proceed to do some other operations. This fails when also 
> using the text index, since Lucene can't acquire a lock in that case (it's 
> limited to one connection). As a work-around we now set the textIndex and 
> dataset fields to public using reflection, and manually close the resources. 
> But ideally this should happen after the main command body. 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to