Skip to content

Commit

Permalink
Ensure that statements belong to the current transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
gartens committed Aug 28, 2024
1 parent 8e640f5 commit 5e3567a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class PIPreparedNamedStatement extends PIPreparedStatement {
@Setter
private PolyImplementation implementation;
@Getter
@Setter
private Statement statement;
private final NamedValueProcessor namedValueProcessor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public void closeResults() {

public abstract void setImplementation( PolyImplementation implementation );

public abstract void setStatement( Statement statement );

public abstract Statement getStatement();

public abstract String getQuery();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
public class PIUnparameterizedStatement extends PIStatement {

private final String query;
@Setter
private Statement statement;
@Setter
private PolyImplementation implementation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.polypheny.db.prisminterface.statements;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
Expand All @@ -28,6 +29,7 @@
import org.polypheny.db.languages.QueryLanguage;
import org.polypheny.db.prisminterface.PIClient;
import org.polypheny.db.prisminterface.PIServiceException;
import org.polypheny.db.transaction.Statement;
import org.polypheny.prism.ExecuteUnparameterizedStatementRequest;
import org.polypheny.prism.PrepareStatementRequest;

Expand All @@ -36,8 +38,8 @@ public class StatementManager {

private final AtomicInteger statementIdGenerator;
private final PIClient client;
private ConcurrentHashMap<Integer, PIStatement> openStatements;
private ConcurrentHashMap<Integer, PIUnparameterizedStatementBatch> openUnparameterizedBatches;
private final Map<Integer, PIStatement> openStatements;
private final Map<Integer, PIUnparameterizedStatementBatch> openUnparameterizedBatches;


public StatementManager( PIClient client ) {
Expand Down Expand Up @@ -190,25 +192,29 @@ public PIStatement getStatement( int statementId ) {
if ( statement == null ) {
throw new PIServiceException( "A statement with id " + statementId + " does not exist for that client" );
}
Statement s = statement.getStatement();
if ( s != null && s.getTransaction().getId() != client.getOrCreateNewTransaction().getId() ) {
statement.setStatement( client.getCurrentTransaction().createStatement() );
}
return statement;
}


public PIPreparedNamedStatement getNamedPreparedStatement( int statementId ) throws PIServiceException {
PIStatement statement = getStatement( statementId );
if ( !(statement instanceof PIPreparedNamedStatement) ) {
if ( !(statement instanceof PIPreparedNamedStatement prepared) ) {
throw new PIServiceException( "A named prepared statement with id " + statementId + " does not exist for that client" );
}
return (PIPreparedNamedStatement) statement;
return prepared;
}


public PIPreparedIndexedStatement getIndexedPreparedStatement( int statementId ) throws PIServiceException {
PIStatement statement = getStatement( statementId );
if ( !(statement instanceof PIPreparedIndexedStatement) ) {
if ( !(statement instanceof PIPreparedIndexedStatement prepared) ) {
throw new PIServiceException( "A prepared indexed statement with id " + statementId + " does not exist for that client" );
}
return (PIPreparedIndexedStatement) statement;
return prepared;
}


Expand Down

0 comments on commit 5e3567a

Please sign in to comment.