cascading.mongodb.MongoDBConfiguration.java Source code

Java tutorial

Introduction

Here is the source code for cascading.mongodb.MongoDBConfiguration.java

Source

/*
 * Copyright (c) 2010 GameAttain, Inc.
 *
 *  This work has been released into the public domain
 *  by the copyright holder. This applies worldwide.
 *
 *
 *  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.
 */

package cascading.mongodb;

import org.apache.hadoop.mapred.JobConf;

/**
 * Date: May 24, 2010
 * Time: 9:56:27 PM
 */
public class MongoDBConfiguration {
    private JobConf jobConf;

    /**
     * MongoDB Access URL *
     */
    public static final String DATABASE = "mapred.mongodb.database";

    public static final String COLLECTION = "mapred.mongodb.collection.name";

    public static final String OUTPUT_DOCUMENT_ATTRIBUTE_NAMES = "mapred.mongodb.output.document.attribute.names";

    public static void configureMongoDB(JobConf jobConf, String database, String collection) {

        if (database != null && !"".equals(database))
            jobConf.set(DATABASE, database);

        if (collection != null && !"".equals(collection))
            jobConf.set(COLLECTION, collection);
    }

    MongoDBConfiguration(JobConf jobConf) {
        this.jobConf = jobConf;
    }

    String getCollection() {
        return jobConf.get(COLLECTION);
    }

    void setCollection(String collection) {
        jobConf.set(COLLECTION, collection);
    }

    String getDatabase() {
        return jobConf.get(DATABASE);
    }

    void setDatabase(String database) {
        jobConf.set(DATABASE, database);
    }

    String[] getDocumentAttributeNames() {
        return jobConf.getStrings(OUTPUT_DOCUMENT_ATTRIBUTE_NAMES);
    }

    void setDocumentAttributeNames(String... attributeNames) {
        jobConf.setStrings(OUTPUT_DOCUMENT_ATTRIBUTE_NAMES, attributeNames);
    }

}