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


Java CouchDbInstance.createConnector方法代码示例

本文整理汇总了Java中org.ektorp.CouchDbInstance.createConnector方法的典型用法代码示例。如果您正苦于以下问题:Java CouchDbInstance.createConnector方法的具体用法?Java CouchDbInstance.createConnector怎么用?Java CouchDbInstance.createConnector使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.ektorp.CouchDbInstance的用法示例。


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

示例1: testAttachments

import org.ektorp.CouchDbInstance; //导入方法依赖的package包/类
public void testAttachments() throws IOException {

        HttpClient httpClient = new CBLiteHttpClient(manager);
        CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);

        CouchDbConnector dbConnector = dbInstance.createConnector(DEFAULT_TEST_DB, true);

        TestObject test = new TestObject(1, false, "ektorp");

        //create a document
        dbConnector.create(test);

        //attach file to it
        byte[] attach1 = "This is the body of attach1".getBytes();
        ByteArrayInputStream b = new ByteArrayInputStream(attach1);
        AttachmentInputStream a = new AttachmentInputStream("attach", b, "text/plain");
        dbConnector.createAttachment(test.getId(), test.getRevision(), a);

        AttachmentInputStream readAttachment = dbConnector.getAttachment(test.getId(), "attach");
        Assert.assertEquals("text/plain", readAttachment.getContentType());
        Assert.assertEquals("attach", readAttachment.getId());

        BufferedReader br = new BufferedReader(new InputStreamReader(readAttachment));
        Assert.assertEquals("This is the body of attach1", br.readLine());
    }
 
开发者ID:couchbaselabs,项目名称:couchbase-lite-android-ektorp,代码行数:26,代码来源:Attachments.java

示例2: instance

import org.ektorp.CouchDbInstance; //导入方法依赖的package包/类
public static CouchDbConnector instance() {
  if (db != null) {
    return db;
  }

  synchronized (Database.class) {
    try {
      CouchDbInstance db_lookup = (CouchDbInstance) new InitialContext().lookup(DATABASE_JNDI);
      db = db_lookup.createConnector(DATABASE_NAME, true);
      return db;
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
}
 
开发者ID:IBM-Cloud,项目名称:local-liberty-tutorial,代码行数:16,代码来源:Database.java

示例3: initConnection

import org.ektorp.CouchDbInstance; //导入方法依赖的package包/类
private CouchDbConnector initConnection() throws MalformedURLException, ProxyInitilizedFailedException {
	
   	String username = ConfigManager.get("couchdbUsername");
   	String password = ConfigManager.get("couchdbPassword");
   	String host = ConfigManager.get("couchdbHost");
   	int port = ConfigManager.getInt("couchdbPort");
   	int timeout = ConfigManager.getInt("couchdbTimeout");
   	boolean enableSSL =  ConfigManager.getBoolean("couchdbEnableSSL", false);
   	String dbName = ConfigManager.get("couchdbDBName");
   
	Builder builder = new StdHttpClient.Builder();
	builder = builder
			.host(host)
			.port(port)
			.connectionTimeout(timeout)
			.enableSSL(enableSSL);

	if (username != null && !username.isEmpty() && password != null && !password.isEmpty() ) {
    	builder = builder.username(username).password(password);
	}
	
	CouchDbInstance dbInstance = new StdCouchDbInstance(builder.build());

       if (!dbInstance.checkIfDbExists(dbName))
       	dbInstance.createDatabase(dbName);
       CouchDbConnector couchDB = dbInstance.createConnector(dbName, true);  
	
	return couchDB;
	
}
 
开发者ID:cfibmers,项目名称:open-Autoscaler,代码行数:31,代码来源:CouchdbStoreService.java

示例4: init

import org.ektorp.CouchDbInstance; //导入方法依赖的package包/类
@PostConstruct
private void init() {
    HttpClient httpClient;
    httpClient = new StdHttpClient.Builder()
            .host("127.0.0.1")
            .port(5984)
            .username("admin")
            .password("password")
            .build();
    CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);
    couchDBConnector = dbInstance.createConnector("relax-dms", false);

    restTemplate = new RestTemplate(httpClient);
}
 
开发者ID:martin-kanis,项目名称:relax-dms,代码行数:15,代码来源:DBConnectorFactory.java

示例5: createConnectors

import org.ektorp.CouchDbInstance; //导入方法依赖的package包/类
private List<CouchDbConnector> createConnectors(List<URL> urlsForConnectors, String databaseName){
	List<CouchDbConnector> result = new ArrayList<CouchDbConnector>();
	for(URL url : urlsForConnectors){
		HttpClient httpClient = new StdHttpClient.Builder().url(url).build();
		CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);
		// 2nd paramter true => Create database if not exists
		CouchDbConnector dbConnector = dbInstance.createConnector(databaseName, true);
		result.add(dbConnector);
	}
	return result;
}
 
开发者ID:arnaudsjs,项目名称:YCSB-couchdb-binding,代码行数:12,代码来源:LoadBalancedConnector.java

示例6: testViewQueryFromWeb

import org.ektorp.CouchDbInstance; //导入方法依赖的package包/类
public void testViewQueryFromWeb() throws IOException {

        HttpClient httpClient = new CBLiteHttpClient(manager);
        CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);

        CouchDbConnector couchDbConnector = dbInstance.createConnector(DEFAULT_TEST_DB, true);

        String dDocName = "ddoc";
        String viewName = "people";
        View view = database.getView(String.format("%s/%s", dDocName, viewName));

        view.setMapReduce(new Mapper() {
                              @Override
                              public void map(Map<String, Object> document, Emitter emitter) {
                                  String type = (String) document.get("type");
                                  if ("person".equals(type)) {
                                      emitter.emit(null, document.get("_id"));
                                  }
                              }
                          }, new Reducer() {
                              @Override
                              public Object reduce(List<Object> keys, List<Object> values, boolean rereduce) {
                                  return null;
                              }
                          }, "1"
        );

        ViewQuery viewQuery = new ViewQuery().designDocId("_design/" + dDocName).viewName(viewName);
        //viewQuery.descending(true); //use this to reverse the sorting order of the view
        ViewResult viewResult = couchDbConnector.queryView(viewQuery);

        Assert.assertEquals(0, viewResult.getTotalRows());

    }
 
开发者ID:couchbaselabs,项目名称:couchbase-lite-android-ektorp,代码行数:35,代码来源:Views.java

示例7: testPull

import org.ektorp.CouchDbInstance; //导入方法依赖的package包/类
public void testPull() throws IOException {

        CountDownLatch doneSignal = new CountDownLatch(1);

        HttpClient httpClient = new CBLiteHttpClient(manager);
        CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);

        // create a local database
        CouchDbConnector dbConnector = dbInstance.createConnector(DEFAULT_TEST_DB, true);

        // push this database to the test replication server
        ReplicationCommand pushCommand = new ReplicationCommand.Builder()
            .source(getReplicationURL().toExternalForm())
            .target(DEFAULT_TEST_DB)
            .continuous(false)
            .build();

        ReplicationStatus status = dbInstance.replicate(pushCommand);
        Replication repl = database.getReplicator(status.getSessionId());

        ReplicationChangeListener replicationObserver = new ReplicationChangeListener(doneSignal);
        repl.addChangeListener(replicationObserver);

        try {
            boolean success = doneSignal.await(30, TimeUnit.SECONDS);
            assertTrue(success);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        Assert.assertNotNull(status.getSessionId());

    }
 
开发者ID:couchbaselabs,项目名称:couchbase-lite-android-ektorp,代码行数:33,代码来源:Replicator.java

示例8: getConnector

import org.ektorp.CouchDbInstance; //导入方法依赖的package包/类
public CouchDbConnector getConnector(String name) {
	CouchDbConnector connector = _connectors.get(name);
	if (connector == null) {
		CouchDbInstance instance = getDataContext().getCouchDbInstance();
		connector = instance.createConnector(name, false);
		_connectors.put(name, connector);
	}
	return connector;
}
 
开发者ID:apache,项目名称:metamodel,代码行数:10,代码来源:CouchDbUpdateCallback.java

示例9: RepositoryManager

import org.ektorp.CouchDbInstance; //导入方法依赖的package包/类
public RepositoryManager() {

		try {
    		String url = "";
    		String database = "";
    		String username = "";
    		String password = "";
			Properties prop = new Properties();
	    	try {
	    		prop.load(new FileInputStream("couchdb.properties"));
	    		url = prop.getProperty("url", "https://127.0.0.1:6984/");
	    		database = prop.getProperty("database", "");
	    		username = prop.getProperty("username", "");
	    		password = prop.getProperty("password", "");
	    	} catch (IOException ex) {
	    		ex.printStackTrace();
	        }
			
	    	// Login to CouchDB and connect to the database
			HttpClient authenticatedHttpClient = new StdHttpClient.Builder()
				.url(url)
				.username(username)
				.password(password)
				.relaxedSSLSettings(true) // TODO: add our self-signed certificate to a trust store
				.build();
			CouchDbInstance dbInstance = new StdCouchDbInstance(authenticatedHttpClient);
			CouchDbConnector db = dbInstance.createConnector(database, true);
			
			// Initialise repositories
			this.trackRepository = new TrackRepository(db);

		} catch (IOException e) {
			e.printStackTrace();
		}
	}
 
开发者ID:matthewdooler,项目名称:STAR-Broadcaster,代码行数:36,代码来源:RepositoryManager.java

示例10: getUsersDb

import org.ektorp.CouchDbInstance; //导入方法依赖的package包/类
private static CouchDbConnector getUsersDb() {
	HttpClient client = getClient();
	CouchDbInstance dbInstance = new StdCouchDbInstance(client);
	CouchDbConnector usersDb = dbInstance.createConnector("_users", false);
	return usersDb;
}
 
开发者ID:plexers,项目名称:project-sparrow,代码行数:7,代码来源:DbManager.java

示例11: testViewReduceQuery

import org.ektorp.CouchDbInstance; //导入方法依赖的package包/类
public void testViewReduceQuery() throws IOException {

        HttpClient httpClient = new CBLiteHttpClient(manager);
        CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);

        CouchDbConnector dbConnector = dbInstance.createConnector(DEFAULT_TEST_DB, true);

        putDocs(dbConnector);
        createViewWithReduce(database);


        //because this view has a reduce function it should default to reduce=true
        ViewQuery query = new ViewQuery().designDocId(dDocId).viewName(viewReduceName);
        ViewResult result = dbConnector.queryView(query);

        Assert.assertEquals(1, result.getTotalRows());
        Assert.assertEquals(5, result.getRows().get(0).getValueAsInt());

        //we should still be able to override it and force reduce=false
        query = new ViewQuery().designDocId(dDocId).viewName(viewReduceName).reduce(false);
        result = dbConnector.queryView(query);

        Assert.assertEquals(5, result.getTotalRows());
    }
 
开发者ID:couchbaselabs,项目名称:couchbase-lite-android-ektorp,代码行数:25,代码来源:Views.java

示例12: testWedgedAsyncTasks

import org.ektorp.CouchDbInstance; //导入方法依赖的package包/类
public void testWedgedAsyncTasks() {

        final CountDownLatch doneSignal = new CountDownLatch(1);
        HttpClient httpClient = new CBLiteHttpClient(manager);
        CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);

        // create a local database
        CouchDbConnector couchDbConnector = dbInstance.createConnector(DEFAULT_TEST_DB, true);

        //create an ansyc task to get updates
        ChangesCommand changesCmd = new ChangesCommand.Builder().since(0)
                .includeDocs(false)
                .continuous(true)
                .heartbeat(5000)
                .build();

        ChangesFeedAsyncTask couchChangesAsyncTask = new ChangesFeedAsyncTask(couchDbConnector, changesCmd) {
            @Override
            protected void handleDocumentChange(DocumentChange documentChange) {
                Log.d(TAG, "handleDocumentChange called");
            }
        };
        couchChangesAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void)null);  // fix by using thread pool executor

        EktorpAsyncTask asyncTask = new EktorpAsyncTask() {
            @Override
            protected void doInBackground() {
                Log.d(TAG, "doInBackground() called");
                doneSignal.countDown();
            }
        };
        asyncTask.execute();

        try {
            boolean wasSignalled = doneSignal.await(500, TimeUnit.MILLISECONDS);
            assertTrue("The async task was wedged by the changes feed task", wasSignalled);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
 
开发者ID:couchbaselabs,项目名称:couchbase-lite-android-ektorp,代码行数:42,代码来源:EktorpAsyncTaskTest.java

示例13: testPush

import org.ektorp.CouchDbInstance; //导入方法依赖的package包/类
public void testPush() throws IOException {

        CountDownLatch doneSignal = new CountDownLatch(1);
        HttpClient httpClient = new CBLiteHttpClient(manager);
        CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);

        // create a local database
        CouchDbConnector dbConnector = dbInstance.createConnector(DEFAULT_TEST_DB, true);

        // create 3 objects
        TestObject test1 = new TestObject(1, false, "ektorp-1");
        TestObject test2 = new TestObject(2, false, "ektorp-2");
        TestObject test3 = new TestObject(3, false, "ektorp-3");

        // save these objects in the database
        dbConnector.create(test1);
        dbConnector.create(test2);
        dbConnector.create(test3);

        // push this database to the test replication server
        ReplicationCommand pushCommand = new ReplicationCommand.Builder()
            .source(DEFAULT_TEST_DB)
            .target(getReplicationURL().toExternalForm())
            .continuous(false)
            .createTarget(true)
            .build();

        ReplicationStatus status = dbInstance.replicate(pushCommand);
        Replication repl = database.getReplicator(status.getSessionId());
        ReplicationChangeListener replicationObserver = new ReplicationChangeListener(doneSignal);
        repl.addChangeListener(replicationObserver);

        try {
            boolean success = doneSignal.await(30, TimeUnit.SECONDS);
            assertTrue(success);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        Assert.assertNotNull(status.getSessionId());

    }
 
开发者ID:couchbaselabs,项目名称:couchbase-lite-android-ektorp,代码行数:42,代码来源:Replicator.java

示例14: testFilteredPush

import org.ektorp.CouchDbInstance; //导入方法依赖的package包/类
public void testFilteredPush() throws IOException {

        CountDownLatch doneSignal = new CountDownLatch(1);

        // install the filter
        database.setFilter("evenFoo", new ReplicationFilter() {

            @Override
            public boolean filter(SavedRevision revision, Map<String, Object> params) {
                Integer foo = (Integer) revision.getProperties().get("foo");
                if (foo != null && foo.intValue() % 2 == 0) {
                    return true;
                }
                return false;
            }
        });

        HttpClient httpClient = new CBLiteHttpClient(manager);
        CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);

        // create a local database
        CouchDbConnector dbConnector = dbInstance.createConnector(DEFAULT_TEST_DB, true);

        // create 3 objects
        TestObject test1 = new TestObject(1, false, "ektorp-1");
        TestObject test2 = new TestObject(2, false, "ektorp-2");
        TestObject test3 = new TestObject(3, false, "ektorp-3");

        // save these objects in the database
        dbConnector.create(test1);
        dbConnector.create(test2);
        dbConnector.create(test3);

        // push this database to the test replication server
        ReplicationCommand pushCommand = new ReplicationCommand.Builder()
            .source(DEFAULT_TEST_DB)
            .target(getReplicationURL().toExternalForm())
            .continuous(false)
            .filter("evenFoo")
            .build();

        ReplicationStatus status = dbInstance.replicate(pushCommand);
        Replication repl = database.getReplicator(status.getSessionId());

        ReplicationChangeListener replicationObserver = new ReplicationChangeListener(doneSignal);
        repl.addChangeListener(replicationObserver);

        try {
            boolean success = doneSignal.await(30, TimeUnit.SECONDS);
            assertTrue(success);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        Assert.assertNotNull(status.getSessionId());

    }
 
开发者ID:couchbaselabs,项目名称:couchbase-lite-android-ektorp,代码行数:57,代码来源:Replicator.java

示例15: disabledTestPushToLocal

import org.ektorp.CouchDbInstance; //导入方法依赖的package包/类
public void disabledTestPushToLocal() throws Exception, IOException {

        Database other = manager.getExistingDatabase(DEFAULT_TEST_DB + "2");
        if(other != null) {
            other.delete();
        }

        HttpClient httpClient = new CBLiteHttpClient(manager);
        CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);

        // create a local database
        CouchDbConnector dbConnector = dbInstance.createConnector(DEFAULT_TEST_DB, true);

        // create 3 objects
        TestObject test1 = new TestObject(1, false, "ektorp-1");
        TestObject test2 = new TestObject(2, false, "ektorp-2");
        TestObject test3 = new TestObject(3, false, "ektorp-3");

        // save these objects in the database
        dbConnector.create(test1);
        dbConnector.create(test2);
        dbConnector.create(test3);

        // push this database to the test replication server
        ReplicationCommand pushCommand = new ReplicationCommand.Builder()
            .source(DEFAULT_TEST_DB)
            .target(DEFAULT_TEST_DB + "2")
            .continuous(false)
            .createTarget(true)
            .build();

        ReplicationStatus status = dbInstance.replicate(pushCommand);
        try {
            Thread.sleep(60*1000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Assert.assertNotNull(status.getSessionId());

    }
 
开发者ID:couchbaselabs,项目名称:couchbase-lite-android-ektorp,代码行数:42,代码来源:Replicator.java


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