package edu.mit.csail.db.ml.util;

import edu.mit.csail.db.ml.conf.ModelDbConfig;
import org.jooq.DSLContext;
import org.jooq.SQLDialect;
import org.jooq.impl.DSL;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ContextFactory {
  public static DSLContext create(String username, String password, String jdbcUrl, ModelDbConfig.DatabaseType dbType)
    throws SQLException, IllegalArgumentException {
    Connection conn = DriverManager.getConnection(jdbcUrl, username, password);

    switch (dbType) {
      case SQLITE: return DSL.using(conn, SQLDialect.SQLITE);
    }

    throw new IllegalArgumentException("Cannot connect to DatabaseType: " + dbType);
  }
}

@@ -252,37 +252,608 @@
 n;%0A%0A
-public class ContextFactory %7B
+/**%0A * This class contains logic for connecting to the database.%0A */%0Apublic class ContextFactory %7B%0A  /**%0A   * Create a database context that reflects a connection to a database.%0A   * @param username - The username to connect to the database.%0A   * @param password - The password to connect to the database.%0A   * @param jdbcUrl - The JDBC URL of the database.%0A   * @param dbType - The database type.%0A   * @return The database context.%0A   * @throws SQLException - Thrown if there are problems connecting to the database.%0A   * @throws IllegalArgumentException - Thrown if the dbType is unsupported.%0A   */
 %0A  p

Comment ContextFactory