1 /* 2 * #%L 3 * MongoFactory.java - mongodb-async-driver - Allanbank Consulting, Inc. 4 * %% 5 * Copyright (C) 2011 - 2014 Allanbank Consulting, Inc. 6 * %% 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 * #L% 19 */ 20 package com.allanbank.mongodb; 21 22 import com.allanbank.mongodb.client.MongoClientImpl; 23 24 /** 25 * MongoFactory provides the bootstrap point for creating a connection 26 * represented via a {@link Mongo} instance) to a MongoDB cluster. Both explicit 27 * construction with a pre-instantiated {@link MongoClientConfiguration} and via 28 * a MongoDB URI are supported. 29 * 30 * @api.yes This class is part of the driver's API. Public and protected members 31 * will be deprecated for at least 1 non-bugfix release (version 32 * numbers are <major>.<minor>.<bugfix>) before being 33 * removed or modified. 34 * @copyright 2012-2013, Allanbank Consulting, Inc., All Rights Reserved 35 */ 36 public class MongoFactory { 37 38 /** 39 * Creates a new {@link Mongo} instance using the 40 * {@link MongoClientConfiguration}. 41 * 42 * @param config 43 * The configuration for the connection to MongoDB. 44 * @return The {@link Mongo} representation of the connections to MongoDB. 45 * @deprecated Use the {@link #createClient(MongoClientConfiguration)} 46 * instead. This method will be removed on or after the 1.3.0 47 * release. 48 */ 49 @Deprecated 50 public static Mongo create(final MongoDbConfiguration config) { 51 return new com.allanbank.mongodb.client.MongoImpl(config); 52 } 53 54 /** 55 * Creates a new {@link Mongo} instance using a MongoDB style URL. 56 * 57 * @param mongoDbUri 58 * The configuration for the connection to MongoDB expressed as a 59 * MongoDB URL. 60 * @return The {@link Mongo} representation of the connections to MongoDB. 61 * 62 * @see <a href="http://www.mongodb.org/display/DOCS/Connections"> MongoDB 63 * Connections</a> 64 * @deprecated Use the {@link #createClient(MongoDbUri)} instead. This 65 * method will be removed on or after the 1.3.0 release. 66 */ 67 @Deprecated 68 public static Mongo create(final MongoDbUri mongoDbUri) { 69 return create(new MongoDbConfiguration(mongoDbUri)); 70 } 71 72 /** 73 * Creates a new {@link Mongo} instance using a MongoDB style URL. 74 * 75 * @param mongoDbUri 76 * The configuration for the connection to MongoDB expressed as a 77 * MongoDB URL. 78 * @return The {@link Mongo} representation of the connections to MongoDB. 79 * 80 * @see <a href="http://www.mongodb.org/display/DOCS/Connections"> MongoDB 81 * Connections</a> 82 * @deprecated Use the {@link #createClient(String)} instead. This method 83 * will be removed on or after the 1.3.0 release. 84 */ 85 @Deprecated 86 public static Mongo create(final String mongoDbUri) { 87 return create(new MongoDbUri(mongoDbUri)); 88 } 89 90 /** 91 * Creates a new {@link Mongo} instance using the 92 * {@link MongoClientConfiguration}. 93 * 94 * @param config 95 * The configuration for the connection to MongoDB. 96 * @return The {@link Mongo} representation of the connections to MongoDB. 97 */ 98 public static MongoClient createClient(final MongoClientConfiguration config) { 99 return new MongoClientImpl(config); 100 } 101 102 /** 103 * Creates a new {@link Mongo} instance using a MongoDB style URL. 104 * 105 * @param mongoDbUri 106 * The configuration for the connection to MongoDB expressed as a 107 * MongoDB URL. 108 * @return The {@link Mongo} representation of the connections to MongoDB. 109 * 110 * @see <a href="http://www.mongodb.org/display/DOCS/Connections"> MongoDB 111 * Connections</a> 112 */ 113 public static MongoClient createClient(final MongoDbUri mongoDbUri) { 114 return createClient(new MongoClientConfiguration(mongoDbUri)); 115 } 116 117 /** 118 * Creates a new {@link Mongo} instance using a MongoDB style URL. 119 * 120 * @param mongoDbUri 121 * The configuration for the connection to MongoDB expressed as a 122 * MongoDB URL. 123 * @return The {@link Mongo} representation of the connections to MongoDB. 124 * 125 * @see <a href="http://www.mongodb.org/display/DOCS/Connections"> MongoDB 126 * Connections</a> 127 */ 128 public static MongoClient createClient(final String mongoDbUri) { 129 return createClient(new MongoDbUri(mongoDbUri)); 130 } 131 132 /** 133 * Stop creation of a new MongoFactory. 134 */ 135 private MongoFactory() { 136 super(); 137 } 138 }