package com.splicemachine.management;

import org.sparkproject.guava.collect.Sets;
import com.splicemachine.EngineDriver;
import com.splicemachine.access.api.DatabaseVersion;
import com.splicemachine.derby.utils.DatabasePropertyManagementImpl;
import com.splicemachine.pipeline.PipelineDriver;
import com.splicemachine.utils.logging.LogManager;
import com.splicemachine.utils.logging.Logging;

import java.sql.SQLException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author Scott Fines
 *         Date: 2/17/16
 */
public class DirectDatabaseAdministrator implements DatabaseAdministrator{
    private final Logging logging = new LogManager();

    @Override
    public void setLoggerLevel(String loggerName,String logLevel) throws SQLException{
        logging.setLoggerLevel(loggerName,logLevel);
    }

    @Override
    public List<String> getLoggerLevel(String loggerName) throws SQLException{
        return Collections.singletonList(logging.getLoggerLevel(loggerName));
    }

    @Override
    public Set<String> getLoggers() throws SQLException{
        return Sets.newHashSet(logging.getLoggerNames());
    }

    @Override
    public Map<String, DatabaseVersion> getClusterDatabaseVersions() throws SQLException{
        return Collections.singletonMap("mem",EngineDriver.driver().getVersion());
    }

    @Override
    public void setWritePoolMaxThreadCount(int maxThreadCount) throws SQLException{
        PipelineDriver.driver().writeCoordinator().setMaxAsyncThreads(maxThreadCount);
    }

    @Override
    public Map<String, Integer> getWritePoolMaxThreadCount() throws SQLException{
        return Collections.singletonMap("mem",PipelineDriver.driver().writeCoordinator().getMaxAsyncThreads());
    }

    @Override
    public Map<String, String> getGlobalDatabaseProperty(String key) throws SQLException{
        return Collections.singletonMap("mem",DatabasePropertyManagementImpl.instance().getDatabaseProperty(key));
    }

    @Override
    public void setGlobalDatabaseProperty(String key,String value) throws SQLException{
        DatabasePropertyManagementImpl.instance().setDatabaseProperty(key,value);
    }

    @Override
    public void emptyGlobalStatementCache() throws SQLException{
        //TODO -sf- no-op for now --eventually may need to implement
    }
}

@@ -438,86 +438,9 @@
 til.
-Collections;%0Aimport java.util.List;%0Aimport java.util.Map;%0Aimport java.util.Set
+*
 ;%0A%0A/
@@ -1285,32 +1285,589 @@
 sion());%0A    %7D%0A%0A
+    @Override%0A    public Map%3CString,Map%3CString,String%3E%3E getDatabaseVersionInfo() throws SQLException%7B%0A        DatabaseVersion databaseVersion = EngineDriver.driver().getVersion();%0A        Map%3CString,String%3E attrs = new HashMap%3C%3E();%0A        attrs.put(%22release%22, databaseVersion.getRelease());%0A        attrs.put(%22implementationVersion%22, databaseVersion.getImplementationVersion());%0A        attrs.put(%22buildTime%22, databaseVersion.getBuildTime());%0A        attrs.put(%22url%22, databaseVersion.getURL());%0A        return Collections.singletonMap(%22mem%22,attrs);%0A    %7D%0A%0A
     @Override%0A  

implement new api for mem db too