/*-------------------------------------------------------------------------- * 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 // // DBInfo.java // Since: Jan 16, 2008 // // $URL$ // $Author$ //-------------------------------------- package org.utgenome.shell; import org.utgenome.config.ConnectionInfo; import org.utgenome.config.DatabaseInfo; import org.utgenome.config.TrackConfiguration; import org.xerial.db.DBException; import org.xerial.db.Relation; import org.xerial.db.datatype.DataType; import org.xerial.db.sql.DatabaseAccess; import org.xerial.util.log.Logger; /** * An UTGB Shell subcommand that displays database information described in config/track-config.xml * * @author leo * */ public class DBInfo extends UTGBShellSubCommandBase { private static Logger _logger = Logger.getLogger(DBInfo.class); @Override public void execute(String[] args) throws UTGBShellException { TrackConfiguration config = loadTrackConfiguration(); for (DatabaseInfo dbInfo : config.getDatabaseList()) { String databaseID = dbInfo.getId(); _logger.info("database ID: " + databaseID); for (ConnectionInfo connInfo : dbInfo.getConnectionList()) { try { DatabaseAccess dbAccess = JDBCUtil.getDatabaseAccess(connInfo); for (String table : dbAccess.getTableNameList()) { _logger.info("table: " + table); Relation relation = dbAccess.getRelation(table); for (DataType dt : relation.getDataTypeList()) { _logger.info(" column: " + dt.getName() + " (" + dt.getTypeName() + ")"); } } } catch (DBException e) { _logger.error(e); } } } } @Override public String name() { return "dbinfo"; } public String getDetailedDescription() { return loadUsage("help-dbinfo.txt"); } public String getOneLinerDescription() { return "displays database information"; } public String getOptionList() { return ""; } }