GitHub user CesarPantoja opened a pull request:

    https://github.com/apache/jena/pull/133

    Support for try-with-resources Statements in ClosableIterator and Models

    Implementation of the interface AutoCloseable in ClosableIterator and 
Model. This would allow to use Java's [try-with 
resources](https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html)
 Statements, i.e.:
    
    `        // some definitions
            String personURI = "http://somewhere/JohnSmith";;
            String fullName = "John Smith";
    
            // create an empty Model
            try (Model model = ModelFactory.createDefaultModel()) {
    
                // create the resource
                Resource johnSmith = model.createResource(personURI);
    
                // add the property
                johnSmith.addProperty(VCARD.FN, fullName);
            }`
    
    or
    
    `            // list the statements in the Model
                try (StmtIterator iter = model.listStatements()) {
    
                    // print out the predicate, subject and object of each 
statement
                    while (iter.hasNext()) {
                        Statement stmt = iter.nextStatement();  // get next 
statement
                        Resource subject = stmt.getSubject();     // get the 
subject
                        Property predicate = stmt.getPredicate();   // get the 
predicate
                        RDFNode object = stmt.getObject();      // get the 
object
    
                        System.out.print(subject.toString());
                        System.out.print(" " + predicate.toString() + " ");
                        if (object instanceof Resource) {
                            System.out.print(object.toString());
                        } else {
                            // object is a literal
                            System.out.print(" \"" + object.toString() + "\"");
                        }
    
                        System.out.println(" .");
                    }
                }`

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/CesarPantoja/jena master

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/jena/pull/133.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #133
    
----
commit 5d2b4edbe74547355f9f5e681e0997d258bfb4ba
Author: Cesar Pantoja <[email protected]>
Date:   2016-03-19T12:49:39Z

    Added Autocloseable iterators

commit ecdc168252bacd4b1af41e2c5aa821a5157efebb
Author: Cesar Pantoja <[email protected]>
Date:   2016-03-19T13:10:07Z

    Merge remote-tracking branch 'upstream/master'

commit d6d11250bf162f3d9517ff493e59af7b6b22f91c
Author: Cesar Pantoja <[email protected]>
Date:   2016-04-02T13:00:24Z

    Merge pull request #1 from apache/master
    
    update from master

commit ad6c1a36e7cb0683131da44c962bcdfe9bb7413c
Author: Cesar Pantoja <[email protected]>
Date:   2016-04-02T13:06:34Z

    Support for try-with-resources in Models

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to