Maybe beause there is no callback fucntion for 
org.apache.ignite.IgniteJdbcThinDriver.



I use a class mock liquibase, hope can help you:



/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package com.samples.vehicles.ignite.init;



import com.samples.vehicles.common.DomainUtils;



import java.util.ArrayList;

import java.util.Collections;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import java.util.UUID;



import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.context.annotation.Bean;

import org.springframework.context.annotation.Configuration;

import org.springframework.context.annotation.DependsOn;

import org.springframework.jdbc.core.JdbcTemplate;



/**

* @author lenovo

*/

@Configuration

public class ILikeLiquibase {



    private final Logger log = LoggerFactory.getLogger(this.getClass());

    @Autowired

    private JdbcTemplate jdbcTemplate;



    private final String lock = UUID.randomUUID().toString();

    private final List<String> sqlList = new ArrayList<>();

    private final Map<String, String> sqlMap = new HashMap<>();



    //add new script here

    private void loadScripts() {



        addSql("20180314WG03", "DROP TABLE IF EXISTS alarm_record_file;");

        addSql("20180314WG04", "CREATE TABLE alarm_record_file(fileossid 
VARCHAR PRIMARY KEY,alarm_id VARCHAR,"

                + "file_type Long, channel Long, create_time TIMESTAMP);");



        addSql("20180314WG05", "DROP TABLE IF EXISTS gps;");

        addSql("20180314WG06", "CREATE TABLE gps(id Long PRIMARY KEY 
,vehicle_id Long, time TIMESTAMP,driver_id Long,"

                + "status Long,lng Long,lat Long,height Long,speed 
Long,direction Long,wirelessstrength Long,gnns Long,mileage Long);");



        addSql("20180323DXM01", "DROP TABLE IF EXISTS alarm_record_file;");

        addSql("20180323DXM02", "CREATE TABLE alarm_record_file(fileossid 
VARCHAR,alarm_id VARCHAR,"

                + "file_type Long, channel Long, create_time TIMESTAMP, PRIMARY 
KEY(fileossid,alarm_id));");



    }



    private void mergeScripts() {

        jdbcTemplate.query("select id, sql from Public.sqlScriptLog",

                (rs, row) -> {

                    String id = rs.getString("id");

                    String sql = rs.getString("sql");

                    if (sqlMap.containsKey(id) && !sqlMap.get(id).equals(sql)) {

                        throw new RuntimeException("Sql script changed id:" + 
id);

                    }

                    sqlList.remove(id);

                    return null;

                });

    }



    private void addSql(String id, String sql) {

        if (sqlList.contains(id)) {

            throw new RuntimeException("duplicate sql script");

        }

        sqlList.add(id);

        sqlMap.put(id, sql);

    }



    private void createTable() {

        jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS sqlScriptLog("

                + " id VARCHAR PRIMARY KEY, sql VARCHAR)"

                + " WITH \"backups=2\";");

        jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS sqlScriptLock("

                + " id VARCHAR PRIMARY KEY, lock LONG)"

                + " WITH \"backups=2\";");

    }



    private void checkLock() {

        Integer nLock = jdbcTemplate.queryForObject("select count(*) from 
sqlScriptLock",

                Integer.class);

        if (nLock == 0) {

            addLock();

        }

        Integer myLock = jdbcTemplate.queryForObject("select count(*) from 
sqlScriptLock "

                + "where id = ? ", new Object[]{lock}, Integer.class);

        if (myLock == 0) {

            log.info("SqlScriptManagement waiting for lock ...");

            try {

                Thread.sleep(10000L);

            } catch (Exception e) {

            }

            checkLock();

        }



    }



    private void addLock() {

        log.info("SqlScriptManagement get lock ...");

        jdbcTemplate.update("insert into sqlScriptLock (id, lock) values (?, 
?)",

                new Object[]{lock, 1});

    }



    private void removeLock() {

        log.info("SqlScriptManagement remove lock ...");

        jdbcTemplate.update("delete from sqlScriptLock "

                + "where id = ?", new Object[]{lock});

    }



    private void runSql() {

        Collections.sort(sqlList);

        log.info("SqlScriptManagement run scripts:" + 
DomainUtils.bean2json(sqlList));

        sqlList.forEach(id -> {

            log.info("Running sql script id:" + id);

            jdbcTemplate.execute(sqlMap.get(id));

            jdbcTemplate.update("insert into sqlScriptLog(id, sql) VALUES 
(?,?)",

                    ps -> {

                        ps.setString(1, id);

                        ps.setString(2, sqlMap.get(id));

                    });

        });

    }



    @Bean

    @DependsOn("igniteConfig")

    public boolean updateSql() throws InterruptedException {

        createTable();

        loadScripts();

        checkLock();

        try {

            mergeScripts();

            runSql();

        } catch (Exception e) {

            throw e;

        } finally {

            removeLock();

        }

        return true;

    }

}







发送自 Windows 10 版邮件<https://go.microsoft.com/fwlink/?LinkId=550986>应用



________________________________
发件人: vkulichenko <valentin.kuliche...@gmail.com>
发送时间: Monday, March 26, 2018 9:23:13 AM
收件人: user@ignite.apache.org
主题: Re: Liquibase with Ignite?

Never heard of anyone doing this, but I don't see why it wouldn't work. Did
you have any issues while working with this combination?

-Val



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Reply via email to