Package org.apache.xindice.examples

Source Code of org.apache.xindice.examples.CreateCollection

package org.apache.xindice.examples;

/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements.  See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $Id: CreateCollection.java 511428 2007-02-25 03:30:52Z vgritsenko $
*/

import org.apache.xindice.client.xmldb.services.CollectionManager;
import org.apache.xindice.xml.dom.DOMParser;
import org.xmldb.api.base.Collection;
import org.xmldb.api.base.XMLDBException;

/**
* Simple XML:DB API example to create a collection.
*/
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\"/>"
                    + "</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();
            }
        }
    }
}
TOP

Related Classes of org.apache.xindice.examples.CreateCollection

TOP
Copyright © 2018 www.massapi.com. 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.