Debian Codegraph @

src/main/org/h2/command/ddl/RefreshMaterializedView.java

raw
1 /*
2 * Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0,
3 * and the EPL 1.0 (https://h2database.com/html/license.html).
4 * Initial Developer: H2 Group
5 */
6 package org.h2.command.ddl;
7
8 import org.h2.command.CommandInterface;
9 import org.h2.engine.SessionLocal;
10 import org.h2.schema.Schema;
11 import org.h2.table.MaterializedView;
12
13 /**
14 * This class represents the statement REFRESH MATERIALIZED VIEW
15 */
16 public class RefreshMaterializedView extends SchemaOwnerCommand {
17
18 private MaterializedView view;
19
20 public RefreshMaterializedView(SessionLocal session, Schema schema) {
21 super(session, schema);
22 }
23
24 public void setView(MaterializedView view) {
25 this.view = view;
26 }
27
28 @Override
29 long update(Schema schema) {
30 // Re-use logic from the existing code for TRUNCATE and CREATE TABLE
31
32 TruncateTable truncate = new TruncateTable(session);
33 truncate.setTable(view.getUnderlyingTable());
34 truncate.update();
35
36 CreateTable createTable = new CreateTable(session, schema);
37 createTable.setQuery(view.getSelect());
38 createTable.insertAsData(view.getUnderlyingTable());
39 view.setModified();
40 return 0;
41 }
42
43 @Override
44 public int getType() {
45 return CommandInterface.REFRESH_MATERIALIZED_VIEW;
46 }
47
48 }