|
| 1 | +/*- |
| 2 | + * #%L |
| 3 | + * JSQLParser library |
| 4 | + * %% |
| 5 | + * Copyright (C) 2004 - 2026 JSQLParser |
| 6 | + * %% |
| 7 | + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 |
| 8 | + * #L% |
| 9 | + */ |
| 10 | +package net.sf.jsqlparser.statement.create.extension; |
| 11 | + |
| 12 | +import net.sf.jsqlparser.expression.Expression; |
| 13 | +import net.sf.jsqlparser.statement.Statement; |
| 14 | +import net.sf.jsqlparser.statement.StatementVisitor; |
| 15 | + |
| 16 | +/** |
| 17 | + * DuckDB 2.0's {@code CREATE EXTENSION REPOSITORY [IF NOT EXISTS] name [WITH PREFIX prefix]}, which |
| 18 | + * registers a custom repository extensions may be installed from. |
| 19 | + */ |
| 20 | +public class CreateExtensionRepository implements Statement { |
| 21 | + private String name; |
| 22 | + private boolean ifNotExists; |
| 23 | + private Expression prefix; |
| 24 | + |
| 25 | + public String getName() { |
| 26 | + return name; |
| 27 | + } |
| 28 | + |
| 29 | + public void setName(String name) { |
| 30 | + this.name = name; |
| 31 | + } |
| 32 | + |
| 33 | + public CreateExtensionRepository withName(String name) { |
| 34 | + setName(name); |
| 35 | + return this; |
| 36 | + } |
| 37 | + |
| 38 | + public boolean isIfNotExists() { |
| 39 | + return ifNotExists; |
| 40 | + } |
| 41 | + |
| 42 | + public void setIfNotExists(boolean ifNotExists) { |
| 43 | + this.ifNotExists = ifNotExists; |
| 44 | + } |
| 45 | + |
| 46 | + public CreateExtensionRepository withIfNotExists(boolean ifNotExists) { |
| 47 | + setIfNotExists(ifNotExists); |
| 48 | + return this; |
| 49 | + } |
| 50 | + |
| 51 | + public Expression getPrefix() { |
| 52 | + return prefix; |
| 53 | + } |
| 54 | + |
| 55 | + public void setPrefix(Expression prefix) { |
| 56 | + this.prefix = prefix; |
| 57 | + } |
| 58 | + |
| 59 | + public CreateExtensionRepository withPrefix(Expression prefix) { |
| 60 | + setPrefix(prefix); |
| 61 | + return this; |
| 62 | + } |
| 63 | + |
| 64 | + public StringBuilder appendTo(StringBuilder builder) { |
| 65 | + builder.append("CREATE EXTENSION REPOSITORY "); |
| 66 | + if (ifNotExists) { |
| 67 | + builder.append("IF NOT EXISTS "); |
| 68 | + } |
| 69 | + builder.append(name); |
| 70 | + if (prefix != null) { |
| 71 | + builder.append(" WITH PREFIX ").append(prefix); |
| 72 | + } |
| 73 | + return builder; |
| 74 | + } |
| 75 | + |
| 76 | + @Override |
| 77 | + public String toString() { |
| 78 | + return appendTo(new StringBuilder()).toString(); |
| 79 | + } |
| 80 | + |
| 81 | + @Override |
| 82 | + public <T, S> T accept(StatementVisitor<T> statementVisitor, S context) { |
| 83 | + return statementVisitor.visit(this, context); |
| 84 | + } |
| 85 | +} |
0 commit comments