|
| 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.alter; |
| 11 | + |
| 12 | +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; |
| 13 | +import net.sf.jsqlparser.statement.Statement; |
| 14 | +import net.sf.jsqlparser.statement.StatementVisitor; |
| 15 | + |
| 16 | +/** |
| 17 | + * PostgreSQL |
| 18 | + * {@code ALTER CONVERSION name {RENAME TO new_name | OWNER TO role | SET SCHEMA schema}}. Names |
| 19 | + * retain SQL identifier quoting. |
| 20 | + */ |
| 21 | +public class AlterConversion extends ASTNodeAccessImpl implements Statement { |
| 22 | + public enum Action { |
| 23 | + RENAME, OWNER, SET_SCHEMA |
| 24 | + } |
| 25 | + |
| 26 | + private String name; |
| 27 | + private Action action; |
| 28 | + private String newName; |
| 29 | + private String owner; |
| 30 | + private String schemaName; |
| 31 | + |
| 32 | + public String getName() { |
| 33 | + return name; |
| 34 | + } |
| 35 | + |
| 36 | + public void setName(String name) { |
| 37 | + this.name = name; |
| 38 | + } |
| 39 | + |
| 40 | + public AlterConversion withName(String name) { |
| 41 | + setName(name); |
| 42 | + return this; |
| 43 | + } |
| 44 | + |
| 45 | + public Action getAction() { |
| 46 | + return action; |
| 47 | + } |
| 48 | + |
| 49 | + public void setAction(Action action) { |
| 50 | + this.action = action; |
| 51 | + } |
| 52 | + |
| 53 | + public AlterConversion withAction(Action action) { |
| 54 | + setAction(action); |
| 55 | + return this; |
| 56 | + } |
| 57 | + |
| 58 | + public String getNewName() { |
| 59 | + return newName; |
| 60 | + } |
| 61 | + |
| 62 | + public void setNewName(String newName) { |
| 63 | + this.newName = newName; |
| 64 | + } |
| 65 | + |
| 66 | + public AlterConversion withNewName(String newName) { |
| 67 | + setNewName(newName); |
| 68 | + return this; |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * The new owner: a role name, {@code CURRENT_ROLE}, {@code CURRENT_USER} or |
| 73 | + * {@code SESSION_USER}. |
| 74 | + * |
| 75 | + * @return the owner of {@code OWNER TO} |
| 76 | + */ |
| 77 | + public String getOwner() { |
| 78 | + return owner; |
| 79 | + } |
| 80 | + |
| 81 | + public void setOwner(String owner) { |
| 82 | + this.owner = owner; |
| 83 | + } |
| 84 | + |
| 85 | + public AlterConversion withOwner(String owner) { |
| 86 | + setOwner(owner); |
| 87 | + return this; |
| 88 | + } |
| 89 | + |
| 90 | + public String getSchemaName() { |
| 91 | + return schemaName; |
| 92 | + } |
| 93 | + |
| 94 | + public void setSchemaName(String schemaName) { |
| 95 | + this.schemaName = schemaName; |
| 96 | + } |
| 97 | + |
| 98 | + public AlterConversion withSchemaName(String schemaName) { |
| 99 | + setSchemaName(schemaName); |
| 100 | + return this; |
| 101 | + } |
| 102 | + |
| 103 | + public StringBuilder appendTo(StringBuilder builder) { |
| 104 | + builder.append("ALTER CONVERSION ").append(name); |
| 105 | + switch (action) { |
| 106 | + case RENAME: |
| 107 | + builder.append(" RENAME TO ").append(newName); |
| 108 | + break; |
| 109 | + case OWNER: |
| 110 | + builder.append(" OWNER TO ").append(owner); |
| 111 | + break; |
| 112 | + case SET_SCHEMA: |
| 113 | + builder.append(" SET SCHEMA ").append(schemaName); |
| 114 | + break; |
| 115 | + default: |
| 116 | + throw new IllegalStateException("Unknown conversion action: " + action); |
| 117 | + } |
| 118 | + return builder; |
| 119 | + } |
| 120 | + |
| 121 | + @Override |
| 122 | + public String toString() { |
| 123 | + return appendTo(new StringBuilder()).toString(); |
| 124 | + } |
| 125 | + |
| 126 | + @Override |
| 127 | + public <T, S> T accept(StatementVisitor<T> statementVisitor, S context) { |
| 128 | + return statementVisitor.visit(this, context); |
| 129 | + } |
| 130 | +} |
0 commit comments