Package com.dotmarketing.startup.runonce

Source Code of com.dotmarketing.startup.runonce.Task03045TagnameTypeChangeMSSQL

package com.dotmarketing.startup.runonce;

import java.sql.SQLException;

import com.dotmarketing.common.db.DotConnect;
import com.dotmarketing.db.DbConnectionFactory;
import com.dotmarketing.exception.DotDataException;
import com.dotmarketing.exception.DotRuntimeException;
import com.dotmarketing.startup.StartupTask;

/**
*
*
* @author Samuel Mortha
*/
public class Task03045TagnameTypeChangeMSSQL implements StartupTask {

    public boolean forceRun() {
        return true;
    }

    void alterProcedure() throws SQLException {
        if (DbConnectionFactory.isMsSql()) {
          DotConnect dc = new DotConnect();
          String alterSql = "alter table tag drop constraint tag_tagname_host;" +
              "alter table tag alter column tagname nvarchar(255) null;" +
              "alter table tag add constraint tag_tagname_host unique (tagname, host_id);";
          dc.executeStatement(alterSql);
        }
    }


    public void executeUpgrade() throws DotDataException, DotRuntimeException {
        try {
            DbConnectionFactory.getConnection().setAutoCommit(true);
        } catch (SQLException e) {
            throw new DotDataException(e.getMessage(), e);
        }
        try {
          alterProcedure();
        } catch (Exception ex) {
            throw new DotRuntimeException(ex.getMessage(), ex);
        }
    }


}
TOP

Related Classes of com.dotmarketing.startup.runonce.Task03045TagnameTypeChangeMSSQL

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.