public OAuthTokenDAO(AuthzTrans trans, Cluster cluster, String keyspace) {
super(trans, OAuthTokenDAO.class.getSimpleName(),cluster, keyspace, Data.class,TABLE, readConsistency(trans,TABLE), writeConsistency(trans,TABLE));
public OAuthTokenDAO(AuthzTrans trans, Cluster cluster, String keyspace) {
super(trans, OAuthTokenDAO.class.getSimpleName(),cluster, keyspace, Data.class,TABLE, readConsistency(trans,TABLE), writeConsistency(trans,TABLE));
- public static class Data implements Bytification {
- public String id;
- public String client_id;
- public String user;
- public boolean active;
- public int type;
- public String refresh;
- public Date expires;
- public long exp_sec;
- public String content;
- public Set<String> scopes;
- public String state;
- public String req_ip; // requesting
-
- public Set<String> scopes(boolean mutable) {
- if (scopes == null) {
- scopes = new HashSet<>();
- } else if (mutable && !(scopes instanceof HashSet)) {
- scopes = new HashSet<>(scopes);
- }
- return scopes;
- }
-
- @Override
- public ByteBuffer bytify() throws IOException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- OAuthLoader.deflt.marshal(this,new DataOutputStream(baos));
- return ByteBuffer.wrap(baos.toByteArray());
- }
-
- @Override
- public void reconstitute(ByteBuffer bb) throws IOException {
- OAuthLoader.deflt.unmarshal(this, toDIS(bb));
- }
-
- public String toString() {
- return user.toString() + ' ' + id.toString() + ' ' + Chrono.dateTime(expires) + (active?"":"in") + "active";
- }
+ public static class Data implements Bytification {
+ public String id;
+ public String client_id;
+ public String user;
+ public boolean active;
+ public int type;
+ public String refresh;
+ public Date expires;
+ public long exp_sec;
+ public String content;
+ public Set<String> scopes;
+ public String state;
+ public String req_ip; // requesting
+
+ public Set<String> scopes(boolean mutable) {
+ if (scopes == null) {
+ scopes = new HashSet<>();
+ } else if (mutable && !(scopes instanceof HashSet)) {
+ scopes = new HashSet<>(scopes);
+ }
+ return scopes;
+ }
+
+ @Override
+ public ByteBuffer bytify() throws IOException {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ OAuthLoader.deflt.marshal(this,new DataOutputStream(baos));
+ return ByteBuffer.wrap(baos.toByteArray());
+ }
+
+ @Override
+ public void reconstitute(ByteBuffer bb) throws IOException {
+ OAuthLoader.deflt.unmarshal(this, toDIS(bb));
+ }
+
+ public String toString() {
+ return user.toString() + ' ' + id.toString() + ' ' + Chrono.dateTime(expires) + (active?"":"in") + "active";
+ }
- @Override
- public void marshal(Data data, DataOutputStream os) throws IOException {
- writeHeader(os,MAGIC,VERSION);
- writeString(os, data.id);
- writeString(os, data.client_id);
- writeString(os, data.user);
- os.writeBoolean(data.active);
- os.writeInt(data.type);
- writeString(os, data.refresh);
- os.writeLong(data.expires==null?-1:data.expires.getTime());
- os.writeLong(data.exp_sec);
- writeString(os, data.content);
- writeStringSet(os,data.scopes);
- writeString(os, data.state);
- writeString(os, data.req_ip);
- }
-
-
- @Override
- public void unmarshal(Data data, DataInputStream is) throws IOException {
- /*int version = */readHeader(is,MAGIC,VERSION);
- // If Version Changes between Production runs, you'll need to do a switch Statement, and adequately read in fields
- byte[] buff = new byte[BUFF_SIZE]; // used only if fits
- data.id = readString(is,buff);
- data.client_id = readString(is,buff);
- data.user = readString(is,buff);
- data.active = is.readBoolean();
- data.type = is.readInt();
- data.refresh = readString(is,buff);
- long l = is.readLong();
- data.expires = l<0?null:new Date(l);
- data.exp_sec = is.readLong();
- data.content = readString(is,buff); // note, large strings still ok with small buffer
- data.scopes = readStringSet(is,buff);
- data.state = readString(is,buff);
- data.req_ip = readString(is,buff);
- }
+ @Override
+ public void marshal(Data data, DataOutputStream os) throws IOException {
+ writeHeader(os,MAGIC,VERSION);
+ writeString(os, data.id);
+ writeString(os, data.client_id);
+ writeString(os, data.user);
+ os.writeBoolean(data.active);
+ os.writeInt(data.type);
+ writeString(os, data.refresh);
+ os.writeLong(data.expires==null?-1:data.expires.getTime());
+ os.writeLong(data.exp_sec);
+ writeString(os, data.content);
+ writeStringSet(os,data.scopes);
+ writeString(os, data.state);
+ writeString(os, data.req_ip);
+ }
+
+
+ @Override
+ public void unmarshal(Data data, DataInputStream is) throws IOException {
+ /*int version = */readHeader(is,MAGIC,VERSION);
+ // If Version Changes between Production runs, you'll need to do a switch Statement, and adequately read in fields
+ byte[] buff = new byte[BUFF_SIZE]; // used only if fits
+ data.id = readString(is,buff);
+ data.client_id = readString(is,buff);
+ data.user = readString(is,buff);
+ data.active = is.readBoolean();
+ data.type = is.readInt();
+ data.refresh = readString(is,buff);
+ long l = is.readLong();
+ data.expires = l<0?null:new Date(l);
+ data.exp_sec = is.readLong();
+ data.content = readString(is,buff); // note, large strings still ok with small buffer
+ data.scopes = readStringSet(is,buff);
+ data.state = readString(is,buff);
+ data.req_ip = readString(is,buff);
+ }