| 43 | import io.crate.types.DataTypes; |
| 44 | |
| 45 | public class SwapTablePlan implements Plan { |
| 46 | |
| 47 | private final AnalyzedSwapTable swapTable; |
| 48 | |
| 49 | SwapTablePlan(AnalyzedSwapTable swapTable) { |
| 50 | this.swapTable = swapTable; |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public StatementType type() { |
| 55 | return StatementType.DDL; |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public void executeOrFail(DependencyCarrier dependencies, |
| 60 | PlannerContext plannerContext, |
| 61 | RowConsumer consumer, |
| 62 | Row params, |
| 63 | SubQueryResults subQueryResults) { |
| 64 | boolean dropSource = Objects.requireNonNull( |
| 65 | DataTypes.BOOLEAN.sanitizeValue(SymbolEvaluator.evaluate( |
| 66 | plannerContext.transactionContext(), |
| 67 | dependencies.nodeContext(), |
| 68 | swapTable.dropSource(), |
| 69 | params, |
| 70 | subQueryResults |
| 71 | )), SwapTableAnalyzer.DROP_SOURCE + " option must be true or false, not null"); |
| 72 | |
| 73 | RelationName source = swapTable.source().ident(); |
| 74 | SwapRelationsRequest request = new SwapRelationsRequest( |
| 75 | Collections.singletonList(new RelationNameSwap(source, swapTable.target().ident())), |
| 76 | dropSource ? Collections.singletonList(source) : emptyList() |
| 77 | ); |
| 78 | OneRowActionListener<AcknowledgedResponse> listener = new OneRowActionListener<>( |
| 79 | consumer, |
| 80 | r -> r.isAcknowledged() ? new Row1(1L) : new Row1(0L) |
| 81 | ); |
| 82 | dependencies.client().execute(TransportSwapRelations.ACTION, request).whenComplete(listener); |
| 83 | } |
| 84 | } |
nothing calls this directly
no outgoing calls
no test coverage detected