/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.facebook.presto.raptor.storage;

import com.google.inject.Binder;
import com.google.inject.Module;
import com.google.inject.Provides;
import com.google.inject.Scopes;
import io.airlift.dbpool.H2EmbeddedDataSource;
import io.airlift.dbpool.H2EmbeddedDataSourceConfig;
import io.airlift.units.Duration;
import org.skife.jdbi.v2.DBI;
import org.skife.jdbi.v2.IDBI;

import javax.inject.Singleton;

import java.io.File;

import static io.airlift.configuration.ConfigurationModule.bindConfig;
import static java.util.concurrent.TimeUnit.SECONDS;

public class StorageModule
        implements Module
{
    @Override
    public void configure(Binder binder)
    {
        bindConfig(binder).to(StorageManagerConfig.class);
        binder.bind(StorageManager.class).to(OrcStorageManager.class).in(Scopes.SINGLETON);
    }

    @Provides
    @Singleton
    @ForStorageManager
    public IDBI createLocalStorageManagerDBI(StorageManagerConfig config)
            throws Exception
    {
        return new DBI(new H2EmbeddedDataSource(new H2EmbeddedDataSourceConfig()
                .setFilename(new File(config.getDataDirectory(), "db/StorageManager").getAbsolutePath())
                .setMaxConnections(500)
                .setMaxConnectionWait(new Duration(1, SECONDS))));
    }
}

@@ -695,298 +695,14 @@
 ect.
-Provides;%0Aimport com.google.inject.Scopes;%0Aimport io.airlift.dbpool.H2EmbeddedDataSource;%0Aimport io.airlift.dbpool.H2EmbeddedDataSourceConfig;%0Aimport io.airlift.units.Duration;%0Aimport org.skife.jdbi.v2.DBI;%0Aimport org.skife.jdbi.v2.IDBI;%0A%0Aimport javax.inject.Singleton;%0A%0Aimport java.io.File
+Scopes
 ;%0A%0Ai
@@ -774,61 +774,8 @@
 fig;
-%0Aimport static java.util.concurrent.TimeUnit.SECONDS;
 %0A%0Apu
@@ -947,16 +947,16 @@
 class);%0A
+
         
@@ -1048,468 +1048,7 @@
    %7D
-%0A%0A    @Provides%0A    @Singleton%0A    @ForStorageManager%0A    public IDBI createLocalStorageManagerDBI(StorageManagerConfig config)%0A            throws Exception%0A    %7B%0A        return new DBI(new H2EmbeddedDataSource(new H2EmbeddedDataSourceConfig()%0A                .setFilename(new File(config.getDataDirectory(), %22db/StorageManager%22).getAbsolutePath())%0A                .setMaxConnections(500)%0A                .setMaxConnectionWait(new Duration(1, SECONDS))));%0A    %7D
 %0A%7D%0A

Remove unused StorageManager H2 database