package com.gyee.wisdom.dao.golden;


import com.rtdb.service.impl.ServerImpl;
import com.rtdb.service.impl.ServerImplPool;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

@Configuration
//@PropertySource("classpath:/golden.properties")
public class GoldenConfig {

    @Value("${golden.server_ip:127.0.0.1}")
    private String serverIp;

    @Value("${golden.server_port:6327}")
    private int serverPort;

    @Value("${golden.user_name:sa}")
    private String userName;

    @Value("${golden.password:golden}")
    private String password;

    @Value("${golden.pool_size:10}")
    private int poolSize;

    @Value("${golden.max_pool_size:100}")
    private int maxPoolSize;

    @Value("${golden.query_history_limit:100000}")
    private int queryHistoryLimit;

    private ServerImplPool pool;

    private GoldenConnectionPool connectionPool;

    public ServerImplPool getServerImplPool() {
        if (pool == null) {
            pool = new ServerImplPool(serverIp, serverPort, userName,password, poolSize, maxPoolSize);
        }
        return pool;
    }

    public GoldenConnectionPool getGoldenConnectionPool() {
        if (connectionPool == null) {
            connectionPool = new GoldenConnectionPool();
            connectionPool.init(serverIp, (short)serverPort, userName,password, poolSize,1, maxPoolSize);
            System.out.println("golden server ip = " +  serverIp);
        }
        return connectionPool;
    }

    public ServerImpl getServerImpl() throws Exception {
        return new ServerImpl(serverIp, serverPort, userName, password);
    }

    public int getQueryHistoryLimit() {
        return queryHistoryLimit;
    }

}