Add "Describe" command, with support for describing both (a) specific table(s) and...
[squelch.git] / src / main / java / net / jaekl / squelch / db / DbDriver.java
1 package net.jaekl.squelch.db;
2
3 import java.sql.Connection;
4 import java.sql.DriverManager;
5 import java.sql.SQLException;
6 import java.util.Locale;
7
8 public abstract class DbDriver {
9         // Returns true iff. this DbDriver knows how to connect to the given JDBC URL
10         abstract public boolean handles(String jdbcUrl);
11         
12         // Execute line as a statement of this type
13         abstract String getJdbcDriverClassName();
14         
15         // Open a new Connection to the database.  Note that the caller must close() this at some point.
16         public Connection connect(String jdbcUrl, String userName, String password) throws ClassNotFoundException, SQLException 
17         {
18                 Class.forName(getJdbcDriverClassName());
19                 return DriverManager.getConnection(jdbcUrl, userName, password);
20         }
21         
22         // If this database uses case-insensitive collation, then return an upper-cased version of the passed string.
23         // Otherwise (if this database is case-sensitive), return the string unchanged.
24         // Note that the default implementation assumes a case-insensitive DB.
25         public String adjustCase(String input) {
26                 if (null == input) {
27                         return "";      // Convert nulls to empty strings, so that we can safely use .equals() on the result
28                 }
29                 return input.toUpperCase(Locale.CANADA);
30         }
31 }