ignite IMDB SQL를 java로 구현해보자!

Karim·2021년 11월 17일
4

Ignite 예제

목록 보기
1/1
post-thumbnail

1. Version

💬

  • Ignite : 2.11.0
  • grdle : ignite-clients/spring.2.11.0

2. build.gradle

💬 build.gredle dependencies

dependencies {
        implementation group: 'org.apache.ignite', name: 'ignite-core', version: '2.11.0'
    implementation group: 'org.apache.ignite', name: 'ignite-spring', version: '2.11.0'
}

3. Ignite connect 및 Close 구현

💬 java code

package com.karim.igniteBasis.igniteConnectCfg;

import org.apache.ignite.Ignition;
import org.apache.ignite.client.ClientCache;
import org.apache.ignite.client.IgniteClient;
import org.apache.ignite.configuration.ClientConfiguration;

/**
 * Created by karim
 * Date : 2021-11-17
 * Time : 오후 2:16
 */
public class IgniteLifeCycle {

    // 접속정보
    ClientConfiguration cfg = new ClientConfiguration()
            .setAddresses("ignigeServerIp:10800")
            .setPartitionAwarenessEnabled(true);

    IgniteClient ignite = Ignition.startClient(cfg);

    public ClientCache IgniteConnect(){
        // 스키마설정
        ClientCache<Object, Object> cache = ignite.getOrCreateCache("PUBLIC");

        return cache;
    }

    public void IgniteClose(){
        try {
            ignite.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

4. Ignite Sql DML 구현

  • 사실상 sql 문 그대로 사용하면된다.

💬 select java code

    public void getSelectAll(ClientCache cache, String table){
        List<?> resultList;

        //select 쿼리문 작성
        SqlFieldsQuery qry = new SqlFieldsQuery("SELECT * FROM table");
        resultList = cache.query(qry).getAll();
        System.out.println("검색 결과 : " + resultList);
    }

💬 insert java code

    public void getSelectAll(ClientCache cache, String table){
        String dmlQry = "INSERT INTO table (USERID, USERNAME, USERINT, USERDOUBLE) VALUES ('1','a',1,1.1)";
        SqlFieldsQuery qry = new SqlFieldsQuery(dmlQry);
        cache.query(qry).getAll();
    }

💬 update java code

    public void getSelectAll(ClientCache cache, String table){
        String dmlQry = "UPDATE table  SET USERNAME = 'karim', USERINT = 1, USERDOUBLE = 0.0 WHERE USERID = '1' ";
        SqlFieldsQuery qry = new SqlFieldsQuery(dmlQry);
        cache.query(qry).getAll();
    }

4. Ignite Sql DDL 구현

  • 사실상 sql 문 그대로 사용하면된다.
  • sql문의 축소판이라고 생각하면 된다.
    !!!AUTO_INCREMENT 같은 기능은 안됨!!!

💬 create table java code

    public void setCreateTable(ClientCache cache, String table){

        //select 쿼리문 작성
        String ddlQry = "CREATE TABLE table (" +
                "USERID VARCHAR," +
                "USERNAME VARCHAR," +
                "USERINT INTEGER," +
                "USERDOUBLE DOUBLE," +
                "CONSTRAINT USERID PRIMARY KEY (USERID)" +
                ");";

        SqlFieldsQuery qry = new SqlFieldsQuery(ddlQry);
        qry.setSchema("PUBLIC");
        cache.query(qry).getAll();
    }

📚 참고

profile
나도 보기 위해 정리해 놓은 벨로그

0개의 댓글