Package org.xmldb.api.base

Examples of org.xmldb.api.base.Collection


        assertNotNull("MetaService is not found!", service);
    }

    public void testGetCollectionMetaData() throws Exception {
        // Get meta service
        Collection col = this.client.getCollection(TEST_COLLECTION_PATH);
        MetaService service = (MetaService) col.getService("MetaService", "1.0");

        // Get meta data
        MetaData data = service.getMetaData();
        assertNotNull("MetaData is not found for the collection!", data);
        assertTrue("Creation time is 0!", data.getCreatedTime() != 0);
View Full Code Here


        assertTrue("Modification time has not changed on update!", modified1 != modified2);
    }

    public void testGetDocumentMetaData() throws Exception {
        // Get meta service
        Collection col = this.client.getCollection(TEST_COLLECTION_PATH);
        MetaService service = (MetaService) col.getService("MetaService", "1.0");

        // Get meta data
        MetaData data = service.getMetaData(DOCUMENT_ID1);
        assertNotNull("MetaData is not found for document " + DOCUMENT_ID1 + "!", data);
        assertTrue("Creation time is 0!", data.getCreatedTime() != 0);
View Full Code Here

        assertTrue("Modification time has not changed on update!", modified1 != modified2);
    }

    public void testSetCollectionMetaData() throws Exception {
        // Get meta service
        Collection col = this.client.getCollection(TEST_COLLECTION_PATH);
        MetaService service = (MetaService) col.getService("MetaService", "1.0");

        // Get meta data
        MetaData data = service.getMetaData();
        long created0 = data.getCreatedTime();
        long modified0 = data.getLastModifiedTime();
View Full Code Here

        assertEquals("Modification time changed on set (diff: "+ (modified1 - modified0) +")!", modified0, modified1);
    }

    public void testSetDocumentMetaData() throws Exception {
        // Get meta service
        Collection col = this.client.getCollection(TEST_COLLECTION_PATH);
        MetaService service = (MetaService) col.getService("MetaService", "1.0");

        // Get meta data
        MetaData data = service.getMetaData(DOCUMENT_ID1);
        long created0 = data.getCreatedTime();
        long modified0 = data.getLastModifiedTime();
View Full Code Here

        assertEquals("Modification time changed on set (diff: "+ (modified1 - modified0) +")!", modified0, modified1);
    }

    public void testSetCollectionMetaDataProperty() throws Exception {
        // Get meta service
        Collection col = this.client.getCollection(TEST_COLLECTION_PATH);
        MetaService service = (MetaService) col.getService("MetaService", "1.0");

        // Get meta data
        String value0 = "MetaAttributeValue" + System.currentTimeMillis();
        MetaData data = service.getMetaData();
        data.setAttribute(ATTRIBUTE_ID, value0);
View Full Code Here

        assertEquals("Attribute value does not match!", value0, value1);
    }

    public void testSetDocumentMetaDataProperty() throws Exception {
        // Get meta service
        Collection col = this.client.getCollection(TEST_COLLECTION_PATH);
        MetaService service = (MetaService) col.getService("MetaService", "1.0");

        // Get meta data
        String value0 = "MetaAttributeValue" + System.currentTimeMillis();
        MetaData data = service.getMetaData(DOCUMENT_ID1);
        data.setAttribute(ATTRIBUTE_ID, value0);
View Full Code Here

* Simple XML:DB API example to update the database.
*/
public class XUpdate  extends AbstractExample {
 
  public static void main(String[] args) throws Exception {
    Collection collection = null;
    try {

      collection = getCollection("xmldb:xindice:///db/addressbook");

      String xupdate =
        "<xu:modifications version=\"1.0\""
          + "      xmlns:xu=\"http://www.xmldb.org/xupdate\">"
          + "   <xu:remove select=\"/person/phone[@type = 'home']\"/>"
          + "   <xu:update select=\"/person/phone[@type = 'work']\">"
          + "       480-300-3003"
          + "   </xu:update>"
          + "</xu:modifications>";

      XUpdateQueryService service = (XUpdateQueryService) collection.getService("XUpdateQueryService", "1.0");
      long count = service.update(xupdate);
      System.out.println(count + " entries updated.");
    }
    catch (XMLDBException e) {
      System.err.println("XML:DB Exception occured " + e.errorCode + " " + e.getMessage());
    }
    finally {
      if (collection != null) {
        collection.close();
      }
    }
  }
View Full Code Here

public class CreateCollection  extends AbstractExample {

  private static final String COLLECTION_NAME = "mycollection";

  public static void main(String[] args) throws Exception {
    Collection collection = null;
    try {

//      collection = getCollection("xmldb:xindice:///db/");
      collection = getCollection("xmldb:xindice://localhost:8888/db/");
//      collection = getCollection("xmldb:xindice-embed:///db/");

      CollectionManager service = (CollectionManager) collection.getService("CollectionManager", "1.0");

      try{
        service.dropCollection(COLLECTION_NAME);
        System.out.println("Dropped existing collection with name: " + COLLECTION_NAME);
      }
      catch (Exception e) {
                ; // nothing, this may be the first pass.
            }

      // Build up the Collection XML configuration.
      String collectionConfig =
        "<collection compressed=\"true\" name=\""
          + COLLECTION_NAME
          + "\">"
          + "   <filer class=\"org.apache.xindice.core.filer.BTreeFiler\" gzip=\"true\"/>"
          + "</collection>";

      service.createCollection(COLLECTION_NAME, DOMParser.toDocument(collectionConfig));

      System.out.println("Collection " + COLLECTION_NAME + " created.");
    }
    catch (XMLDBException e) {
      System.err.println("XML:DB Exception occured " + e.errorCode + " " + e.getMessage());
    }
    finally {
      if (collection != null) {
        collection.close();
      }
    }
  }
View Full Code Here

        this.client.createCollection(XmlDbClientSetup.INSTANCE_NAME + "/" + XmlDbClientSetup.TEST_COLLECTION_NAME,
                                     name, DOMParser.toDocument(cfg));
    }

  public void testRoundTrip() throws Exception {
    Collection collection = client.getCollection(TEST_COLLECTION_PATH);
    if (collection == null) {
      throw new Exception("getCollection(" + TEST_COLLECTION_PATH + ") returned null");
    }

    /*
     * Create a binary resource, save it in the 'current' collection,
     * then retrieve it and verify that the data comes back right.
     */

        Resource newResource = collection.createResource(null, "BinaryResource");
        newResource.setContent(new byte[] { 0x00, 0x10, 0x01, 0x11 });
    collection.storeResource(newResource);
    String id = newResource.getId();

    Resource foundResource = collection.getResource(id);

    assertNotNull("We know you're in there...", foundResource);
    assertEquals("The resource type is supposed be 'BinaryResource'", "BinaryResource", foundResource.getResourceType());
    assertTrue("The resource is an instance of BinaryResource", foundResource instanceof BinaryResource);

View Full Code Here

      assertEquals("The resources differ in byte " + i, newBytes[i], foundBytes[i]);
    }
  }

    public void testList() throws Exception {
        Collection collection = client.getCollection(TEST_COLLECTION_PATH);
        if (collection == null) {
            throw new Exception("getCollection(" + TEST_COLLECTION_PATH + ") returned null");
        }

        //
        // Create a binary resource, save it in the 'current' collection,
        // then list resources.
        //

        Resource newResource = collection.createResource(null, "BinaryResource");
        newResource.setContent(new byte[] { 0x00, 0x10, 0x01, 0x11 });
        collection.storeResource(newResource);
        String id = newResource.getId();

        String[] resources = collection.listResources();
        assertNotNull("Can not be null", resources);
        assertEquals("Should have one resource", 1, resources.length);
        assertEquals("Resource ID should match", id, resources[0]);

        collection.removeResource(newResource);
    }
View Full Code Here

TOP

Related Classes of org.xmldb.api.base.Collection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.