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
-
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
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
static final int
Fields inherited from class ghidra.features.bsim.query.client.AbstractSQLFunctionDatabase
ds, JAVA_TIME_FORMAT, SQL_TIME_FORMAT, supportedLayoutVersion, vectorFactory
-
Constructor Summary
ConstructorsConstructorDescriptionH2FileFunctionDatabase
(BSimServerInfo serverInfo) Constructor used to connect to an existing H2 file databaseH2FileFunctionDatabase
(URL bsimURL) Constructor used to connect to an existing H2 file database -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close down (the connection with) the databaseprotected 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 deleteddoQuery
(BSimQuery<?> query, Connection c) protected void
Drop this databaseformatBitAndSQL
(String v1, String v2) Generate SQL bitwise-and syntax for use in database query WHERE clauseprotected void
Generate new empty database which corresponds toAbstractSQLFunctionDatabase.ds
.int
Get the maximum number of functions to be queried per staged query when performing an overview query.int
Get the maximum number of functions to be queried per staged query when searching for similar functions.protected Connection
Establish PostgreSQL DB pooledConnection
for this instance.int
queryFunctions
(QueryNearest query, BSimSqlClause filter, ResponseNearest response, DescriptionManager descMgr, Iterator<FunctionDescription> iter) protected void
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) Create vector map which maps vector ID toVectorStoreEntry
protected void
protected long
storeSignatureRecord
(SignatureRecord sigrec) Make sure the vector corresponding to the SignatureRecord is inserted into the vectableMethods 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:
-
QUERY_FUNCS_PER_STAGE
public static final int QUERY_FUNCS_PER_STAGE- See Also:
-
LAYOUT_VERSION
public static final int LAYOUT_VERSION- See Also:
-
-
Constructor Details
-
H2FileFunctionDatabase
Constructor used to connect to an existing H2 file database- Parameters:
bsimURL
- local file URL for H2 database
-
H2FileFunctionDatabase
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 interfaceAutoCloseable
- Specified by:
close
in interfaceFunctionDatabase
- Overrides:
close
in classAbstractSQLFunctionDatabase<Base64VectorFactory>
-
setConnectionOnTables
- Overrides:
setConnectionOnTables
in classAbstractSQLFunctionDatabase<Base64VectorFactory>
-
initConnection
Description copied from class:AbstractSQLFunctionDatabase
Establish PostgreSQL DB pooledConnection
for this instance.- Overrides:
initConnection
in classAbstractSQLFunctionDatabase<Base64VectorFactory>
- Returns:
- database connection
- Throws:
SQLException
- if error occurs obtaining connection
-
generateRawDatabase
Description copied from class:AbstractSQLFunctionDatabase
Generate new empty database which corresponds toAbstractSQLFunctionDatabase.ds
. A new connection may be used to the default database so that a new database may be created.- Specified by:
generateRawDatabase
in classAbstractSQLFunctionDatabase<Base64VectorFactory>
- Throws:
SQLException
- if an error occurs while creating the database
-
createDatabase
Description copied from class:AbstractSQLFunctionDatabase
Generate tables and initialize state for a new database.- Overrides:
createDatabase
in classAbstractSQLFunctionDatabase<Base64VectorFactory>
- Parameters:
config
- the database configuration- Throws:
SQLException
- if there is aproblem opening a connectino to the database
-
dropDatabase
Description copied from class:AbstractSQLFunctionDatabase
Drop this database- Specified by:
dropDatabase
in classAbstractSQLFunctionDatabase<Base64VectorFactory>
- Throws:
SQLException
- if a database error occured
-
readVectorMap
Create vector map which maps vector ID toVectorStoreEntry
- Returns:
- vector map
- Throws:
SQLException
- if error occurs while reading map data
-
deleteVectors
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 classAbstractSQLFunctionDatabase<Base64VectorFactory>
- Parameters:
id
- vector row IDcountdiff
- 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 classAbstractSQLFunctionDatabase<Base64VectorFactory>
- Throws:
SQLException
LSHException
FunctionDatabase.DatabaseNonFatalException
-
queryVectorId
- Specified by:
queryVectorId
in classAbstractSQLFunctionDatabase<Base64VectorFactory>
- Parameters:
id
- the vector id- Returns:
- the vector result
- Throws:
SQLException
- if there is a problem creating or executing the query
-
storeSignatureRecord
Description copied from class:AbstractSQLFunctionDatabase
Make sure the vector corresponding to the SignatureRecord is inserted into the vectable- Specified by:
storeSignatureRecord
in classAbstractSQLFunctionDatabase<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 classAbstractSQLFunctionDatabase<Base64VectorFactory>
- Parameters:
resultset
- the list of result set objects to populatevec
- the vector containing the saveSQL query statementsimthresh
- the similarity thresholdsigthresh
- the confidence thresholdmax
- 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
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 classAbstractSQLFunctionDatabase<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 classAbstractSQLFunctionDatabase<Base64VectorFactory>
- Parameters:
query
- the query to executefilter
- the function filterresponse
- the response objectdescMgr
- the executable descriptoriter
- the function iterator- Returns:
- the number of unique results found
- Throws:
SQLException
- if there is an error issuing the queryLSHException
- if there is a problem creating executable records
-
formatBitAndSQL
Description copied from interface:SQLFunctionDatabase
Generate SQL bitwise-and syntax for use in database query WHERE clause- Parameters:
v1
- first valuev2
- 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
.
-