Package org.ektorp

Examples of org.ektorp.CouchDbConnector


            if (isSet(column)) {
                map.put(column.getName(), values[i]);
            }
        }

        CouchDbConnector connector = getUpdateCallback().getConnector(name);
        connector.addToBulkBuffer(map);
    }
View Full Code Here


    @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();
        }
    }
View Full Code Here

  }

  @Override
  public void execute() throws MetaModelException {
    final Table table = getTable();
    final CouchDbConnector connector = _updateCallback.getConnector(table.getName());

    // create a map which will act as a prototype for updated objects
    final Map<String, Object> prototype = new HashMap<String, Object>();
    final Column[] columns = getColumns();
    final Object[] values = getValues();
    for (int i = 0; i < columns.length; i++) {
      final Column column = columns[i];
      if (isSet(column)) {
        final String columnName = column.getName();
        final Object value = values[i];
        prototype.put(columnName, value);
      }
    }

    final CouchDbDataContext dc = _updateCallback.getDataContext();
    final DataSet dataSet = dc.query().from(table).select(table.getColumns()).where(getWhereItems()).execute();
    try {
      while (dataSet.next()) {
        final Map<String, Object> map = new HashMap<String, Object>(prototype);
        final Row row = dataSet.getRow();
        for (Column column : table.getColumns()) {
          if (!map.containsKey(column.getName())) {
            map.put(column.getName(), row.getValue(column));
          }
        }

        // copy the prototype and set the not-updated values
        connector.update(map);
      }
    } finally {
      dataSet.close();
    }
  }
View Full Code Here

    public CouchDbDatabaseDocumentSource(CouchDbInstance couchDbInstance, String databaseName, int maxRows) {
        _couchDbInstance = couchDbInstance;
        _databaseName = databaseName;
        _closed = new AtomicBoolean(false);

        final CouchDbConnector tableConnector = _couchDbInstance.createConnector(databaseName, false);
        if (maxRows > -1) {
            _view = tableConnector.queryForStreamingView(new ViewQuery().allDocs().includeDocs(true).limit(maxRows));
        } else {
            _view = tableConnector.queryForStreamingView(new ViewQuery().allDocs().includeDocs(true));
        }
        _rowIterator = _view.iterator();
    }
View Full Code Here

        final String databaseName = getDatabaseName();

        {
            // insert a document to provide data to do inferential schema
            // detection
            final CouchDbConnector connector = couchDbInstance.createConnector(databaseName, false);
            final Map<String, Object> map = new HashMap<String, Object>();
            map.put("foo", "bar");
            map.put("bar", "baz");
            map.put("baz", 1234);
            connector.addToBulkBuffer(map);
            connector.flushBulkBuffer();
        }

        final CouchDbDataContext dc = new CouchDbDataContext(couchDbInstance);
        Table table = dc.getDefaultSchema().getTableByName(databaseName);
        assertNotNull(table);
View Full Code Here

      }
    }
  }

  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);
    }
View Full Code Here

    @Override
    protected DataSet materializeMainSchemaTable(Table table, 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 SelectItem[] selectItems = MetaModelHelper.createSelectItems(columns);
        return new CouchDbDataSet(selectItems, streamingView);
    }
View Full Code Here

        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));
View Full Code Here

    @Override
    protected Number executeCountQuery(Table table, List<FilterItem> whereItems, boolean functionApproximationAllowed) {
        if (whereItems.isEmpty()) {
            String databaseName = table.getName();
            CouchDbConnector connector = _couchDbInstance.createConnector(databaseName, false);
            long docCount = connector.getDbInfo().getDocCount();
            return docCount;
        }
        return null;
    }
View Full Code Here

            if (databaseName.startsWith("_")) {
                // don't add system tables
                continue;
            }

            CouchDbConnector connector = couchDbInstance.createConnector(databaseName, false);

            SimpleTableDef tableDef = detectTable(connector);
            tableDefs.add(tableDef);
        }
        return tableDefs.toArray(new SimpleTableDef[tableDefs.size()]);
View Full Code Here

TOP

Related Classes of org.ektorp.CouchDbConnector

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.