initial quantum version
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / adapters / OracleAdapter.java
diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/OracleAdapter.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/adapters/OracleAdapter.java
new file mode 100644 (file)
index 0000000..a7fc544
--- /dev/null
@@ -0,0 +1,67 @@
+package com.quantum.adapters;
+
+import com.quantum.Messages;
+import com.quantum.sql.SQLHelper;
+import com.quantum.util.QuantumUtil;
+
+
+
+public class OracleAdapter extends DatabaseAdapter {
+       public String getShowSequenceQuery(String qualifier, boolean isDefault) {
+        return "SELECT SEQUENCE_OWNER, SEQUENCE_NAME FROM ALL_SEQUENCES WHERE SEQUENCE_OWNER = '" + qualifier + "'"; //$NON-NLS-1$
+       }
+       public String getPrevValue(String sequence, String owner) {
+       return "SELECT LAST_NUMBER FROM ALL_SEQUENCES WHERE SEQUENCE_OWNER = '" + owner + "' AND SEQUENCE_NAME = '" + sequence + "'"; //$NON-NLS-1$ //$NON-NLS-2$
+       }       
+       public String getNextValue(String sequence, String owner) {
+               return "SELECT " + SQLHelper.getQualifiedName(owner, sequence) + ".NEXTVAL FROM DUAL";
+       }
+       public String getCommentsQuery(String tableName, String column) {
+               String query = "SELECT COMMENTS FROM ALL_COL_COMMENTS WHERE TABLE_NAME = '"; 
+               query += QuantumUtil.getTableName(tableName) + "' AND COLUMN_NAME = '" + column + "'" ;
+               if (!(QuantumUtil.getSchemaName(tableName).equals("")))
+                       query += " AND OWNER = '" + QuantumUtil.getSchemaName(tableName) + "'";
+               return query;
+       }
+       /**
+        * Quotes a string according to the type of the column 
+        * @param string to be quoted
+        * @param type according to java.sql.Types
+        * @return
+        */
+       public String quote(String string, int type, String typeString) {
+               if (type == java.sql.Types.DATE || type == java.sql.Types.TIMESTAMP) {
+                       string = string.trim();
+                       String sub = string.substring(string.length()-2, string.length()-1);
+                       if (string.length() > 1 &&  sub.equals(Messages.getString("OracleAdapter.._3"))) //$NON-NLS-1$
+                               string = string.substring(0,string.length()-2);
+                       return "TO_DATE('" + string + "','yyyy-mm-dd hh24:mi:ss')"; //$NON-NLS-1$ //$NON-NLS-2$
+               }
+               // use the default (upper type)
+               return super.quote(string, type, typeString);
+       }
+
+       /* (non-Javadoc)
+        * @see com.quantum.adapters.DatabaseAdapter#filterTableName(java.lang.String)
+        */
+       public String filterTableName(String tableName) {
+               // If there is no mixed case, better not quote, it's prettier on display
+               if (tableName.equals(tableName.toUpperCase())) return tableName;
+               // We quote the table name (and only the table name) because it has mixed case
+               if (QuantumUtil.getSchemaName(tableName).equals(""))
+                       return "\"" + tableName +"\""; //$NON-NLS-1$
+               else
+                       return QuantumUtil.getSchemaName(tableName) + ".\"" + 
+                                       QuantumUtil.getTableName(tableName) + "\"";
+}
+
+    /**
+     * The default schema for Oracle is the upper-case userid.
+     * @see com.quantum.adapters.DatabaseAdapter#getDefaultSchema(java.lang.String)
+     */
+    public String getDefaultSchema(String userid) {
+        return super.getDefaultSchema(userid).toUpperCase();
+    }
+  
+
+}
\ No newline at end of file