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 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
.protected void
initializeDatabase
(Configuration config) Initialize table state andconfig
from existing database.protected void
Obtain an exclusive lock on the main tables.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) 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, initConnection, initialize, query, queryFunctions, retrieveFuncDescFromVectors, setConnectionOnTables
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, 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:FunctionDatabase
Close down (the connection with) the database- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceFunctionDatabase
- Overrides:
close
in 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:
lockTablesForWrite
in classAbstractSQLFunctionDatabase<WeightedLSHCosineVectorFactory>
- Throws:
SQLException
- if the server reports an error
-
initializeDatabase
Description copied from class:AbstractSQLFunctionDatabase
Initialize table state andconfig
from existing database. NOTE: it is left to specific implementation to override this method to properly initialize defaultconfig.weightfactory
andconfig.idflookup
.- Overrides:
initializeDatabase
in classAbstractSQLFunctionDatabase<WeightedLSHCosineVectorFactory>
- Parameters:
config
- the database configuration- Throws:
SQLException
- if there is a problem opening the database 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<WeightedLSHCosineVectorFactory>
- 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<WeightedLSHCosineVectorFactory>
- 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<WeightedLSHCosineVectorFactory>
- Throws:
SQLException
- if a database error occured
-
storeSignatureRecord
Make sure the vector corresponding to the SignatureRecord is inserted into the vectable- Specified by:
storeSignatureRecord
in 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:
deleteVectors
in 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:
queryNearestVector
in 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: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<WeightedLSHCosineVectorFactory>
- Parameters:
query
- the nearest vector query to perform- Throws:
SQLException
- if there is an error issuing the query
-
queryVectorId
- Specified by:
queryVectorId
in 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:
getUserName
in interfaceFunctionDatabase
- Overrides:
getUserName
in classAbstractSQLFunctionDatabase<WeightedLSHCosineVectorFactory>
- Returns:
- username (being used to establish connection)
-
doQuery
public QueryResponseRecord doQuery(BSimQuery<?> query, Connection c) throws SQLException, LSHException, FunctionDatabase.DatabaseNonFatalException - Overrides:
doQuery
in classAbstractSQLFunctionDatabase<WeightedLSHCosineVectorFactory>
- Throws:
SQLException
LSHException
FunctionDatabase.DatabaseNonFatalException
-
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
-