Debian Codegraph @

jetty-integrations/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/NoSqlSessionDataStore.java

raw
1 //
2 // ========================================================================
3 // Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
4 //
5 // This program and the accompanying materials are made available under the
6 // terms of the Eclipse Public License v. 2.0 which is available at
7 // https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
8 // which is available at https://www.apache.org/licenses/LICENSE-2.0.
9 //
10 // SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
11 // ========================================================================
12 //
13
14 package org.eclipse.jetty.nosql;
15
16 import java.util.HashSet;
17 import java.util.Set;
18
19 import org.eclipse.jetty.session.ObjectStreamSessionDataStore;
20 import org.eclipse.jetty.session.SessionData;
21
22 /**
23 * NoSqlSessionDataStore
24 */
25 public abstract class NoSqlSessionDataStore extends ObjectStreamSessionDataStore
26 {
27
28 public class NoSqlSessionData extends SessionData
29 {
30 private Object _version;
31 private Set<String> _dirtyAttributes = new HashSet<>();
32
33 public NoSqlSessionData(String id, String cpath, String vhost, long created, long accessed, long lastAccessed, long maxInactiveMs)
34 {
35 super(id, cpath, vhost, created, accessed, lastAccessed, maxInactiveMs);
36 setVersion(0L);
37 }
38
39 public void setVersion(Object v)
40 {
41 _version = v;
42 }
43
44 public Object getVersion()
45 {
46 return _version;
47 }
48
49 @Override
50 public void setDirty(String name)
51 {
52 super.setDirty(name);
53 _dirtyAttributes.add(name);
54 }
55
56 public Set<String> takeDirtyAttributes()
57 {
58 Set<String> copy = new HashSet<>(_dirtyAttributes);
59 _dirtyAttributes.clear();
60 return copy;
61 }
62
63 public Set<String> getAllAttributeNames()
64 {
65 return new HashSet<>(_attributes.keySet());
66 }
67 }
68
69 @Override
70 public SessionData newSessionData(String id, long created, long accessed, long lastAccessed, long maxInactiveMs)
71 {
72 return new NoSqlSessionData(id, _context.getCanonicalContextPath(), _context.getVhost(), created, accessed, lastAccessed, maxInactiveMs);
73 }
74 }