Package org.ektorp

Examples of org.ektorp.CouchDbConnector


        HttpClient httpClient = new StdHttpClient.Builder()
                            .host("localhost")
                            .port(5984)
                            .build();
        CouchDbInstance couch = new StdCouchDbInstance(httpClient);
        CouchDbConnector connector = couch.createConnector("test-choose", true);
        app2.setupReplication(couch, connector);



View Full Code Here


         HttpClient httpClient1 = new StdHttpClient.Builder()
                            .host("localhost")
                            .port(5984)
                            .build();
        CouchDbInstance couch1 = new StdCouchDbInstance(httpClient1);
        CouchDbConnector connector1 = couch1.createConnector("ecko-it", false);



        HttpClient httpClient2 = new StdHttpClient.Builder()
                            .host("localhost")
                            .port(5984)
                            .build();
        CouchDbInstance couch2 = new StdCouchDbInstance(httpClient2);
        try {
            couch2.deleteDatabase("eckoit-clone");
        } catch(Exception ignore) {}
       
        CouchDbConnector connector2 = couch2.createConnector("eckoit-clone", true);
        app2.copyDesignDocs(connector1, connector2);

        app2.setupReplication(couch2, connector2);

    }
View Full Code Here

        try {
            showSplashDialog();

           
            couchDbInstance = localCouchManager.getCouchInstance();
            CouchDbConnector db = localCouchManager.getCouchConnector(localDbName, couchDbInstance);
            DbInfo info = db.getDbInfo();
           
            ready(db);
        } catch(CouchDBNotFoundException nfe) {
            ready(loadNeeded(true));
        } catch (Exception noInfo) {
View Full Code Here

                localCouchManager.installCouchDbEmbedded();

            }

            couchDbInstance = localCouchManager.getCouchInstance();
            CouchDbConnector db = localCouchManager.getCouchConnector(localDbName, couchDbInstance);
            try {
                db.createDatabaseIfNotExists();
            catch (org.ektorp.DbAccessException dae) {
                // we need to login to the db
                promptForCredientials(true);
                localCouchManager.setCredentials(local_username, local_password);
                couchDbInstance = localCouchManager.getCouchInstance();
                db = localCouchManager.getCouchConnector(localDbName, couchDbInstance);
                db.createDatabaseIfNotExists();
            }


            // handle design docs very differently.
            EventBus.publish(new LoadingMessage(step++, totalSteps, "Downloading Data", 0, 0, "Copy data from " + getSrcReplicationUrl(false) ));
View Full Code Here

    protected Map getReplicationIDs(CouchDbInstance instance) {
        HashMap map = new HashMap();
        // 1.0 and earlier will fail
        try {
            CouchDbConnector replicator = instance.createConnector("_replicator", false);
            ViewQuery query = new ViewQuery().allDocs().includeDocs(true);
            ViewResult result = replicator.queryView(query);
            for (Row row : result) {
                String replicationID = row.getDocAsNode().get("_replication_id").getTextValue();
                map.put(replicationID.substring(0,4), replicationID);
            }
        } catch (Exception e) {}
View Full Code Here

        if (StringUtils.equalsIgnoreCase(syncType, "none")) return;
        String src_fullurl = getSrcReplicationUrl(true);

        // create a continous replication
        CouchDbConnector rep_db = localCouchManager.getCouchConnector("_replicator", instance);

        try {
            ObjectMapper mapper = new ObjectMapper();
            if (StringUtils.equalsIgnoreCase(syncType, "bi-directional") || StringUtils.equalsIgnoreCase(syncType, "pull")) {

                ObjectNode pull = mapper.createObjectNode();
                pull.put("_id", "couchapp-takeout-" + localDbName + "-pull");
                pull.put("source", src_fullurl);
                pull.put("target", localDbName);
                pull.put("continuous", true);
                if (StringUtils.isNotEmpty(pullFilter)) {
                    pull.put("filter", pullFilter);
                }
                rep_db.create(pull);
            }
            if (StringUtils.equalsIgnoreCase(syncType, "bi-directional") || StringUtils.equalsIgnoreCase(syncType, "push")) {
                // other direction
                ObjectNode push = mapper.createObjectNode();
                push.put("_id", "couchapp-takeout-" + localDbName + "-push");
                push.put("target", src_fullurl);
                push.put("source", localDbName);
                push.put("continuous", true);
                if (StringUtils.isNotEmpty(pushFilter)) {
                    push.put("filter", pushFilter);
                }
                rep_db.create(push);
            }
        } catch(org.ektorp.UpdateConflictException uce) {
            // the entry exists already in the replicator.
        } catch (Exception e) {
            // something else...no replicator db
View Full Code Here

        }

        HttpClient httpClient = builder.build();

        CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);
        CouchDbConnector db = new StdCouchDbConnector(src_db, dbInstance);

        return db;
    }
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

    @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

    @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

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.