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


Java Database类代码示例

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


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

示例1: setupViewAndQuery

import com.couchbase.lite.Database; //导入依赖的package包/类
private void setupViewAndQuery() {
    Database database = SyncManager.get().getDatabase();
    LiveQuery liveQuery = database.createAllDocumentsQuery().toLiveQuery();
    liveQuery.addChangeListener(new LiveQuery.ChangeListener() {
        @Override
        public void changed(final LiveQuery.ChangeEvent event) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    docsCountView.setText(String.valueOf(event.getRows().getCount()));
                }
            });
        }
    });
    liveQuery.start();
}
 
开发者ID:couchbaselabs,项目名称:mini-hacks,代码行数:17,代码来源:MainActivity.java

示例2: setupQuery

import com.couchbase.lite.Database; //导入依赖的package包/类
private void setupQuery() {
    Database database = null;
    try {
        database = manager.getExistingDatabase("todo");
    } catch (CouchbaseLiteException e) {
        e.printStackTrace();
    }
    if (database != null) {
        LiveQuery liveQuery = database.createAllDocumentsQuery().toLiveQuery();
        liveQuery.addChangeListener(new LiveQuery.ChangeListener() {
            @Override
            public void changed(final LiveQuery.ChangeEvent event) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        docCountLabel.setText(String.valueOf(event.getRows().getCount()));
                    }
                });
            }
        });
        liveQuery.start();
    }
}
 
开发者ID:couchbaselabs,项目名称:mini-hacks,代码行数:24,代码来源:MainActivity.java

示例3: initializePuzzleTypes

import com.couchbase.lite.Database; //导入依赖的package包/类
@NonNull
private static Completable initializePuzzleTypes(Context context, Database database) {
    return Completable.create(completableSubscriber -> {
        Query puzzleTypesQuery = database.getView(VIEW_PUZZLETYPES).createQuery();
        puzzleTypesQuery.runAsync((rows, error) -> {
            if (!rows.hasNext()) {
                try {
                    initializeFirstRun(context);
                    completableSubscriber.onCompleted();
                } catch (CouchbaseLiteException | IOException e) {
                    completableSubscriber.onError(e);
                }
            } else {
                List<PuzzleType> puzzleTypes = new ArrayList<>();
                for (QueryRow row : rows) {
                    PuzzleType type = PuzzleType.fromDoc(row.getDocument(), PuzzleType.class);
                    puzzleTypes.add(type);
                }

                sPuzzleTypes = puzzleTypes;

                completableSubscriber.onCompleted();
            }
        });
    }).subscribeOn(Schedulers.io());
}
 
开发者ID:plusCubed,项目名称:plusTimer,代码行数:27,代码来源:PuzzleType.java

示例4: changed

import com.couchbase.lite.Database; //导入依赖的package包/类
/**
 * This is called back for changes from the ReplicationInternal.
 * Simply propagate the events back to all listeners.
 */
@Override
public void changed(ChangeEvent event) {
    // forget cached IDs (Should be executed in workExecutor)
    final long lastSeqPushed = (isPull() || replicationInternal.lastSequence == null) ? -1L :
            Long.valueOf(replicationInternal.lastSequence);
    if (lastSeqPushed >= 0 && lastSeqPushed != _lastSequencePushed) {
        db.runAsync(new AsyncTask() {
            @Override
            public void run(Database database) {
                synchronized (_lockPendingDocIDs) {
                    _lastSequencePushed = lastSeqPushed;
                    _pendingDocIDs = null;
                }
            }
        });
    }

    for (ChangeListener changeListener : changeListeners) {
        try {
            changeListener.changed(event);
        } catch (Exception e) {
            Log.e(Log.TAG_SYNC, "Exception calling changeListener.changed", e);
        }
    }
}
 
开发者ID:couchbase,项目名称:couchbase-lite-java-core,代码行数:30,代码来源:Replication.java

示例5: RemoteMultipartRequest

import com.couchbase.lite.Database; //导入依赖的package包/类
public RemoteMultipartRequest(
        HttpClientFactory clientFactory,
        String method,
        URL url,
        boolean syncGateway,
        boolean cancelable,
        Map<String, ?> body,
        Map<String, Object> attachments,
        Database db,
        Map<String, Object> requestHeaders,
        RemoteRequestCompletion onCompletion) {
    super(clientFactory, method, url, cancelable, body, requestHeaders, onCompletion);
    this.attachments = attachments;
    this.db = db;
    this.syncGateway = syncGateway;
}
 
开发者ID:couchbase,项目名称:couchbase-lite-java-core,代码行数:17,代码来源:RemoteMultipartRequest.java

示例6: RemoteBulkDownloaderRequest

import com.couchbase.lite.Database; //导入依赖的package包/类
public RemoteBulkDownloaderRequest(HttpClientFactory factory,
                                   URL dbURL,
                                   boolean cancelable,
                                   List<RevisionInternal> revs,
                                   Database db,
                                   Map<String, Object> requestHeaders,
                                   BulkDownloaderDocument onDocument,
                                   RemoteRequestCompletion onCompletion)
        throws Exception {
    super(factory,
            "POST",
            new URL(buildRelativeURLString(dbURL, "/_bulk_get?revs=true&attachments=true")),
            cancelable,
            buildJSONBody(revs, db),
            requestHeaders,
            onCompletion);
    this.db = db;
    _onDocument = onDocument;
}
 
开发者ID:couchbase,项目名称:couchbase-lite-java-core,代码行数:20,代码来源:RemoteBulkDownloaderRequest.java

示例7: buildJSONBody

import com.couchbase.lite.Database; //导入依赖的package包/类
private static Map<String, Object> buildJSONBody(List<RevisionInternal> revs, final Database db) {
    // Build up a JSON body describing what revisions we want:
    final int maxRevTreeDepth = db.getMaxRevTreeDepth();
    Collection<Map<String, Object>> keys = CollectionUtils.transform(
            revs, new CollectionUtils.Functor<RevisionInternal, Map<String, Object>>() {
                public Map<String, Object> invoke(RevisionInternal rev) {
                    AtomicBoolean haveBodies = new AtomicBoolean(false);
                    List<String> possibleAncestors = db.getPossibleAncestorRevisionIDs(
                            rev, PullerInternal.MAX_NUMBER_OF_ATTS_SINCE, haveBodies, true);
                    Map<String, Object> key = new HashMap<String, Object>();
                    key.put("id", rev.getDocID());
                    key.put("rev", rev.getRevID());
                    if (possibleAncestors != null) {
                        key.put(haveBodies.get() ? "atts_since" : "revs_from", possibleAncestors);
                    } else {
                        if (rev.getGeneration() > maxRevTreeDepth)
                            key.put("revs_limit", maxRevTreeDepth);
                    }
                    return key;
                }
            });
    Map<String, Object> retval = new HashMap<String, Object>();
    retval.put("docs", keys);
    return retval;
}
 
开发者ID:couchbase,项目名称:couchbase-lite-java-core,代码行数:26,代码来源:RemoteBulkDownloaderRequest.java

示例8: findCommonAncestor

import com.couchbase.lite.Database; //导入依赖的package包/类
/**
 * Given a revision and an array of revIDs, finds the latest common ancestor revID
 * and returns its generation #. If there is none, returns 0.
 * <p/>
 * int CBLFindCommonAncestor(CBL_Revision* rev, NSArray* possibleRevIDs) in CBLRestPusher.m
 */
private static int findCommonAncestor(RevisionInternal rev, List<String> possibleRevIDs) {
    if (possibleRevIDs == null || possibleRevIDs.size() == 0) {
        return 0;
    }
    List<String> history = Database.parseCouchDBRevisionHistory(rev.getProperties());

    //rev is missing _revisions property
    assert (history != null);

    boolean changed = history.retainAll(possibleRevIDs);
    String ancestorID = history.size() == 0 ? null : history.get(0);

    if (ancestorID == null) {
        return 0;
    }

    int generation = RevisionUtils.parseRevIDNumber(ancestorID);

    return generation;
}
 
开发者ID:couchbase,项目名称:couchbase-lite-java-core,代码行数:27,代码来源:PusherInternal.java

示例9: parseJson

import com.couchbase.lite.Database; //导入依赖的package包/类
private void parseJson() {
    if(parsed) {
        return;
    }

    try {
        List<T> parsedvalues  = (List<T>) Manager.getObjectMapper().readValue(json, Object.class);
        //Merge parsed values into List, overwriting the values for duplicate keys
        parsedvalues.addAll(cache);
        cache = parsedvalues;
    } catch (Exception e) {
        Log.e(Database.TAG, this.getClass().getName()+": Failed to parse Json data: ", e);
    } finally {
        parsed = true;
        json = null;
    }
}
 
开发者ID:couchbase,项目名称:couchbase-lite-java-core,代码行数:18,代码来源:LazyJsonArray.java

示例10: parseJson

import com.couchbase.lite.Database; //导入依赖的package包/类
private void parseJson() {
    if (parsed) {
        return;
    }

    try {
        Map<K, V> parsedprops = (Map<K, V>) Manager.getObjectMapper().readValue(json, Object.class);
        //Merge parsed properties into map, overwriting the values for duplicate keys
        parsedprops.putAll(cache);
        cache = parsedprops;
    } catch (Exception e) {
        Log.e(Database.TAG, this.getClass().getName() + ": Failed to parse Json data: ", e);
    } finally {
        parsed = true;
        json = null;
    }
}
 
开发者ID:couchbase,项目名称:couchbase-lite-java-core,代码行数:18,代码来源:LazyJsonObject.java

示例11: loadPreviouslyStoredCookies

import com.couchbase.lite.Database; //导入依赖的package包/类
private void loadPreviouslyStoredCookies(Database db) {
    Map<String, Object> cookiesDoc = db.getExistingLocalDocument(COOKIE_LOCAL_DOC_NAME);
    if (cookiesDoc == null)
        return;
    for (String name : cookiesDoc.keySet()) {
        // ignore special couchbase lite fields like _id and _rev
        if (name.startsWith("_"))
            continue;
        String encodedCookie = (String) cookiesDoc.get(name);
        if (encodedCookie == null)
            continue;
        Cookie decodedCookie = new SerializableCookie().decode(encodedCookie);
        if (decodedCookie == null)
            continue;
        // NOTE: no check for expiration
        cookies.put(name, decodedCookie);
    }
}
 
开发者ID:couchbase,项目名称:couchbase-lite-java-core,代码行数:19,代码来源:PersistentCookieJar.java

示例12: getContent

import com.couchbase.lite.Database; //导入依赖的package包/类
public byte[] getContent() {
    byte[] data = getEncodedContent();
    switch (encoding) {
        case AttachmentEncodingGZIP:
            if (data != null)
                data = Utils.decompressByGzip(data);
            break;
        case AttachmentEncodingNone:
            // special case
            if (data != null && blobKey != null && database != null &&
                    database.getAttachmentStore().isGZipped(blobKey)) {
                data = Utils.decompressByGzip(data);
                encoding = AttachmentEncoding.AttachmentEncodingGZIP;
            }
            break;
    }
    if (data == null)
        Log.w(Database.TAG, "Unable to decode attachment!");

    return data;
}
 
开发者ID:couchbase,项目名称:couchbase-lite-java-core,代码行数:22,代码来源:AttachmentInternal.java

示例13: do_GET_Database

import com.couchbase.lite.Database; //导入依赖的package包/类
/**
 * DATABASE REQUESTS: *
 */

public Status do_GET_Database(Database _db, String _docID, String _attachmentName) {
    // http://wiki.apache.org/couchdb/HTTP_database_API#Database_Information
    Status status = openDB();
    if (!status.isSuccessful()) {
        return status;
    }
    // NOTE: all methods are read operation. not necessary to be synchronized
    int num_docs = db.getDocumentCount();
    long update_seq = db.getLastSequenceNumber();
    long instanceStartTimeMicroseconds = db.getStartTime() * 1000;
    Map<String, Object> result = new HashMap<String, Object>();
    result.put("db_name", db.getName());
    result.put("db_uuid", db.publicUUID());
    result.put("doc_count", num_docs);
    result.put("update_seq", update_seq);
    result.put("disk_size", db.totalDataSize());
    result.put("instance_start_time", instanceStartTimeMicroseconds);

    connection.setResponseBody(new Body(result));
    return new Status(Status.OK);
}
 
开发者ID:couchbase,项目名称:couchbase-lite-java-core,代码行数:26,代码来源:Router.java

示例14: do_POST_Document_all_docs

import com.couchbase.lite.Database; //导入依赖的package包/类
public Status do_POST_Document_all_docs(Database _db, String _docID, String _attachmentName)
        throws CouchbaseLiteException {
    QueryOptions options = new QueryOptions();
    if (!getQueryOptions(options)) {
        return new Status(Status.BAD_REQUEST);
    }

    Map<String, Object> body = getBodyAsDictionary();
    if (body == null) {
        return new Status(Status.BAD_REQUEST);
    }

    List<Object> keys = (List<Object>) body.get("keys");
    options.setKeys(keys);

    Map<String, Object> result = db.getAllDocs(options);
    if (result == null) {
        return new Status(Status.INTERNAL_SERVER_ERROR);
    } else {
        convertCBLQueryRowsToMaps(result);
    }
    connection.setResponseBody(new Body(result));
    return new Status(Status.OK);
}
 
开发者ID:couchbase,项目名称:couchbase-lite-java-core,代码行数:25,代码来源:Router.java

示例15: do_POST_Document_compact

import com.couchbase.lite.Database; //导入依赖的package包/类
@SuppressWarnings("MethodMayBeStatic")
public Status do_POST_Document_compact(Database _db, String _docID, String _attachmentName) {
    Status status = new Status(Status.OK);
    try {
        // Make Database.compact() thread-safe
        _db.compact();
    } catch (CouchbaseLiteException e) {
        status = e.getCBLStatus();
    }

    if (status.getCode() < 300) {
        Status outStatus = new Status();
        outStatus.setCode(202);    // CouchDB returns 202 'cause it's an async operation
        return outStatus;
    } else {
        return status;
    }
}
 
开发者ID:couchbase,项目名称:couchbase-lite-java-core,代码行数:19,代码来源:Router.java


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