Class PostgresFunctionDatabase
java.lang.Object
ghidra.features.bsim.query.client.AbstractSQLFunctionDatabase<WeightedLSHCosineVectorFactory>
ghidra.features.bsim.query.client.PostgresFunctionDatabase
- All Implemented Interfaces:
FunctionDatabase,SQLFunctionDatabase,AutoCloseable
public final class PostgresFunctionDatabase
extends AbstractSQLFunctionDatabase<WeightedLSHCosineVectorFactory>
Defines the BSim
FunctionDatabase backed by a PostgreSQL database.
Simple, one-column tables that only contain string data use the
SQLStringTable class and are defined in this class. More complex
tables are defined in their own classes in the
ghidra.features.bsim.query.client.tables package.-
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
FieldsFields inherited from class ghidra.features.bsim.query.client.AbstractSQLFunctionDatabase
ds, JAVA_TIME_FORMAT, SQL_TIME_FORMAT, supportedLayoutVersion, vectorFactory -
Constructor Summary
Constructors -
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.protected voidinitializeDatabase(Configuration config) Initialize table state andconfigfrom existing database.protected voidObtain an exclusive lock on the main tables.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) protected 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, initConnection, initialize, query, queryFunctions, retrieveFuncDescFromVectors, setConnectionOnTablesMethods 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, getOverviewFunctionsPerStage, getQueriedFunctionsPerStage, isPasswordChangeAllowed
-
Field Details
-
LAYOUT_VERSION
public static final int LAYOUT_VERSION- See Also:
-
-
Constructor Details
-
PostgresFunctionDatabase
-
-
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<WeightedLSHCosineVectorFactory>
-
lockTablesForWrite
Obtain an exclusive lock on the main tables. To be used when INSERTING, DELETING, or UPDATING to prevent concurrent changes to the tables.- Overrides:
lockTablesForWritein classAbstractSQLFunctionDatabase<WeightedLSHCosineVectorFactory>- Throws:
SQLException- if the server reports an error
-
initializeDatabase
Description copied from class:AbstractSQLFunctionDatabaseInitialize table state andconfigfrom existing database. NOTE: it is left to specific implementation to override this method to properly initialize defaultconfig.weightfactoryandconfig.idflookup.- Overrides:
initializeDatabasein classAbstractSQLFunctionDatabase<WeightedLSHCosineVectorFactory>- Parameters:
config- the database configuration- Throws:
SQLException- if there is a problem opening the database 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<WeightedLSHCosineVectorFactory>- 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<WeightedLSHCosineVectorFactory>- 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<WeightedLSHCosineVectorFactory>- Throws:
SQLException- if a database error occured
-
storeSignatureRecord
Make sure the vector corresponding to the SignatureRecord is inserted into the vectable- Specified by:
storeSignatureRecordin classAbstractSQLFunctionDatabase<WeightedLSHCosineVectorFactory>- Parameters:
sigrec- is the SignatureRecord- Returns:
- the computed id of the vector
- Throws:
SQLException- if there is a problem creating or executing the query
-
deleteVectors
Low level count decrement of a vector record from vectable, if count reaches zero, the record is deleted- Specified by:
deleteVectorsin classAbstractSQLFunctionDatabase<WeightedLSHCosineVectorFactory>- 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
-
queryNearestVector
protected int queryNearestVector(List<VectorResult> resultset, LSHVector vec, double simthresh, double sigthresh, int max) throws SQLException - Specified by:
queryNearestVectorin classAbstractSQLFunctionDatabase<WeightedLSHCosineVectorFactory>- 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<WeightedLSHCosineVectorFactory>- Parameters:
query- the nearest vector query to perform- Throws:
SQLException- if there is an error issuing the query
-
queryVectorId
- Specified by:
queryVectorIdin classAbstractSQLFunctionDatabase<WeightedLSHCosineVectorFactory>- Parameters:
id- the vector id- Returns:
- the vector result
- Throws:
SQLException- if there is a problem creating or executing the query
-
getUserName
- Specified by:
getUserNamein interfaceFunctionDatabase- Overrides:
getUserNamein classAbstractSQLFunctionDatabase<WeightedLSHCosineVectorFactory>- Returns:
- username (being used to establish connection)
-
doQuery
public QueryResponseRecord doQuery(BSimQuery<?> query, Connection c) throws SQLException, LSHException, FunctionDatabase.DatabaseNonFatalException - Overrides:
doQueryin classAbstractSQLFunctionDatabase<WeightedLSHCosineVectorFactory>- Throws:
SQLExceptionLSHExceptionFunctionDatabase.DatabaseNonFatalException
-
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
-