Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.neolumin.simpleOrm;
  
 
 import java.util.Map;
 import java.util.Set;
 
     // Used by Jetty
     @SuppressWarnings("UnusedDeclaration")
     public static final Class TYPE = SessionManager.class;
 
     private static final int CACHE_MAX_SIZE = 50;
     private static final int CACHE_EXPIRE_MINUTES = 10;
     private static final String VISIBILITY_STRING = "";
 
     private final SimpleOrmSession simpleOrmSession;
     private final SimpleOrmContext simpleOrmContext;
     private final LoadingCache<StringOptional<JettySession>> cache;
 
     // Used by Jetty
     @SuppressWarnings("UnusedDeclaration")
     public SimpleOrmJettySessionManager(SimpleOrmSession simpleOrmSession) {
         this(simpleOrmSessionsimpleOrmSession.createContext());
     }
 
     public SimpleOrmJettySessionManager(SimpleOrmSession simpleOrmSessionSimpleOrmContext simpleOrmContext) {
         this. = simpleOrmSession;
         this. = simpleOrmContext;
 
         this. = CacheBuilder.newBuilder()
                 .maximumSize()
                 .expireAfterWrite(.)
                 .build(new CacheLoader<StringOptional<JettySession>>() {
                     @Override
                     public Optional<JettySessionload(@SuppressWarnings("NullableProblems"String clusterIdthrows Exception {
                         return Optional.fromNullable(getSimpleOrmSession().findById(JettySession.classclusterIdgetSimpleOrmContext()));
                     }
                 });
     }
 
     @Override
     protected NoSqlSession loadSession(String clusterId) {
         Optional<JettySessionrow = .getUnchecked(clusterId);
         if (!row.isPresent()) {
             return null;
         }
 
         JettySession jettySession = row.get();
         NoSqlSession session = new NoSqlSession(
                 this,
                 jettySession.getCreated(),
                 jettySession.getAccessed(),
                 jettySession.getClusterId(),
                 jettySession.getVersion());
         setData(sessionjettySession.getData());
         session.didActivate();
 
         return session;
     }
 
     @Override
     protected Object save(NoSqlSession sessionObject versionboolean activateAfterSave) {
         session.willPassivate();
 
         if (session.isValid()) {
             boolean isNew = false;
             JettySession row;
 
             Optional<JettySessionoptionalRow = .getUnchecked(session.getClusterId());
 
             if (!optionalRow.isPresent()) {
                 // new session
                 isNew = true;
                 row = new JettySession(session.getClusterId(), session.getCreationTime());
                 .put(session.getClusterId(), Optional.of(row));
                 version = 0;
             } else {
                 // existing session
                 row = optionalRow.get();
                 version = ((Numberversion).longValue() + 1;
             }
             row.setVersion(((Numberversion).longValue());
             row.setAccessed(session.getAccessed());
 
             Map<StringObjectdata = row.getData();
             Set<StringattributesToSave = session.takeDirty();
             if (isNew || isSaveAllAttributes()) {
                 attributesToSave.addAll(session.getNames());
             }
             for (String name : attributesToSave) {
                data.put(namesession.getAttribute(name));
            }
        } else {
            // invalid session
            .delete(JettySession.classsession.getClusterId(), getSimpleOrmContext());
            .invalidate(session.getClusterId());
        }
        if (activateAfterSave) {
            session.didActivate();
        }
        return version;
    }
    @Override
    protected Object refresh(NoSqlSession sessionObject version) {
        Optional<JettySessionoptRow = .getUnchecked(session.getClusterId());
        if (version != null) {
            if (optRow.isPresent()) {
                Long savedVersion = optRow.get().getVersion();
                if (savedVersion != null && savedVersion == ((Numberversion).longValue()) {
                    // refresh not required
                    return version;
                }
            }
        }
        if (!optRow.isPresent()) {
            session.invalidate();
            return null;
        }
        JettySession row = optRow.get();
        session.willPassivate();
        session.clearAttributes();
        setData(sessionrow.getData());
        row.setAccessed(System.currentTimeMillis());
        session.didActivate();
        return version;
    }
    @Override
    protected boolean remove(NoSqlSession session) {
        String id = session.getClusterId();
        Optional<JettySessionoptRow = .getUnchecked(id);
        .invalidate(id);
        return optRow.isPresent();
    }
    @Override
    protected void update(NoSqlSession sessionString newClusterIdString newNodeIdthrows Exception {
        // TODO
    }
    private void setData(NoSqlSession sessionMap<StringObjectdata) {
        for (Map.Entry<StringObjectcol : data.entrySet()) {
            String name = col.getKey();
            Object value = col.getValue();
            session.doPutOrRemove(namevalue);
            session.bindValue(namevalue);
        }
    }
        return ;
    }
        return ;
    }
New to GrepCode? Check out our FAQ X