Search in sources :

Example 1 with Truncate

use of net.sf.jsqlparser.statement.truncate.Truncate in project herddb by diennea.

the class SQLPlanner method plan.

@Override
public ExecutionPlan plan(String defaultTableSpace, net.sf.jsqlparser.statement.Statement stmt, boolean scan, boolean returnValues, int maxRows) {
    verifyJdbcParametersIndexes(stmt);
    ExecutionPlan result;
    if (stmt instanceof CreateTable) {
        result = ExecutionPlan.simple(buildCreateTableStatement(defaultTableSpace, (CreateTable) stmt));
    } else if (stmt instanceof CreateIndex) {
        result = ExecutionPlan.simple(buildCreateIndexStatement(defaultTableSpace, (CreateIndex) stmt));
    } else if (stmt instanceof Insert) {
        result = buildInsertStatement(defaultTableSpace, (Insert) stmt, returnValues);
    } else if (stmt instanceof Delete) {
        result = buildDeleteStatement(defaultTableSpace, (Delete) stmt, returnValues);
    } else if (stmt instanceof Update) {
        result = buildUpdateStatement(defaultTableSpace, (Update) stmt, returnValues);
    } else if (stmt instanceof Select) {
        result = buildSelectStatement(defaultTableSpace, (Select) stmt, scan, maxRows);
    } else if (stmt instanceof Execute) {
        result = ExecutionPlan.simple(buildExecuteStatement(defaultTableSpace, (Execute) stmt));
    } else if (stmt instanceof Alter) {
        result = ExecutionPlan.simple(buildAlterStatement(defaultTableSpace, (Alter) stmt));
    } else if (stmt instanceof Drop) {
        result = ExecutionPlan.simple(buildDropStatement(defaultTableSpace, (Drop) stmt));
    } else if (stmt instanceof Truncate) {
        result = ExecutionPlan.simple(buildTruncateStatement(defaultTableSpace, (Truncate) stmt));
    } else {
        return null;
    }
    return result;
}
Also used : Delete(net.sf.jsqlparser.statement.delete.Delete) Alter(net.sf.jsqlparser.statement.alter.Alter) ExecutionPlan(herddb.model.ExecutionPlan) CreateIndex(net.sf.jsqlparser.statement.create.index.CreateIndex) Execute(net.sf.jsqlparser.statement.execute.Execute) CreateTable(net.sf.jsqlparser.statement.create.table.CreateTable) PlainSelect(net.sf.jsqlparser.statement.select.PlainSelect) Select(net.sf.jsqlparser.statement.select.Select) Truncate(net.sf.jsqlparser.statement.truncate.Truncate) Insert(net.sf.jsqlparser.statement.insert.Insert) Update(net.sf.jsqlparser.statement.update.Update) Drop(net.sf.jsqlparser.statement.drop.Drop)

Example 2 with Truncate

use of net.sf.jsqlparser.statement.truncate.Truncate in project herddb by diennea.

the class TableSpaceMapper method getTableSpace.

public String getTableSpace(Statement statement) throws ScriptException {
    String tableName = null;
    if (statement instanceof Insert) {
        Insert st = (Insert) statement;
        tableName = st.getTable().getFullyQualifiedName();
    } else if (statement instanceof Update) {
        Update st = (Update) statement;
        tableName = st.getTables().get(0).getFullyQualifiedName();
    } else if (statement instanceof Delete) {
        Delete st = (Delete) statement;
        tableName = st.getTables().get(0).getFullyQualifiedName();
    } else if (statement instanceof Truncate) {
        Truncate st = (Truncate) statement;
        tableName = st.getTable().getFullyQualifiedName();
    } else if (statement instanceof Drop) {
        Drop st = (Drop) statement;
        tableName = st.getName().getFullyQualifiedName();
    } else if (statement instanceof CreateTable) {
        CreateTable st = (CreateTable) statement;
        tableName = st.getTable().getFullyQualifiedName();
    } else if (statement instanceof Alter) {
        Alter st = (Alter) statement;
        tableName = st.getTable().getFullyQualifiedName();
    } else {
        return null;
    }
    return mapTableNameToSchema(tableName);
}
Also used : Delete(net.sf.jsqlparser.statement.delete.Delete) Alter(net.sf.jsqlparser.statement.alter.Alter) CreateTable(net.sf.jsqlparser.statement.create.table.CreateTable) Truncate(net.sf.jsqlparser.statement.truncate.Truncate) Insert(net.sf.jsqlparser.statement.insert.Insert) Update(net.sf.jsqlparser.statement.update.Update) Drop(net.sf.jsqlparser.statement.drop.Drop)

Example 3 with Truncate

use of net.sf.jsqlparser.statement.truncate.Truncate in project JSqlParser by JSQLParser.

the class TruncateTest method testTruncate.

@Test
public void testTruncate() throws Exception {
    String statement = "TRUncATE TABLE myschema.mytab";
    Truncate truncate = (Truncate) parserManager.parse(new StringReader(statement));
    assertEquals("myschema", truncate.getTable().getSchemaName());
    assertEquals("myschema.mytab", truncate.getTable().getFullyQualifiedName());
    assertEquals(statement.toUpperCase(), truncate.toString().toUpperCase());
    statement = "TRUncATE   TABLE    mytab";
    String toStringStatement = "TRUncATE TABLE mytab";
    truncate = (Truncate) parserManager.parse(new StringReader(statement));
    assertEquals("mytab", truncate.getTable().getName());
    assertEquals(toStringStatement.toUpperCase(), truncate.toString().toUpperCase());
}
Also used : StringReader(java.io.StringReader) Truncate(net.sf.jsqlparser.statement.truncate.Truncate) Test(org.junit.Test)

Aggregations

Truncate (net.sf.jsqlparser.statement.truncate.Truncate)3 Alter (net.sf.jsqlparser.statement.alter.Alter)2 CreateTable (net.sf.jsqlparser.statement.create.table.CreateTable)2 Delete (net.sf.jsqlparser.statement.delete.Delete)2 Drop (net.sf.jsqlparser.statement.drop.Drop)2 Insert (net.sf.jsqlparser.statement.insert.Insert)2 Update (net.sf.jsqlparser.statement.update.Update)2 ExecutionPlan (herddb.model.ExecutionPlan)1 StringReader (java.io.StringReader)1 CreateIndex (net.sf.jsqlparser.statement.create.index.CreateIndex)1 Execute (net.sf.jsqlparser.statement.execute.Execute)1 PlainSelect (net.sf.jsqlparser.statement.select.PlainSelect)1 Select (net.sf.jsqlparser.statement.select.Select)1 Test (org.junit.Test)1