Package ghidra.features.bsim.query.file

# Class H2FileFunctionDatabase

java.lang.Object
ghidra.features.bsim.query.client.AbstractSQLFunctionDatabase<Base64VectorFactory>
ghidra.features.bsim.query.file.H2FileFunctionDatabase

All Implemented Interfaces:
  `FunctionDatabase`, `SQLFunctionDatabase`, `AutoCloseable`

public class H2FileFunctionDatabase extends AbstractSQLFunctionDatabase<Base64VectorFactory>

- ## Nested Class Summary

  ## Nested classes/interfaces inherited from interface ghidra.features.bsim.query.FunctionDatabase

  `FunctionDatabase.BSimError, FunctionDatabase.ConnectionType, FunctionDatabase.DatabaseNonFatalException, FunctionDatabase.ErrorCategory, FunctionDatabase.Status`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `LAYOUT_VERSION`
  `static final int`
  `OVERVIEW_FUNCS_PER_STAGE`
  `static final int`
  `QUERY_FUNCS_PER_STAGE`

  ### Fields inherited from class ghidra.features.bsim.query.client.AbstractSQLFunctionDatabase

  `ds, JAVA_TIME_FORMAT, SQL_TIME_FORMAT, supportedLayoutVersion, vectorFactory`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `H2FileFunctionDatabase(BSimServerInfo serverInfo)`
  Constructor used to connect to an existing H2 file database
  `H2FileFunctionDatabase(URL bsimURL)`
  Constructor used to connect to an existing H2 file database

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `close()`
  Close down (the connection with) the database
  `protected void`
  `createDatabase(Configuration config)`
  Generate tables and initialize state for a new database.
  `protected int`
  `deleteVectors(long id, int countdiff)`
  Low level count decrement of a vector record from vectable, if count reaches zero, the record is deleted
  `QueryResponseRecord`
  `doQuery(BSimQuery<?> query, Connection c)`
  `protected void`
  `dropDatabase()`
  Drop this database
  `String`
  `formatBitAndSQL(String v1, String v2)`
  Generate SQL bitwise-and syntax for use in database query WHERE clause
  `protected void`
  `generateRawDatabase()`
  Generate new empty database which corresponds to `AbstractSQLFunctionDatabase.ds`.
  `int`
  `getOverviewFunctionsPerStage()`
  Get the maximum number of functions to be queried per staged query when performing an overview query.
  `int`
  `getQueriedFunctionsPerStage()`
  Get the maximum number of functions to be queried per staged query when searching for similar functions.
  `protected Connection`
  `initConnection()`
  Establish PostgreSQL DB pooled `Connection` for this instance.
  `int`
  `queryFunctions(QueryNearest query, BSimSqlClause filter, ResponseNearest response, DescriptionManager descMgr, Iterator<FunctionDescription> iter)`
  `protected void`
  `queryNearestVector(QueryNearestVector query)`
  Perform nearest vector query based upon specified query which contains response record which should be filled-in with search results.
  `protected int`
  `queryNearestVector(List<VectorResult> resultset, LSHVector vec, double simthresh, double sigthresh, int max)`
  `protected VectorResult`
  `queryVectorId(long id)`
  `Map<Long,VectorStoreEntry>`
  `readVectorMap()`
  Create vector map which maps vector ID to `VectorStoreEntry`
  `protected void`
  `setConnectionOnTables(Connection db)`
  `protected long`
  `storeSignatureRecord(SignatureRecord sigrec)`
  Make sure the vector corresponding to the SignatureRecord is inserted into the vectable

  ### Methods inherited from class ghidra.features.bsim.query.client.AbstractSQLFunctionDatabase

  `appendEscapedLiteral, beginTransaction, closing, compareLayout, convertDescriptionRows, endTransaction, getConnectionType, getFunctionTags, getInfo, getLastError, getLSHVectorFactory, getServerInfo, getStatus, getURLString, getUserName, initialize, initializeDatabase, lockTablesForWrite, query, retrieveFuncDescFromVectors`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface ghidra.features.bsim.query.FunctionDatabase

  `changePassword, isPasswordChangeAllowed`

- ## Field Details

  - ### OVERVIEW_FUNCS_PER_STAGE

    public static final int OVERVIEW_FUNCS_PER_STAGE
    See Also:
      - Constant Field Values

  - ### QUERY_FUNCS_PER_STAGE

    public static final int QUERY_FUNCS_PER_STAGE
    See Also:
      - Constant Field Values

  - ### LAYOUT_VERSION

    public static final int LAYOUT_VERSION
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### H2FileFunctionDatabase

    public H2FileFunctionDatabase(URL bsimURL)
    Constructor used to connect to an existing H2 file database
    Parameters:
      `bsimURL` - local file URL for H2 database

  - ### H2FileFunctionDatabase

    public H2FileFunctionDatabase(BSimServerInfo serverInfo)
    Constructor used to connect to an existing H2 file database
    Parameters:
      `serverInfo` - local file info for H2 database

- ## Method Details

  - ### close

    public void close()
    Description copied from interface: `FunctionDatabase`
    Close down (the connection with) the database
    Specified by:
      `close` in interface `AutoCloseable`
    Specified by:
      `close` in interface `FunctionDatabase`
    Overrides:
      `close` in class `AbstractSQLFunctionDatabase<Base64VectorFactory>`

  - ### setConnectionOnTables

    protected void setConnectionOnTables(Connection db)
    Overrides:
      `setConnectionOnTables` in class `AbstractSQLFunctionDatabase<Base64VectorFactory>`

  - ### initConnection

    protected Connection initConnection() throws SQLException
    Description copied from class: `AbstractSQLFunctionDatabase`
    Establish PostgreSQL DB pooled `Connection` for this instance.
    Overrides:
      `initConnection` in class `AbstractSQLFunctionDatabase<Base64VectorFactory>`
    Returns:
      database connection
    Throws:
      `SQLException` - if error occurs obtaining connection

  - ### generateRawDatabase

    protected void generateRawDatabase() throws SQLException
    Description copied from class: `AbstractSQLFunctionDatabase`
    Generate new empty database which corresponds to `AbstractSQLFunctionDatabase.ds`. A new connection may be used to the default database so that a new database may be created.
    Specified by:
      `generateRawDatabase` in class `AbstractSQLFunctionDatabase<Base64VectorFactory>`
    Throws:
      `SQLException` - if an error occurs while creating the database

  - ### createDatabase

    protected void createDatabase(Configuration config) throws SQLException
    Description copied from class: `AbstractSQLFunctionDatabase`
    Generate tables and initialize state for a new database.
    Overrides:
      `createDatabase` in class `AbstractSQLFunctionDatabase<Base64VectorFactory>`
    Parameters:
      `config` - the database configuration
    Throws:
      `SQLException` - if there is aproblem opening a connectino to the database

  - ### dropDatabase

    protected void dropDatabase() throws SQLException
    Description copied from class: `AbstractSQLFunctionDatabase`
    Drop this database
    Specified by:
      `dropDatabase` in class `AbstractSQLFunctionDatabase<Base64VectorFactory>`
    Throws:
      `SQLException` - if a database error occured

  - ### readVectorMap

    public Map<Long,VectorStoreEntry> readVectorMap() throws SQLException
    Create vector map which maps vector ID to `VectorStoreEntry`
    Returns:
      vector map
    Throws:
      `SQLException` - if error occurs while reading map data

  - ### deleteVectors

    protected int deleteVectors(long id, int countdiff) throws SQLException
    Description copied from class: `AbstractSQLFunctionDatabase`
    Low level count decrement of a vector record from vectable, if count reaches zero, the record is deleted
    Specified by:
      `deleteVectors` in class `AbstractSQLFunctionDatabase<Base64VectorFactory>`
    Parameters:
      `id` - vector row ID
      `countdiff` - the amount to subtract from count
    Returns:
      0 if decrement short of 0, return 1 if record was removed, return -1 if there was a problem
    Throws:
      `SQLException` - if there is a problem creating or executing the query

  - ### doQuery

    public QueryResponseRecord doQuery(BSimQuery<?> query, Connection c) throws SQLException, LSHException, FunctionDatabase.DatabaseNonFatalException
    Overrides:
      `doQuery` in class `AbstractSQLFunctionDatabase<Base64VectorFactory>`
    Throws:
      `SQLException`
      `LSHException`
      `FunctionDatabase.DatabaseNonFatalException`

  - ### queryVectorId

    protected VectorResult queryVectorId(long id) throws SQLException
    Specified by:
      `queryVectorId` in class `AbstractSQLFunctionDatabase<Base64VectorFactory>`
    Parameters:
      `id` - the vector id
    Returns:
      the vector result
    Throws:
      `SQLException` - if there is a problem creating or executing the query

  - ### storeSignatureRecord

    protected long storeSignatureRecord(SignatureRecord sigrec) throws SQLException
    Description copied from class: `AbstractSQLFunctionDatabase`
    Make sure the vector corresponding to the SignatureRecord is inserted into the vectable
    Specified by:
      `storeSignatureRecord` in class `AbstractSQLFunctionDatabase<Base64VectorFactory>`
    Parameters:
      `sigrec` - is the SignatureRecord
    Returns:
      the computed id of the vector
    Throws:
      `SQLException` - if there is a problem creating or executing the query

  - ### queryNearestVector

    protected int queryNearestVector(List<VectorResult> resultset, LSHVector vec, double simthresh, double sigthresh, int max) throws SQLException
    Specified by:
      `queryNearestVector` in class `AbstractSQLFunctionDatabase<Base64VectorFactory>`
    Parameters:
      `resultset` - the list of result set objects to populate
      `vec` - the vector containing the saveSQL query statement
      `simthresh` - the similarity threshold
      `sigthresh` - the confidence threshold
      `max` - the max number of results to return
    Returns:
      the number of results returned
    Throws:
      `SQLException` - if there is a problem creating or executing the query

  - ### queryNearestVector

    protected void queryNearestVector(QueryNearestVector query) throws SQLException
    Description copied from class: `AbstractSQLFunctionDatabase`
    Perform nearest vector query based upon specified query which contains response record which should be filled-in with search results.
    Specified by:
      `queryNearestVector` in class `AbstractSQLFunctionDatabase<Base64VectorFactory>`
    Parameters:
      `query` - the nearest vector query to perform
    Throws:
      `SQLException` - if there is an error issuing the query

  - ### queryFunctions

    public int queryFunctions(QueryNearest query, BSimSqlClause filter, ResponseNearest response, DescriptionManager descMgr, Iterator<FunctionDescription> iter) throws SQLException, LSHException
    Overrides:
      `queryFunctions` in class `AbstractSQLFunctionDatabase<Base64VectorFactory>`
    Parameters:
      `query` - the query to execute
      `filter` - the function filter
      `response` - the response object
      `descMgr` - the executable descriptor
      `iter` - the function iterator
    Returns:
      the number of unique results found
    Throws:
      `SQLException` - if there is an error issuing the query
      `LSHException` - if there is a problem creating executable records

  - ### formatBitAndSQL

    public String formatBitAndSQL(String v1, String v2)
    Description copied from interface: `SQLFunctionDatabase`
    Generate SQL bitwise-and syntax for use in database query WHERE clause
    Parameters:
      `v1` - first value
      `v2` - second value
    Returns:
      SQL

  - ### getQueriedFunctionsPerStage

    public int getQueriedFunctionsPerStage()
    Description copied from interface: `FunctionDatabase`
    Get the maximum number of functions to be queried per staged query when searching for similar functions.
    Returns:
      maximum number of functions to be queried per staged query, or 0 for default which is generally ten (10) per stage. See `SFQueryInfo.DEFAULT_QUERIES_PER_STAGE`.

  - ### getOverviewFunctionsPerStage

    public int getOverviewFunctionsPerStage()
    Description copied from interface: `FunctionDatabase`
    Get the maximum number of functions to be queried per staged query when performing an overview query.
    Returns:
      maximum number of functions to be queried per staged query, or 0 for default which is generally ten (10) per stage. See `SFOverviewInfo.DEFAULT_QUERIES_PER_STAGE`.