All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.schlak.universalQB.Implementation.MySQL.StatmentBoxes.MysqlAlterBox Maven / Gradle / Ivy

Go to download

The java lib universalQB can be used to access different databases using formalized objects. These objects got converted into a query matching to the syntactical rules of the database management system

There is a newer version: 0.6.4
Show newest version
package com.github.schlak.universalQB.Implementation.MySQL.StatmentBoxes;

import com.github.schlak.universalQB.Definition.GeneralOperations.ValueToConnection;
import com.github.schlak.universalQB.Definition.StatementBoxes.BasicAlterBox;
import org.apache.commons.lang.StringEscapeUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayDeque;
import java.util.Queue;

public class MysqlAlterBox extends BasicAlterBox {


    @Override
    public PreparedStatement getStatement(Connection connection) throws SQLException {
        return connection.prepareStatement("ALTER TABLE " +
                StringEscapeUtils.escapeSql(this.tableName) + " " +
            this.getColumnDefinitions() + ";");
    }

    @Override
    public boolean validate() {
        return !(tableName.equals("") || columnDefinitionList.size() == 0);
    }

    @Override
    public Queue getParameterQueue() {
        return new ArrayDeque<>();
    }

    @Override
    public String getPreparedStatementString() {
        return "ALTER TABLE " +
                StringEscapeUtils.escapeSql(this.tableName) + " " +
                this.getColumnDefinitions() + ";";
    }

    public String getColumnDefinitions() {
        StringBuilder columnDefinitions = new StringBuilder();

        columnDefinitions.append("MODIFY COLUMN ");

        this.columnDefinitionList.forEach(o->{
            columnDefinitions.append(o.getDefinition());
            columnDefinitions.append(" ");
        });
        return columnDefinitions.toString();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy