public static Version create(long version) { // Versions count from 1 or use a constant, if ( version == UNSET.value() ) return UNSET; if ( version == INIT.value() ) return INIT; if ( version <= 0 ) throw new DeltaException(); return new Version(version, null); }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((patch == null) ? 0 : patch.hashCode()); result = prime * result + ((previous == null) ? 0 : previous.hashCode()); result = prime * result + ((version == null) ? 0 : version.hashCode()); return result; }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((dsd == null) ? 0 : dsd.hashCode()); result = prime * result + ((latestPatch == null) ? 0 : latestPatch.hashCode()); result = prime * result + ((maxVersion == null) ? 0 : maxVersion.hashCode()); result = prime * result + ((minVersion == null) ? 0 : minVersion.hashCode()); return result; }
public static PatchLogInfo fromJson(JsonObject obj) { DataSourceDescription dsd = DataSourceDescription.fromJson(obj); Version minVer = Version.fromJson(obj, F_MINVER, Version.UNSET) ; Version maxVer = Version.fromJson(obj, F_MAXVER, Version.UNSET) ; String latestPatchStr = JSONX.getStrOrNull(obj, F_LATEST); Id latestPatch = null; if ( latestPatchStr != null && !latestPatchStr.isEmpty() ) latestPatch = Id.fromString(latestPatchStr); return new PatchLogInfo(dsd, minVer, maxVer, latestPatch); }
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); }
/** Convert to original exception. */ public static DeltaHttpException extract(DeltaHttpException ex) { int statusCode = ex.getStatusCode(); String msg = ex.getMessage(); switch(statusCode) { case HttpSC.BAD_REQUEST_400: return new DeltaBadRequestException(msg); case HttpSC.NOT_FOUND_404: return new DeltaNotFoundException(msg); case HttpSC.UNAUTHORIZED_401: return new DeltaNotRegisteredException(msg); case HttpSC.FORBIDDEN_403: default: return ex; } }
@Override public String toString() { return String.format("[%s, %s, [%s,%s] <%s>]", getDataSourceId(), getDataSourceName(), verString(minVersion), verString(maxVersion), (latestPatch==null)?"":latestPatch.toString()); }
public Id getDsRef() { return dsd.getId() ; } }
@Override public long inc() { synchronized(lock) { long x = getInteger(); x++; setInteger(x); return x ; } }
/** Is this version a possible version? (i.e. not a marker) */ public static boolean isValid(Version version) { if ( version == null ) return false; return version.isValid(); }
@Override public Version getCurrentVersion() { return Version.create(version); }
/** Add fields to current JsonBuilder object */ public void addJsonFields(JsonBuilder b) { dsd.addJsonFields(b); b.key(F_MINVER).value(minVersion.asJson()); b.key(F_MAXVER).value(maxVersion.asJson()); if ( latestPatch != null ) b.key(F_LATEST).value(latestPatch.asString()); else b.key(F_LATEST).value(""); }
@Override public String toString() { return getStatusCode()+" : "+getMessage(); }
private void writeLocation(long value) { if ( filename != null ) { write(filename, value) ; } }
public void set(long x) { synchronized(lock) { value = x ; writeLocation(); } }
/** For labelling with the type of thing id'ed. eg "ds:abcdef" */ public String toSchemeString(String scheme) { if ( this == nilId ) return "id:nil"; if ( uuid != null ) return scheme+shortUUIDstr(uuid); return scheme+"\""+string+"\"" ; }
public long inc() { synchronized(lock) { long x = (value++) ; set(value) ; return x ; } }
public void set(byte[] x) { value = x ; valueStr = null; writeLocation(); }