1 package com.quantum.adapters;
3 import com.quantum.Messages;
4 import com.quantum.sql.SQLHelper;
5 import com.quantum.util.QuantumUtil;
9 public class OracleAdapter extends DatabaseAdapter {
10 protected OracleAdapter() {
11 super(AdapterFactory.ORACLE);
13 public String getShowSequenceQuery(String qualifier) {
14 return "SELECT SEQUENCE_OWNER, SEQUENCE_NAME FROM ALL_SEQUENCES WHERE SEQUENCE_OWNER = '" + qualifier + "'"; //$NON-NLS-1$
16 public String getPrevValue(String sequence, String owner) {
17 return "SELECT LAST_NUMBER FROM ALL_SEQUENCES WHERE SEQUENCE_OWNER = '" + owner + "' AND SEQUENCE_NAME = '" + sequence + "'"; //$NON-NLS-1$ //$NON-NLS-2$
19 public String getNextValue(String sequence, String owner) {
20 return "SELECT " + SQLHelper.getQualifiedName(owner, sequence) + ".NEXTVAL FROM DUAL";
22 public String getCommentsQuery(String tableName, String column) {
23 String query = "SELECT COMMENTS FROM ALL_COL_COMMENTS WHERE TABLE_NAME = '";
24 query += QuantumUtil.getTableName(tableName) + "' AND COLUMN_NAME = '" + column + "'" ;
25 if (!(QuantumUtil.getSchemaName(tableName).equals("")))
26 query += " AND OWNER = '" + QuantumUtil.getSchemaName(tableName) + "'";
30 * Quotes a string according to the type of the column
31 * @param string to be quoted
32 * @param type according to java.sql.Types
35 public String quote(String string, int type, String typeString) {
36 if (type == java.sql.Types.DATE || type == java.sql.Types.TIMESTAMP) {
37 string = string.trim();
38 String sub = string.substring(string.length()-2, string.length()-1);
39 if (string.length() > 1 && sub.equals(Messages.getString("OracleAdapter.._3"))) //$NON-NLS-1$
40 string = string.substring(0,string.length()-2);
41 return "TO_DATE('" + string + "','yyyy-mm-dd hh24:mi:ss')"; //$NON-NLS-1$ //$NON-NLS-2$
43 // use the default (upper type)
44 return super.quote(string, type, typeString);
48 * @see com.quantum.adapters.DatabaseAdapter#filterTableName(java.lang.String)
50 public String filterTableName(String tableName) {
51 // If there is no mixed case, better not quote, it's prettier on display
52 if (tableName.equals(tableName.toUpperCase())) return tableName;
53 // We quote the table name (and only the table name) because it has mixed case
54 if (QuantumUtil.getSchemaName(tableName).equals(""))
55 return "\"" + tableName +"\""; //$NON-NLS-1$
57 return QuantumUtil.getSchemaName(tableName) + ".\"" +
58 QuantumUtil.getTableName(tableName) + "\"";
62 * The default schema for Oracle is the upper-case userid.
63 * @see com.quantum.adapters.DatabaseAdapter#getDefaultSchema(java.lang.String)
65 public String getDefaultSchema(String userid) {
66 return super.getDefaultSchema(userid).toUpperCase();