当前位置: 首页>>代码示例>>Java>>正文


Java MongoURI类代码示例

本文整理汇总了Java中com.mongodb.MongoURI的典型用法代码示例。如果您正苦于以下问题:Java MongoURI类的具体用法?Java MongoURI怎么用?Java MongoURI使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MongoURI类属于com.mongodb包,在下文中一共展示了MongoURI类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getDataStore

import com.mongodb.MongoURI; //导入依赖的package包/类
public Datastore getDataStore() throws UnknownHostException {
    Logger.getLogger( "org.mongodb" ).setLevel(Level.OFF);

    Morphia morphia = getMorphiaInstance();
    MongoURI mongoClientURI = new MongoURI(uri);
    Mongo mongoClient = new Mongo(mongoClientURI);

    Datastore ds = morphia.createDatastore(mongoClient, mongoClientURI.getDatabase());
    ds.ensureIndexes();
    ds.ensureCaps();

    return ds;
}
 
开发者ID:hasanozgan,项目名称:persona-java,代码行数:14,代码来源:MorphiaFactory.java

示例2: makeState

import com.mongodb.MongoURI; //导入依赖的package包/类
@Override
public State makeState(Map conf, int partitionIndex, int numPartitions) {
    MongoURI mongoURI = new MongoURI(mongoUri);
    Mongo mongo;
    try {
        mongo = new Mongo(mongoURI);
    } catch (UnknownHostException e) {
        throw new RuntimeException(e);
    }
    JacksonProcessor processor = new JacksonProcessor() {
        @Override
        public <T> T unmarshall(String json, Class<T> clazz) {
            if (TransactionalValue.class.equals(clazz) || OpaqueValue.class.equals(clazz)) {
                return (T) super.unmarshall(json, entityClass);
            }
            return super.unmarshall(json, clazz);
        }
    };
    Jongo jongo = new Jongo(mongo.getDB(mongoURI.getDatabase()), processor, processor);
    collection = jongo.getCollection(mongoURI.getCollection());

    MapState<T> mapState;
    switch (type) {
        case NON_TRANSACTIONAL:
            mapState = buildNonTransactional();
            break;
        case TRANSACTIONAL:
            collection.getDBCollection().setWriteConcern(WriteConcern.SAFE);
            mapState = buildTransactional();
            break;
        case OPAQUE:
            mapState = buildOpaque();
            break;
        default:
            throw new RuntimeException("Unknown state type: " + type);
    }

    return new SnapshottableMap<T>(mapState, Arrays.<Object>asList(opts.globalKey));
}
 
开发者ID:duolaieimeng,项目名称:trident-mongodb,代码行数:40,代码来源:MongoState.java

示例3: addJob

import com.mongodb.MongoURI; //导入依赖的package包/类
public void addJob(String mongoURI) {
  @SuppressWarnings("deprecation")
  MongoURI uri = new MongoURI(mongoURI);

  String database = uri.getDatabase(), collection = uri.getCollection();
  String tableName = getTranslator().mapNamespaceToHBaseTable(database, collection);

  if (tableName == null) {
    log.info("Skipping namespace '" + database + "." + collection + "' because it doesn't map to an HBase table");
    return;
  }

  addJob(uri, tableName);
}
 
开发者ID:colinmarc,项目名称:zerowing,代码行数:15,代码来源:BulkImportRunner.java

示例4: calculateRegionSplits

import com.mongodb.MongoURI; //导入依赖的package包/类
private byte[][] calculateRegionSplits(MongoURI uri, String tableName) throws Exception {
  DBCollection collection = uri.connectDB().getCollection(uri.getCollection());
  long size = collection.getStats().getLong("size");
  long regionSize = ConfigUtil.getPresplitTableRegionSize(_conf);
  int numRegions = (int) Math.min((size / regionSize) + 1, 4096);

  if (numRegions > 1) {
    log.info("Pre-splitting " + tableName + " into " + numRegions + " regions");
    RegionSplitter.UniformSplit splitter = new RegionSplitter.UniformSplit();
    return splitter.split(numRegions);
  } else {
    log.info("Not splitting " + tableName + ", because the data can fit into a single region");
    return new byte[0][0];
  }
}
 
开发者ID:colinmarc,项目名称:zerowing,代码行数:16,代码来源:BulkImportRunner.java

示例5: BulkImportJob

import com.mongodb.MongoURI; //导入依赖的package包/类
public BulkImportJob(Configuration conf, MongoURI mongoURI, String tableName) throws IOException {
  Configuration cloned = new Configuration(conf);
  _uuid = UUID.randomUUID().toString();
  _job = new Job(cloned, tableName + "." + _uuid);

  _mongoURI = mongoURI;
  _tableName = tableName;

  String tmpPath = ConfigUtil.getTemporaryHFilePath(conf);
  _hfilePath = new Path(tmpPath, _uuid);

  setupJob();
}
 
开发者ID:colinmarc,项目名称:zerowing,代码行数:14,代码来源:BulkImportJob.java

示例6: setupMongo

import com.mongodb.MongoURI; //导入依赖的package包/类
Mongo setupMongo() {
  return uri() == null ? new Mongo() : new Mongo(new MongoURI(uri()));
}
 
开发者ID:apache,项目名称:beam,代码行数:4,代码来源:MongoDbGridFSIO.java

示例7: setup

import com.mongodb.MongoURI; //导入依赖的package包/类
/**
 * Create an instance of <code>Mongo</code> based on the information
 * provided in the configuration files located into <code>WEB-INF/conf</code>, if the instance has already been
 * created using the same information, so it uses the same instance.
 *
 * @param context <code>ServletContext</code> of a web application.
 * @return an instance of a <code>CollectionManager</code>.
 */
public static CollectionManager setup(ServletContext context) {
    try {
        File props = getPropertiesFile(context);
        if (props == null) {
            throw new FileNotFoundException("application or database configuration file not found.");
        }
        InputStream in = new FileInputStream(props);
        Properties properties = new Properties();
        properties.load(in);
        StringBuilder builder = new StringBuilder();
        builder.append(MongoURI.MONGODB_PREFIX);
        String user, password, host, port, dbName;
        user = properties.containsKey("mongocom.user") ? properties.getProperty("mongocom.user") : "";
        password = properties.containsKey("mongocom.password") ? properties.getProperty("mongocom.password") : "";
        host = properties.containsKey("mongocom.host") ? properties.getProperty("mongocom.host") : "";
        port = properties.containsKey("mongocom.port") ? properties.getProperty("mongocom.port") : "";
        dbName = properties.containsKey("mongocom.database") ? properties.getProperty("mongocom.database") : "";
        if (!user.equals("")) {
            builder.append(user).append(":").append(password).append("@");
        }
        if (host.equals("")) {
            builder.append("localhost");
        } else {
            builder.append(host);
        }
        if (!port.equals("")) {
            builder.append(":");
            builder.append(port);
        }
        builder.append("/");
        if (!dbName.equals("")) {
            builder.append(dbName);
        }
        LOG.log(Level.INFO, "Mongo URI: {0}", builder.toString());
        MongoURI uri = new MongoURI(builder.toString());
        client = MongoClient.Holder.singleton().connect(uri);
        return new CollectionManager(client, dbName);
    } catch (IOException ex) {
        LOG.log(Level.SEVERE, null, ex);
    }
    return null;
}
 
开发者ID:thiguetta,项目名称:MongOCOM,代码行数:51,代码来源:CollectionManagerFactory.java

示例8: mongoURI

import com.mongodb.MongoURI; //导入依赖的package包/类
@Bean
public MongoURI mongoURI() throws Exception {
	return new MongoURI(env.getProperty("dbUrl"));
}
 
开发者ID:thiagoandrade6,项目名称:pubanywhere,代码行数:5,代码来源:MongoConfig.java

示例9: ZettlMongoDbFactory

import com.mongodb.MongoURI; //导入依赖的package包/类
public ZettlMongoDbFactory(MongoURI uri) throws UnknownHostException {
	mongoDbFactory = new SimpleMongoDbFactory(uri);
	mongoDbFactory.setWriteConcern(WriteConcern.ACKNOWLEDGED);
}
 
开发者ID:ueberadmin,项目名称:flypost,代码行数:5,代码来源:ZettlMongoDbFactory.java

示例10: addJobsForNamespace

import com.mongodb.MongoURI; //导入依赖的package包/类
public void addJobsForNamespace(String rawURI, String database, String collection) {
  Mongo mongo;

  @SuppressWarnings("deprecation")
  MongoURI uri = new MongoURI(rawURI);

  try {
    mongo = uri.connect();
  } catch (UnknownHostException e) {
    throw new IllegalArgumentException("Failed to connect to MongoDB using URI: " + uri, e);
  }

  if (database != null && collection != null) {
    if(!mongo.getDB(database).collectionExists(collection)) {
      throw new IllegalArgumentException("Couldn't find namespace: " + database + "." + collection);
    }

    buildJob(uri, database, collection);
    return;
  } else if (database == null && collection != null) {
    throw new IllegalArgumentException("You can't specify a MongoDB collection without also specifying a database");
  }

  List<String> databases;
  if (database != null) {
    databases = new ArrayList<String>(1);
    databases.add(database);
  } else {
    databases = mongo.getDatabaseNames();
  }

  for (String db : databases) {
    if (db.equals("local") || db.equals("admin")) continue;

    Set<String> collections = mongo.getDB(db).getCollectionNames();
    for (String coll : collections) {
      if (coll.startsWith("system.")) continue;
      buildJob(uri, db, coll);
    }
  }
}
 
开发者ID:colinmarc,项目名称:zerowing,代码行数:42,代码来源:BulkImportRunner.java

示例11: buildJob

import com.mongodb.MongoURI; //导入依赖的package包/类
private void buildJob(MongoURI uri, String database, String collection) {
  UriBuilder builder = UriBuilder.fromUri(uri.toString());
  String builtURI = builder.path("{db}.{coll}").build(database, collection).toString();

  addJob(builtURI);
}
 
开发者ID:colinmarc,项目名称:zerowing,代码行数:7,代码来源:BulkImportRunner.java

示例12: getMongoURI

import com.mongodb.MongoURI; //导入依赖的package包/类
public MongoURI getMongoURI() {
  return _mongoURI;
}
 
开发者ID:colinmarc,项目名称:zerowing,代码行数:4,代码来源:BulkImportJob.java


注:本文中的com.mongodb.MongoURI类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。