protected void writeBoolean(Store store, Transaction txn, ByteIterable key, boolean value) { byte[] bytes = new byte[] {(byte)(value?1:0)}; store.put(txn, key, new ArrayByteIterable(bytes)); }
protected void writeInt(Store store, Transaction txn, ByteIterable key, int value) { byte[] bytes = ByteBuffer.allocate(Integer.BYTES).putInt(value).array(); store.put(txn, key, new ArrayByteIterable(bytes)); }
protected void writeLong(Store store, Transaction txn, ByteIterable key, long value) { byte[] bytes = ByteBuffer.allocate(Long.BYTES).putLong(value).array(); store.put(txn, key, new ArrayByteIterable(bytes)); }
protected void writeLongs(Store store, Transaction txn, ByteIterable key, Collection<Long> collection) { store.put(txn, key, new LongsByteIterable(collection)); }
@Override public void put(byte[] key, byte[] value) { key.getClass(); value.getClass(); Preconditions.checkState(!this.closed.get(), "transaction closed"); Preconditions.checkState(!this.txType.isReadOnly(), "read-only transaction"); this.store.put(this.tx, new ArrayByteIterable(key), new ArrayByteIterable(value)); }
protected void writeCommits(Store store, Transaction txn, ByteIterable key, Collection<ObjectId> commits) { byte[] bytes = new byte[commits.size()*20]; int index = 0; for (ObjectId commit: commits) { commit.copyRawTo(bytes, index); index += 20; } store.put(txn, key, new ArrayByteIterable(bytes)); }
@Override public void putAll( final LocalDB.DB db, final Map<String, String> keyValueMap ) throws LocalDBException { checkStatus( true ); environment.executeInTransaction( transaction -> { final Store store = getStore( db ); for ( final Map.Entry<String, String> entry : keyValueMap.entrySet() ) { final ByteIterable k = bindMachine.keyToEntry( entry.getKey() ); final ByteIterable v = bindMachine.valueToEntry( entry.getValue() ); store.put( transaction, k, v ); } } ); outputLogExecutor.conditionallyExecuteTask(); }
@Override public boolean put( final LocalDB.DB db, final String key, final String value ) throws LocalDBException { checkStatus( true ); return environment.computeInTransaction( transaction -> { final ByteIterable k = bindMachine.keyToEntry( key ); final ByteIterable v = bindMachine.valueToEntry( value ); final Store store = getStore( db ); return store.put( transaction, k, v ); } ); }
private int getPathIndex(Store pathToIndexStore, Store indexToPathStore, Transaction txn, NextIndex nextIndex, String path) { StringByteIterable pathKey = new StringByteIterable(path); int pathIndex = readInt(pathToIndexStore, txn, pathKey, -1); if (pathIndex == -1) { pathIndex = nextIndex.path++; writeInt(pathToIndexStore, txn, pathKey, pathIndex); indexToPathStore.put(txn, new IntByteIterable(pathIndex), new StringByteIterable(path)); } return pathIndex; }
userIndex = nextIndex.user++; writeInt(emailToIndexStore, txn, emailKey, userIndex); indexToUserStore.put(txn, new IntByteIterable(userIndex), new ArrayByteIterable(SerializationUtils.serialize(nameAndEmail))); bytesOfHistoryPaths.length, Integer.BYTES); buffer.putInt(oldPathIndex); historyPathsStore.put(txn, pathKey, new ArrayByteIterable(newBytesOfHistoryPaths)); dailyContributionsStore.put(txn, new IntByteIterable(entry.getKey()), new ArrayByteIterable(bytesOfContributionsOnDay)); defaultStore.put(txn, OVERALL_CONTRIBUTIONS_KEY, new ArrayByteIterable(serializeContributions(overallContributions))); defaultStore.put(txn, LINE_STATS_KEY, new ArrayByteIterable(bytesOfLineStats)); defaultStore.put(txn, USERS_KEY, new ArrayByteIterable(userBytes)); usersCache.remove(project.getId()); defaultStore.put(txn, FILES_KEY, new ArrayByteIterable(fileBytes)); filesCache.remove(project.getId()); writeInt(editsStore, txn, new LongByteIterable(entry.getKey()), entry.getValue()); defaultStore.put(txn, LAST_COMMIT_OF_DEFAULT_BRANCH_KEY, new CommitByteIterable(currentCommitId));
@Override public void execute(Transaction txn) { ByteIterable configurationKey = new LongByteIterable(build.getConfiguration().getId()); Collection<ObjectId> lastCommits = readCommits(lastCommitsStore, txn, configurationKey); if (lastCommits.isEmpty() && build.getConfiguration().getBaseCommit() != null) lastCommits.add(ObjectId.fromString(build.getConfiguration().getBaseCommit())); writeCommits(prevCommitsStore, txn, new LongByteIterable(build.getId()), lastCommits); ObjectId buildCommit = ObjectId.fromString(build.getCommitHash()); boolean addCommit = true; for (Iterator<ObjectId> it = lastCommits.iterator(); it.hasNext();) { ObjectId lastCommit = it.next(); if (GitUtils.isMergedInto(project.getRepository(), null, lastCommit, buildCommit)) { it.remove(); } else if (GitUtils.isMergedInto(project.getRepository(), null, buildCommit, lastCommit)) { addCommit = false; break; } } if (addCommit) lastCommits.add(buildCommit); writeCommits(lastCommitsStore, txn, configurationKey, lastCommits); defaultStore.put(txn, LAST_BUILD_KEY, new LongByteIterable(build.getId())); }
@LocalDB.WriteOperation public boolean putIfAbsent( final LocalDB.DB db, final String key, final String value ) throws LocalDBException { checkStatus( true ); return environment.computeInTransaction( transaction -> { final ByteIterable k = bindMachine.keyToEntry( key ); final ByteIterable v = bindMachine.valueToEntry( value ); final Store store = getStore( db ); final ByteIterable existingValue = store.get( transaction, k ); if ( existingValue != null ) { return false; } return store.put( transaction, k, v ); } ); }
codeCommentStore.put(txn, commitKey, new ArrayByteIterable(SerializationUtils.serialize((Serializable) comments)));
commitsStore.put(txn, nextCommitKey, new ArrayByteIterable(newNextCommitBytes)); commitsStore.put(txn, parentCommitKey, new ArrayByteIterable(newParentCommitBytes)); commitCountCache.remove(project.getId()); defaultStore.put(txn, LAST_COMMIT_KEY, new CommitByteIterable(commitId)); } catch (IOException e) { throw new RuntimeException(e);
@Override public void execute(Transaction txn) { associateCommentWithCommit(txn, comment.getMarkPos().getCommit()); String compareCommit = comment.getCompareContext().getCompareCommit(); if (!comment.getMarkPos().getCommit().equals(compareCommit) && project.getRepository().hasObject(ObjectId.fromString(compareCommit))) associateCommentWithCommit(txn, comment.getCompareContext().getCompareCommit()); defaultStore.put(txn, LAST_CODE_COMMENT_KEY, new LongByteIterable(comment.getId())); }