Search in sources :

Example 1 with LongValueHashMap

use of org.hsqldb_voltpatches.lib.LongValueHashMap 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 LongValueHashMap

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

the class StatementManager method registerStatement.

/**
     * Registers a compiled statement to be managed.
     *
     * The only caller should be a Session that is attempting to prepare
     * a statement for the first time or process a statement that has been
     * invalidated due to DDL changes.
     *
     * @param csid existing id or negative if the statement is not yet managed
     * @param cs The CompiledStatement to add
     * @return The compiled statement id assigned to the CompiledStatement
     *  object
     */
private long registerStatement(long csid, Statement cs) {
    if (csid < 0) {
        csid = nextID();
        int schemaid = cs.getSchemaName().hashCode();
        LongValueHashMap sqlMap = (LongValueHashMap) schemaMap.get(schemaid);
        if (sqlMap == null) {
            sqlMap = new LongValueHashMap();
            schemaMap.put(schemaid, sqlMap);
        }
        sqlMap.put(cs.getSQL(), csid);
        sqlLookup.put(csid, cs.getSQL());
    }
    cs.setID(csid);
    csidMap.put(csid, cs);
    return csid;
}
Also used : LongValueHashMap(org.hsqldb_voltpatches.lib.LongValueHashMap)

Example 3 with LongValueHashMap

use of org.hsqldb_voltpatches.lib.LongValueHashMap 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

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