Search in sources :

Example 1 with LongKeyIntValueHashMap

use of org.hsqldb_voltpatches.lib.LongKeyIntValueHashMap in project voltdb by VoltDB.

the class StatementManager method freeStatement.

/**
     * Removes one (or all) of the links between a session and a compiled
     * statement. If the statement is not linked with any other session, it is
     * removed from management.
     *
     * @param csid the compiled statment identifier
     * @param sessionID the session identifier
     * @param freeAll if true, remove all links to the session
     */
synchronized void freeStatement(long csid, long sessionID, boolean freeAll) {
    if (csid == -1) {
        // statement was never added
        return;
    }
    LongKeyIntValueHashMap scsMap = (LongKeyIntValueHashMap) sessionUseMap.get(sessionID);
    if (scsMap == null) {
        // statement already removed due to invalidation
        return;
    }
    int sessionUseCount = scsMap.get(csid, 0);
    if (sessionUseCount == 0) {
    // statement already removed due to invalidation
    } else if (sessionUseCount == 1 || freeAll) {
        scsMap.remove(csid);
        int usecount = useMap.get(csid, 0);
        if (usecount == 0) {
        // statement already removed due to invalidation
        } else if (usecount == 1) {
            Statement cs = (Statement) csidMap.remove(csid);
            if (cs != null) {
                int schemaid = cs.getSchemaName().hashCode();
                LongValueHashMap sqlMap = (LongValueHashMap) schemaMap.get(schemaid);
                String sql = (String) sqlLookup.remove(csid);
                sqlMap.remove(sql);
            }
            useMap.remove(csid);
        } else {
            useMap.put(csid, usecount - 1);
        }
    } else {
        scsMap.put(csid, sessionUseCount - 1);
    }
}
Also used : LongKeyIntValueHashMap(org.hsqldb_voltpatches.lib.LongKeyIntValueHashMap) LongValueHashMap(org.hsqldb_voltpatches.lib.LongValueHashMap)

Example 2 with LongKeyIntValueHashMap

use of org.hsqldb_voltpatches.lib.LongKeyIntValueHashMap in project voltdb by VoltDB.

the class StatementManager method linkSession.

/**
     * Links a session with a registered compiled statement. If this session has
     * not already been linked with the given statement, then the statement use
     * count is incremented.
     *
     * @param csid the compiled statement identifier
     * @param sessionID the session identifier
     */
private void linkSession(long csid, long sessionID) {
    LongKeyIntValueHashMap scsMap;
    scsMap = (LongKeyIntValueHashMap) sessionUseMap.get(sessionID);
    if (scsMap == null) {
        scsMap = new LongKeyIntValueHashMap();
        sessionUseMap.put(sessionID, scsMap);
    }
    int count = scsMap.get(csid, 0);
    scsMap.put(csid, count + 1);
    if (count == 0) {
        useMap.put(csid, useMap.get(csid, 0) + 1);
    }
}
Also used : LongKeyIntValueHashMap(org.hsqldb_voltpatches.lib.LongKeyIntValueHashMap)

Example 3 with LongKeyIntValueHashMap

use of org.hsqldb_voltpatches.lib.LongKeyIntValueHashMap in project voltdb by VoltDB.

the class StatementManager method removeSession.

/**
     * Releases the link betwen the session and all compiled statement objects
     * it is linked to. If any such statement is not linked with any other
     * session, it is removed from management.
     *
     * @param sessionID the session identifier
     */
synchronized void removeSession(long sessionID) {
    LongKeyIntValueHashMap scsMap;
    long csid;
    Iterator i;
    scsMap = (LongKeyIntValueHashMap) sessionUseMap.remove(sessionID);
    if (scsMap == null) {
        return;
    }
    i = scsMap.keySet().iterator();
    while (i.hasNext()) {
        csid = i.nextLong();
        int usecount = useMap.get(csid, 1) - 1;
        if (usecount == 0) {
            Statement cs = (Statement) csidMap.remove(csid);
            if (cs != null) {
                int schemaid = cs.getSchemaName().hashCode();
                LongValueHashMap sqlMap = (LongValueHashMap) schemaMap.get(schemaid);
                String sql = (String) sqlLookup.remove(csid);
                sqlMap.remove(sql);
            }
            useMap.remove(csid);
        } else {
            useMap.put(csid, usecount);
        }
    }
}
Also used : LongKeyIntValueHashMap(org.hsqldb_voltpatches.lib.LongKeyIntValueHashMap) LongValueHashMap(org.hsqldb_voltpatches.lib.LongValueHashMap) Iterator(org.hsqldb_voltpatches.lib.Iterator)

Aggregations

LongKeyIntValueHashMap (org.hsqldb_voltpatches.lib.LongKeyIntValueHashMap)3 LongValueHashMap (org.hsqldb_voltpatches.lib.LongValueHashMap)2 Iterator (org.hsqldb_voltpatches.lib.Iterator)1