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 intstatic final intstatic final intFields 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 TypeMethodDescriptionvoidclose()Close down (the connection with) the databaseprotected voidcreateDatabase(Configuration config) Generate tables and initialize state for a new database.protected intdeleteVectors(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 voidDrop this databaseformatBitAndSQL(String v1, String v2) Generate SQL bitwise-and syntax for use in database query WHERE clauseprotected voidGenerate new empty database which corresponds toAbstractSQLFunctionDatabase.ds.intGet the maximum number of functions to be queried per staged query when performing an overview query.intGet the maximum number of functions to be queried per staged query when searching for similar functions.protected ConnectionEstablish PostgreSQL DB pooledConnectionfor this instance.intqueryFunctions(QueryNearest query, BSimSqlClause filter, ResponseNearest response, DescriptionManager descMgr, Iterator<FunctionDescription> iter) protected voidPerform nearest vector query based upon specified query which contains response record which should be filled-in with search results.protected intqueryNearestVector(List<VectorResult> resultset, LSHVector vec, double simthresh, double sigthresh, int max) protected VectorResultqueryVectorId(long id) Create vector map which maps vector ID toVectorStoreEntryprotected voidprotected longstoreSignatureRecord(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, retrieveFuncDescFromVectorsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:FunctionDatabaseClose down (the connection with) the database- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceFunctionDatabase- Overrides:
closein classAbstractSQLFunctionDatabase<Base64VectorFactory>
-
setConnectionOnTables
- Overrides:
setConnectionOnTablesin classAbstractSQLFunctionDatabase<Base64VectorFactory>
-
initConnection
Description copied from class:AbstractSQLFunctionDatabaseEstablish PostgreSQL DB pooledConnectionfor this instance.- Overrides:
initConnectionin classAbstractSQLFunctionDatabase<Base64VectorFactory>- Returns:
- database connection
- Throws:
SQLException- if error occurs obtaining connection
-
generateRawDatabase
Description copied from class:AbstractSQLFunctionDatabaseGenerate 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:
generateRawDatabasein classAbstractSQLFunctionDatabase<Base64VectorFactory>- Throws:
SQLException- if an error occurs while creating the database
-
createDatabase
Description copied from class:AbstractSQLFunctionDatabaseGenerate tables and initialize state for a new database.- Overrides:
createDatabasein classAbstractSQLFunctionDatabase<Base64VectorFactory>- Parameters:
config- the database configuration- Throws:
SQLException- if there is aproblem opening a connectino to the database
-
dropDatabase
Description copied from class:AbstractSQLFunctionDatabaseDrop this database- Specified by:
dropDatabasein 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:AbstractSQLFunctionDatabaseLow level count decrement of a vector record from vectable, if count reaches zero, the record is deleted- Specified by:
deleteVectorsin 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:
doQueryin classAbstractSQLFunctionDatabase<Base64VectorFactory>- Throws:
SQLExceptionLSHExceptionFunctionDatabase.DatabaseNonFatalException
-
queryVectorId
- Specified by:
queryVectorIdin 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:AbstractSQLFunctionDatabaseMake sure the vector corresponding to the SignatureRecord is inserted into the vectable- Specified by:
storeSignatureRecordin 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:
queryNearestVectorin 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:AbstractSQLFunctionDatabasePerform nearest vector query based upon specified query which contains response record which should be filled-in with search results.- Specified by:
queryNearestVectorin 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:
queryFunctionsin 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:SQLFunctionDatabaseGenerate 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:FunctionDatabaseGet 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:FunctionDatabaseGet 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.
-