001 package hep.aida.ref.sql; 002 003 // SQL 004 import java.sql.SQLException; 005 006 // Log4J 007 import org.apache.log4j.Logger; 008 009 /** <code>Util</code> contains various special utilities usefull 010 * in SQLTuple. Often, they represent functionality proposed to 011 * AIDA, bu not yet standartised. 012 * <p><font color="#880088"> 013 * <pre> 014 * $Log: Util.java,v $ 015 * Revision 1.31 2007/05/23 16:38:44 hrivnac 016 * logical connections for Plotter; better UML 017 * 018 * Revision 1.30 2006/12/13 15:39:29 hrivnac 019 * derby url modified 020 * 021 * Revision 1.29 2006/12/12 15:21:43 hrivnac 022 * McKoi replaced with Derby; uppercase-only dbs handled better; moving to JAS 0.8.3 023 * 024 * Revision 1.28 2006/11/10 17:40:03 hrivnac 025 * WebService updated, long-format Oracle URL allowed, complete db not parsed if only table requested (speed) 026 * 027 * Revision 1.27 2005/09/28 16:21:06 hrivnac 028 * code cleaning 029 * 030 * Revision 1.26 2004/10/29 22:27:25 hrivnac 031 * imports corrected 032 * 033 * Revision 1.25 2004/10/22 15:33:00 hrivnac 034 * cleaned 035 * 036 * Revision 1.24 2004/10/12 13:25:40 hrivnac 037 * small improvements 038 * 039 * Revision 1.23 2004/07/06 14:24:50 hrivnac 040 * support for Oracle 041 * 042 * Revision 1.22 2004/05/22 15:05:59 hrivnac 043 * test 044 * 045 * Revision 1.21 2004/04/14 13:39:47 hrivnac 046 * 1.5 warnings fixed 047 * 048 * Revision 1.20 2004/04/13 15:45:54 hrivnac 049 * AIDA URL introduced 050 * 051 * Revision 1.19 2004/02/26 15:07:33 hrivnac 052 * new AidaUtils, Ant 1.6.1 053 * 054 * Revision 1.18 2004/02/10 14:50:58 hrivnac 055 * JavaDoc tags completed 056 * 057 * Revision 1.17 2004/02/04 13:30:40 hrivnac 058 * - improvement of Enums internal mapping 059 * - general cleaning 060 * 061 * Revision 1.16 2004/01/28 15:54:48 hrivnac 062 * better help 063 * 064 * Revision 1.15 2003/11/26 16:09:46 hrivnac 065 * Functional EventSelector WebService 066 * 067 * Revision 1.14 2003/11/24 15:13:22 hrivnac 068 * Logging improved. 069 * 070 * Revision 1.13 2003/11/21 18:14:04 hrivnac 071 * Prototype of C++ interface based on JACE introduced. 072 * 073 * Revision 1.12 2003/11/20 17:21:58 hrivnac 074 * Java 1.5 natively supported, Log4J reporting improved. 075 * 076 * Revision 1.11 2003/11/18 22:03:45 hrivnac 077 * Root benchmarks. 078 * 079 * Revision 1.10 2003/11/05 19:46:22 hrivnac 080 * - FreeHEP 1.2.1 081 * - JAIDA 3.2.1 082 * 083 * Revision 1.2 2003/10/20 21:03:49 hrivnac 084 * Write/read tests work on both SQL and XML. 085 * 086 * </pre> 087 * </font></p> 088 * @opt attributes 089 * @opt operations 090 * @opt types 091 * @opt visibility 092 * @version $Id: Util.java,v 1.31 2007/05/23 16:38:44 hrivnac Exp $ 093 * @author <a href="mailto:Julius.Hrivnac@cern.ch">J.Hrivnac</a> */ 094 public class Util { 095 096 /** Report about standard SQL Exception. 097 * @param msg Message to be displayed. 098 * @param e Exception to be displayed. 099 * @return Formated message. */ 100 public static String report(String msg, Throwable e) { 101 String s = msg + "\n\n" + e.getMessage() + "\n"; 102 if (e instanceof SQLException) { 103 s += "SQLException: " + ((SQLException)e).getMessage() + "\n"; 104 s += "SQLState: " + ((SQLException)e).getSQLState() + "\n"; 105 s += "VendorError: " + ((SQLException)e).getErrorCode() + "\n"; 106 } 107 if (e.getCause() != null) { 108 s += report("Caused by:", e.getCause()); 109 } 110 return s; 111 } 112 113 /** Form standard command "usage" message. 114 * @param msg Message to be displayed. 115 * @return Formated message. */ 116 public static String urlHelp(String msg) { 117 String s = "\n" + msg + "\n"; 118 s += "url = jdbc:[mysql|postgresql|cjdbc]://<host>/<db>/<table>\n"; 119 s += " jdbc:derby:<dbname>()/<table>\n"; 120 s += " jdbc:oracle:thin:@<host>:<port>:<sid>/<table>\n"; 121 s += " jdbc:oracle:thin:@(DESCRIPTION=...)\n"; 122 s += " <file>.aida/<table>\n"; 123 s += " <file>.root/<table>\n"; 124 return s; 125 } 126 127 /** Logging . */ 128 private static Logger log = Logger.getLogger(Util.class); 129 130 }