001    package hep.aida.ref.sql;
002    
003    // Log4J
004    import org.apache.log4j.Logger;
005    
006    // Java
007    import java.util.Properties;
008    
009    /** <code>Type</code> manages information about SQL database implementations.
010      * It handles their protocol names, driver Class name and various capabilities.
011      * The features are read from {@link Properties} resource
012      * searched in:
013      * <ol>
014      * <li><code>Implementation.properties</code></li>
015      * <li><code>hep/aida/ref/sql/Implementation.properties</code></li>
016      * </ol>
017      * @see Type Type for list of supported Types.
018      * <p><font color="#880088">
019      * <pre>
020      * $Log: Implementation.java,v $
021      * Revision 1.32  2007/06/11 14:02:29  hrivnac
022      * better support for tags in Oracle
023      *
024      * Revision 1.31  2007/05/23 16:38:44  hrivnac
025      * logical connections for Plotter; better UML
026      *
027      * Revision 1.30  2007/05/22 23:33:20  hrivnac
028      * Plotter uses real arguments parsing
029      *
030      * Revision 1.29  2006/12/14 17:55:52  hrivnac
031      * going back to JAS 0.8.3rc6
032      *
033      * Revision 1.28  2006/12/12 15:21:42  hrivnac
034      * McKoi replaced with Derby; uppercase-only dbs handled better; moving to JAS 0.8.3
035      *
036      * Revision 1.27  2004/11/22 18:09:52  hrivnac
037      * Oracle treatment
038      *
039      * Revision 1.26  2004/10/22 15:32:59  hrivnac
040      * cleaned
041      *
042      * Revision 1.25  2004/10/22 14:22:44  hrivnac
043      * properties loading refactored
044      *
045      * Revision 1.24  2004/10/21 10:39:31  hrivnac
046      * works wel with ColMan
047      *
048      * Revision 1.23  2004/10/20 23:02:29  hrivnac
049      * Types mapping simplified
050      *
051      * Revision 1.22  2004/10/12 19:26:59  hrivnac
052      * MySQL Connector 3.0.14
053      *
054      * Revision 1.21  2004/06/30 13:01:05  hrivnac
055      * oracle sceleton
056      *
057      * Revision 1.20  2004/05/22 15:12:59  hrivnac
058      * class id reformated
059      *
060      * Revision 1.19  2004/05/18 15:34:28  hrivnac
061      * compatible with Java 1.5.0-beta2
062      *
063      * Revision 1.18  2004/04/21 22:05:53  hrivnac
064      * Implementation.properties to configure Inplementation.java, no SQL dependency in code
065      *
066      * Revision 1.17  2004/04/21 22:04:03  hrivnac
067      * Implementation.properties to configure Inplementation.java, no SQL dependency in code
068      *
069      * Revision 1.16  2004/04/21 13:41:32  hrivnac
070      * explicit dependency on MySQL removed
071      *
072      * Revision 1.15  2004/04/20 22:33:33  hrivnac
073      * Implementation/Type handling improved
074      *
075      * Revision 1.14  2004/04/16 15:32:57  hrivnac
076      * Type.properties to setup Type.class
077      *
078      * Revision 1.13  2004/04/14 13:39:46  hrivnac
079      * 1.5 warnings fixed
080      *
081      * Revision 1.12  2004/04/13 15:45:54  hrivnac
082      * AIDA URL introduced
083      *
084      * Revision 1.11  2004/02/10 14:50:58  hrivnac
085      * JavaDoc tags completed
086      *
087      * Revision 1.10  2004/02/04 13:30:39  hrivnac
088      * - improvement of Enums internal mapping
089      * - general cleaning
090      *
091      * Revision 1.9  2003/12/29 23:43:52  hrivnac
092      * Only core SQLTuple; only with Java 1.5
093      *
094      * Revision 1.8  2003/11/05 19:46:22  hrivnac
095      * - FreeHEP 1.2.1
096      * - JAIDA 3.2.1
097      *
098      * Revision 1.1  2003/10/08 15:00:30  hrivnac
099      * Enums introduced as standard entities.
100      *
101      * </pre>
102      * </font></p>
103      * @opt attributes
104      * @opt operations
105      * @opt types
106      * @opt visibility
107      * @version $Id: Implementation.java,v 1.32 2007/06/11 14:02:29 hrivnac Exp $
108      * @author <a href="mailto:Julius.Hrivnac@cern.ch">J.Hrivnac</a> */
109    public class Implementation {
110    
111      /** Give associated JDBC driver.
112        * @param protocol The JDBC protocol.
113        * @return         The name of the driver Class corresponding to this Impementation. */
114      public static String driver(String protocol) {
115        return (String)_properties.get(_place + ".Driver." + protocol);
116        }
117    
118      /** Give associated database creation command, if exists.
119        * @param protocol The JDBC protocol
120        * @return         The database creation command, if exists */
121      public static String creationCommand(String protocol) {
122        String creation = (String)_properties.get(_place + ".CreationCommand." + protocol);
123        if (creation == null) {
124          return "";
125          }
126        return creation;
127        }
128    
129      /** Tell, if supports only uppercase names.
130        * @param protocol The JDBC protocol.
131        * @return Whether supports only uppercase names. */
132      public static boolean supportsOnlyUpperCase(String protocol) {
133        String supports = (String)_properties.get(_place + ".UpperCase." + protocol);
134        if (supports == null) {
135          return false;
136          }
137        return supports.equals("true");
138        }
139    
140      /** Tell, if supports table replication within database.
141        * @param protocol The JDBC protocol.
142        * @return Whether supports table replication within database. */
143      public static boolean supportsReplication(String protocol) {
144        String supports = (String)_properties.get(_place + ".Replication." + protocol);
145        if (supports == null) {
146          return false;
147          }
148        return supports.equals("true");
149        }
150    
151      /** Tell, if supports only TYPE_FORWARD_ONLY cursor.
152        * @param protocol The JDBC protocol.
153        * @return Whether supports only TYPE_FORWARD_ONLY cursor. */
154      public static boolean supportsOnlyForwardOnly(String protocol) {
155        String supports = (String)_properties.get(_place + ".ForwardOnly." + protocol);
156        if (supports == null) {
157          return false;
158          }
159        return supports.equals("true");
160        }
161    
162      /** Add an implementation not available from default.
163        * @param protocol            The JDBC protocol.
164        * @param driver              The name of the driver Class corresponding to this Impementation.
165        * @param supportsReplication Whether supports table replication within database. */
166      public static void add(String protocol,
167                             String driver,
168                             boolean supportsReplication) {
169        _properties.setProperty(_place + ".Driver." + protocol, driver);
170        _properties.setProperty(_place + ".Replication." + protocol, supportsReplication ? "true" : "false");
171        }
172    
173      private static Properties _properties = new LoadedProperties("Implementation.properties", "hep/aida/ref/sql");
174    
175      private static String _place = Implementation.class.getName();
176    
177      /** Logging . */
178      private static Logger log = Logger.getLogger(Implementation.class);
179    
180      }