@Override public Version getCurrentVersion() { return Version.create(version); }
@Override public Version nextVersion() { Version ver = Version.create(version+1); FmtLog.debug(LOG, "Alloc version %d", ver); return ver; }
@Override public Version getEarliestVersion() { return Version.create(fileStore.getMinIndex()); }
public static Version fromJson(JsonObject obj, String field, Version dftValue) { long ver = JSONX.getLong(obj, field, dftValue.version) ; return create(ver); }
@Override public Version getLatestVersion() { validateLatest(); return Version.create(fileStore.getCurrentIndex()); }
public Version inc() { if ( this == INIT ) return FIRST; if ( ! isValid() ) throw new DeltaException("Attempt to get inc version on a non-version number: "+this); return Version.create(version+1); }
public static Version fromJson(JsonObject obj, String field) { long ver = JSONX.getLong(obj, field, -99) ; if ( ver < -1 ) throw new DeltaException("Bad version number: '"+JSON.toStringFlat(obj.get(field))+"'"); return create(ver); }
@Override public PatchInfo getPatchInfo(Id id) { String p = headerPath(id); JsonObject obj = Zk.zkFetchJson(client, p); Id patchId = getIdOrNull(obj, fId); if ( ! Objects.equals(id, patchId) ) { /*msg*/ } Id prevId = getIdOrNull(obj, fPrevious); long ver = JSONX.getLong(obj, fVersion, -99); Version version = ver < 0 ? Version.UNSET : Version.create(ver); return new PatchInfo(patchId, Version.UNSET, prevId); }
public static Version create(JsonValue version) { Objects.requireNonNull(version, "version"); if ( version.isNumber() ) { long ver = JSONX.getLong(version, -2); if ( ver < -1 ) throw new DeltaException("Bad version number: '"+JSON.toStringFlat(version)+"'"); return create(ver); } if ( version.isString() ) { try { String s = version.getAsString().value(); long ver = Long.parseLong(s); return create(ver); } catch (NumberFormatException ex) { throw new DeltaException("Bad format for version: '"+JSON.toStringFlat(version)+"'"); } } throw new DeltaException("Unrecognized JSON version: '"+JSON.toStringFlat(version)+"'"); }
@Override protected void execCmd() { if ( getPositional().isEmpty() ) { Id dsRef = getDescription().getId(); PatchLogInfo logInfo = dLink.getPatchLogInfo(dsRef); if ( ! logInfo.getMaxVersion().isValid()) { throw new CmdException(getCommandName()+" : Empty log"); } exec1(logInfo.getMaxVersion()); return ; } getPositional().forEach(v->{ long patchVersion; try { patchVersion = Integer.parseInt(v); } catch (NumberFormatException ex) { throw new CmdException(getCommandName()+" : Invalid version"); } exec1(Version.create(patchVersion)); }); }
Version ver = Version.create(idx); idToVersion.put(id, ver); latestId = id;
/** Play patches, return details of the the last successfully applied one */ private static Pair<Version, Node> play(Id datasourceId, RDFChanges target, DeltaLink dLink, long minVersion, long maxVersion) { // [Delta] replace with a one-shot "get all patches" operation. //FmtLog.debug(LOG, "Patch range [%d, %d]", minVersion, maxVersion); Node patchLastIdNode = null; Version patchLastVersion = Version.UNSET; for ( long ver = minVersion ; ver <= maxVersion ; ver++ ) { //FmtLog.debug(LOG, "Play: patch=%d", ver); RDFPatch patch; Version verObj = Version.create(ver); try { patch = dLink.fetch(datasourceId, verObj); if ( patch == null ) { FmtLog.info(LOG, "Play: %s patch=%d : not found", datasourceId, verObj); continue; } } catch (DeltaNotFoundException ex) { // Which ever way it is signalled. This way means "bad datasourceId" FmtLog.info(LOG, "Play: %s patch=%d : not found", datasourceId, verObj); continue; } RDFChanges c = target; if ( false ) c = DeltaOps.print(c); patch.apply(c); patchLastIdNode = patch.getId(); patchLastVersion = verObj; } return Pair.create(patchLastVersion, patchLastIdNode); }
}); Version version = Version.create(entry.version); validateVersionNotInUse(version); idToVersion.put(patchId, version);