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


Java CouchDbConnector类代码示例

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


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

示例1: beforeClass

import org.ektorp.CouchDbConnector; //导入依赖的package包/类
@BeforeClass
public static void beforeClass() throws MalformedURLException {
    HttpClient httpClient = new StdHttpClient.Builder()
            .url("http://192.168.99.100:5984/")
            .username("mapUser")
            .password("myCouchDBSecret")
            .build();

    dbi = new StdCouchDbInstance(httpClient);
    CouchDbConnector dbc = dbi.createConnector(CouchInjector.DB_NAME, false);

    repo = new MapRepository();
    repo.db = dbc;
    repo.postConstruct();
    debugWriter = repo.sites.mapper.writerWithDefaultPrettyPrinter();
}
 
开发者ID:gameontext,项目名称:gameon-map,代码行数:17,代码来源:TestLiveMapPlacement.java

示例2: getComments

import org.ektorp.CouchDbConnector; //导入依赖的package包/类
private JSONArray getComments(String itemNumber) {
	JSONArray returnArray = new JSONArray();
	CouchDbConnector dbc = _db.createConnector(dbname, true);

	Map<String, String> doc = new HashMap<String, String>();

	ViewQuery query = new ViewQuery().allDocs().includeDocs(true);
	List<Map> result = dbc.queryView(query, Map.class);
	JSONArray jsonresult = new JSONArray();
	for (Map element : result) {
		JSONObject obj = new JSONObject();
		obj.putAll(element);
		if(itemNumber==null || obj.get("itemNumber").equals(itemNumber))
			jsonresult.add(obj);
	}

	System.out.println(jsonresult.toString());

	return jsonresult;

}
 
开发者ID:IBM-Cloud,项目名称:BluemixBoutique,代码行数:22,代码来源:CommentsServlet.java

示例3: initConnection

import org.ektorp.CouchDbConnector; //导入依赖的package包/类
private CouchDbConnector initConnection(String dbName, String userName, String password, String host, int port, boolean enableSSL, int timeout)
  {
Builder builder = new StdHttpClient.Builder()
.host(host)
.port(port)
.connectionTimeout(timeout)
.socketTimeout(timeout)
.enableSSL(enableSSL); 

      
      if(userName != null && !userName.isEmpty() && password != null && !password.isEmpty())
          builder.username(userName).password(password);
      
      dbInstance = new StdCouchDbInstance(builder.build());
      if (!dbInstance.checkIfDbExists(dbName))
      	dbInstance.createDatabase(dbName);
      CouchDbConnector couchDB = dbInstance.createConnector(dbName, true);   
      return couchDB;


  }
 
开发者ID:cfibmers,项目名称:open-Autoscaler,代码行数:22,代码来源:CouchDbConnectionManager.java

示例4: insert

import org.ektorp.CouchDbConnector; //导入依赖的package包/类
@Override
public void insert(String dbName, String jsonContent)
{
	try
	{
		CouchDbConnector connector = createConnector(dbName, true);
		ObjectMapper mapper = new ObjectMapper();

		JsonNode jsonItems = mapper.readTree(jsonContent);
		List<JsonNode> itemList = new ArrayList<JsonNode>();

		if (jsonItems.isArray())
			for (JsonNode item : jsonItems)
			{
			  normalizeId(item);
				itemList.add(item);
			}

		connector.executeBulk(itemList);
	} catch(Exception e)
	{
		e.printStackTrace();
	}
}
 
开发者ID:catedrasaes-umu,项目名称:NoSQLDataEngineering,代码行数:25,代码来源:CouchDbClient.java

示例5: createDesign

import org.ektorp.CouchDbConnector; //导入依赖的package包/类
public static void createDesign(CouchDbConnector db) {
	if (!db.contains("_design/views")) {
		DesignDocument dd = new DesignDocument("_design/views");
		
		String mapFullPicturesByCreationDate = "function(doc) {\n  if (doc.type == \"FullPicture\") {\n           emit(doc.creationDate, doc);\n       }\n}";
		String mapPortraitsByCreationDate = "function(doc) {\n  if (doc.type == \"Portrait\") {\n           emit(doc.creationDate, doc);\n       }\n}";
			
		DesignDocument.View view = new DesignDocument.View(mapFullPicturesByCreationDate);
		dd.addView("fullPicturesByCreationDate", view);
	
		view = new DesignDocument.View(mapPortraitsByCreationDate);
		dd.addView("portraitsByCreationDate", view);
		
		db.create(dd);
	}
}
 
开发者ID:IBM-Cloud,项目名称:drone-selfie,代码行数:17,代码来源:DatabaseDesign.java

示例6: testGetStatements

import org.ektorp.CouchDbConnector; //导入依赖的package包/类
@Test
public void testGetStatements() {
	StatementResultQuery mockedQuery = mock(StatementResultQuery.class);

	IQueryResolver mockedResolver = mock(IQueryResolver.class);
	StatementFilter filter = new StatementFilter();
	CouchDbConnector mockedConnector = mock(CouchDbConnector.class);

	when(mockedResolver.resolve(filter)).thenReturn(mockedQuery);

	StatementResult expectedResult = new StatementResult(
			new ArrayList<Statement>(), new Date());

	when(
			mockedQuery.getQueryResult(
					Matchers.any(CouchDbConnector.class), eq(filter),
					Matchers.any(QueryStrategy.class))).thenReturn(
			expectedResult);

	StatementRepository repository = new CouchDbStatementRepository(
			mockedConnector, mockedResolver);

	assertEquals(expectedResult, repository.getStatements(filter));

}
 
开发者ID:Apereo-Learning-Analytics-Initiative,项目名称:Larissa,代码行数:26,代码来源:TestStatementRepository.java

示例7: testAttachments

import org.ektorp.CouchDbConnector; //导入依赖的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

示例8: execute

import org.ektorp.CouchDbConnector; //导入依赖的package包/类
@Override
public void execute() throws MetaModelException {
    Table table = getTable();
    String name = table.getName();

    Object[] values = getValues();
    Column[] columns = getColumns();
    Map<String, Object> map = new HashMap<String, Object>();
    for (int i = 0; i < columns.length; i++) {
        Column column = columns[i];
        if (isSet(column)) {
            map.put(column.getName(), values[i]);
        }
    }

    CouchDbConnector connector = getUpdateCallback().getConnector(name);
    connector.addToBulkBuffer(map);
}
 
开发者ID:apache,项目名称:metamodel,代码行数:19,代码来源:CouchDbInsertionBuilder.java

示例9: materializeMainSchemaTable

import org.ektorp.CouchDbConnector; //导入依赖的package包/类
@Override
protected DataSet materializeMainSchemaTable(Table table, List<Column> columns, int firstRow, int maxRows) {
    // the connector represents a handle to the the couchdb "database".
    final String databaseName = table.getName();
    final CouchDbConnector connector = _couchDbInstance.createConnector(databaseName, false);

    ViewQuery query = new ViewQuery().allDocs().includeDocs(true);

    if (maxRows > 0) {
        query = query.limit(maxRows);
    }
    if (firstRow > 1) {
        final int skip = firstRow - 1;
        query = query.skip(skip);
    }

    final StreamingViewResult streamingView = connector.queryForStreamingView(query);

    final List<SelectItem> selectItems = columns.stream().map(SelectItem::new).collect(Collectors.toList());
    return new CouchDbDataSet(selectItems, streamingView);
}
 
开发者ID:apache,项目名称:metamodel,代码行数:22,代码来源:CouchDbDataContext.java

示例10: executePrimaryKeyLookupQuery

import org.ektorp.CouchDbConnector; //导入依赖的package包/类
@Override
protected org.apache.metamodel.data.Row executePrimaryKeyLookupQuery(Table table, List<SelectItem> selectItems,
        Column primaryKeyColumn, Object keyValue) {
    if (keyValue == null) {
        return null;
    }

    final String databaseName = table.getName();
    final CouchDbConnector connector = _couchDbInstance.createConnector(databaseName, false);

    final String keyString = keyValue.toString();
    final JsonNode node = connector.find(JsonNode.class, keyString);
    if (node == null) {
        return null;
    }

    return CouchDbUtils.jsonNodeToMetaModelRow(node, new SimpleDataSetHeader(selectItems));
}
 
开发者ID:apache,项目名称:metamodel,代码行数:19,代码来源:CouchDbDataContext.java

示例11: execute

import org.ektorp.CouchDbConnector; //导入依赖的package包/类
@Override
public void execute() throws MetaModelException {
    Table table = getTable();
    List<FilterItem> whereItems = getWhereItems();

    CouchDbConnector connector = _updateCallback.getConnector(table.getName());
    CouchDbDataContext dataContext = _updateCallback.getDataContext();

    DataSet dataSet = dataContext.query().from(table)
            .select(CouchDbDataContext.FIELD_ID, CouchDbDataContext.FIELD_REV).where(whereItems).execute();
    try {
        while (dataSet.next()) {
            Row row = dataSet.getRow();
            String id = (String) row.getValue(0);
            String revision = (String) row.getValue(1);
            connector.delete(id, revision);
        }
    } finally {
        dataSet.close();
    }
}
 
开发者ID:apache,项目名称:metamodel,代码行数:22,代码来源:CouchDbRowDeletionBuilder.java

示例12: close

import org.ektorp.CouchDbConnector; //导入依赖的package包/类
@Override
public void close() {
	Collection<CouchDbConnector> connectorSet = _connectors.values();
	for (CouchDbConnector connector : connectorSet) {
		List<String> errornousResultsDescriptions = new ArrayList<String>();
		List<DocumentOperationResult> results = connector.flushBulkBuffer();
		for (DocumentOperationResult result : results) {
			if (result.isErroneous()) {
				String id = result.getId();
				String error = result.getError();
				String reason = result.getReason();
				String revision = result.getRevision();
				logger.error("Error occurred while flushing bulk buffer: {}, id: {}, revision: {}, reason: {}",
						new Object[] { error, id, revision, reason });
				errornousResultsDescriptions.add(error);
			}
		}

		if (!errornousResultsDescriptions.isEmpty()) {
			throw new MetaModelException(errornousResultsDescriptions.size() + " out of " + results.size()
					+ " operations in bulk was errornous: " + errornousResultsDescriptions);
		}
	}
}
 
开发者ID:apache,项目名称:metamodel,代码行数:25,代码来源:CouchDbUpdateCallback.java

示例13: GenericDao

import org.ektorp.CouchDbConnector; //导入依赖的package包/类
protected GenericDao(Class<T> type, CouchDbConnector db) {
	super(type, db, true);

	try {
		/*ParameterizedType genericSuperclass = (ParameterizedType) getClass()
				.getGenericSuperclass();
		this.m_persistenceClass = (Class<T>) genericSuperclass
				.getActualTypeArguments()[0];

		LOGGER.debugFormat("persistent class identified as {}", m_persistenceClass);*/
		LOGGER.debug("persistent class identified as {}", type);
		this.m_persistenceClass = type;
		
	} catch (Exception e) {
		LOGGER.error(e.getMessage(),e);
	}
}
 
开发者ID:williamd1618,项目名称:solace.common-java,代码行数:18,代码来源:GenericDao.java

示例14: expose

import org.ektorp.CouchDbConnector; //导入依赖的package包/类
@Produces
public CouchDbConnector expose() {

    try {
        // Connect to the database with the specified
        CouchDbConnector dbc = dbi.createConnector(DB_NAME, false);
        Log.log(Level.FINER, this, "Connected to {0}", DB_NAME);
        return dbc;
    } catch (Exception e) {
        // Log the warning, and then re-throw to prevent this class from going into service,
        // which will prevent injection to the Health check, which will make the app stay down.
        Log.log(Level.WARNING, this, "Unable to connect to database", e);
        throw e;
    }
}
 
开发者ID:gameontext,项目名称:gameon-map,代码行数:16,代码来源:CouchInjector.java

示例15: beforeClass

import org.ektorp.CouchDbConnector; //导入依赖的package包/类
@BeforeClass
public static void beforeClass() throws MalformedURLException {
    roomOwner = "testOwner";
    HttpClient httpClient = new StdHttpClient.Builder()
            .url("http://127.0.0.1:5984/")
            .build();
    dbi = new StdCouchDbInstance(httpClient);
    CouchDbConnector dbc = dbi.createConnector(CouchInjector.DB_NAME, false);

    repo = new MapRepository();
    repo.db = dbc;
    repo.postConstruct();
    debugWriter = repo.sites.mapper.writerWithDefaultPrettyPrinter();
    swapRoomsAccessPolicy = new AccessCertainResourcesPolicy(Collections.singleton(SiteSwapPermission.class));
}
 
开发者ID:gameontext,项目名称:gameon-map,代码行数:16,代码来源:TestLiveRoomSwap.java


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