/*-------------------------------------------------------------------------- * Copyright 2008 utgenome.org * * 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. *--------------------------------------------------------------------------*/ //-------------------------------------- // utgb-shell Project // // JDBCUtil.java // Since: Aug 11, 2008 // // $URL$ // $Author$ //-------------------------------------- package org.utgenome.shell; import java.io.File; import org.utgenome.config.ConnectionInfo; import org.xerial.db.DBException; import org.xerial.db.sql.DatabaseAccess; import org.xerial.db.sql.postgres.PostgresAccess; import org.xerial.db.sql.sqlite.SQLiteAccess; /** * Utilities for connecting DMBS through JDBC * * @author leo * */ public class JDBCUtil { public static DatabaseAccess getDatabaseAccess(ConnectionInfo connectionInfo) throws UTGBShellException { return getDatabaseAccess(new File(".").getAbsolutePath(), connectionInfo); } public static DatabaseAccess getDatabaseAccess(String projectRootFolder, ConnectionInfo connectionInfo) throws UTGBShellException { try { String dbms = connectionInfo.getDbms(); if (dbms.equals("sqlite")) { return new SQLiteAccess(projectRootFolder + "/" + connectionInfo.getAddress()); } else if (dbms.equals("postgres")) { return new PostgresAccess(connectionInfo.getAddress(), connectionInfo.getUser(), connectionInfo.getPass()); } else throw new UTGBShellException("unknown DBMS: " + dbms); } catch (DBException e) { throw new UTGBShellException(e); } } }