preparing new release
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / adapters / OracleAdapter.java
1 package com.quantum.adapters;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6 import com.quantum.Messages;
7 import com.quantum.util.QuantumUtil;
8
9
10
11 public class OracleAdapter extends DatabaseAdapter {
12         protected OracleAdapter() {
13                 super(AdapterFactory.ORACLE);
14         }
15         public String getShowSequenceQuery(String qualifier) {
16         return "SELECT SEQUENCE_OWNER, SEQUENCE_NAME FROM ALL_SEQUENCES WHERE SEQUENCE_OWNER = '" + qualifier + "'"; //$NON-NLS-1$
17         }
18         public String getPrevValue(String sequence, String owner) {
19         return "SELECT " + getQualifiedName(owner, sequence) + ".CURRVAL FROM DUAL";
20         }
21         public String getNextValue(String sequence, String owner) {
22                 return "SELECT " + getQualifiedName(owner, sequence) + ".NEXTVAL FROM DUAL";
23         }
24         public String getCommentsQuery(String tableName, String column) {
25                 String query = "SELECT COMMENTS FROM ALL_COL_COMMENTS WHERE TABLE_NAME = '"; 
26                 query += QuantumUtil.getTableName(tableName) + "' AND COLUMN_NAME = '" + column + "'" ;
27                 if (!(QuantumUtil.getSchemaName(tableName).equals("")))
28                         query += " AND OWNER = '" + QuantumUtil.getSchemaName(tableName) + "'";
29                 return query;
30         }
31         /**
32          * Quotes a string according to the type of the column 
33          * @param string to be quoted
34          * @param type according to java.sql.Types
35          * @return
36          */
37         public String quote(String string, int type, String typeString) {
38                 if (type == java.sql.Types.DATE || type == java.sql.Types.TIMESTAMP) {
39                         string = string.trim();
40                         // Eliminate the fractions of seconds, if present
41                         if (string.length() > 1) {
42                                 // If the third character from the end is a dot, it means it has fractions
43                                 String sub = string.substring(string.length()-2, string.length()-1);
44                                 if ( sub.equals(Messages.getString("."))) //$NON-NLS-1$
45                                         string = string.substring(0,string.length()-2);
46                         }
47                         return "TO_DATE('" + string + "','yyyy-mm-dd hh24:mi:ss')"; //$NON-NLS-1$ //$NON-NLS-2$
48                 }
49                 // use the default (upper type)
50                 return super.quote(string, type, typeString);
51         }
52
53         /* (non-Javadoc)
54          * @see com.quantum.adapters.DatabaseAdapter#filterTableName(java.lang.String)
55          */
56         public String filterTableName(String tableName) {
57                 // If there is no mixed case, better not quote, it's prettier on display
58                 if (tableName.equals(tableName.toUpperCase())) return tableName;
59                 // We quote the table name (and only the table name) because it has mixed case
60                 if (QuantumUtil.getSchemaName(tableName).equals(""))
61                         return "\"" + tableName +"\""; //$NON-NLS-1$
62                 else
63                         return QuantumUtil.getSchemaName(tableName) + ".\"" + 
64                                         QuantumUtil.getTableName(tableName) + "\"";
65 }
66
67     /**
68      * The default schema for Oracle is the upper-case userid.
69      * @see com.quantum.adapters.DatabaseAdapter#getDefaultSchema(java.lang.String)
70      */
71     public String getDefaultSchema(String userid) {
72         return super.getDefaultSchema(userid).toUpperCase();
73     }
74     
75     public Map getDefaultConnectionParameters() {
76         Map map = new HashMap();
77         map.put("port", "1521");
78         map.put("hostname", "localhost");
79         return map;
80     }
81     
82
83         /* (non-Javadoc)
84          * @see com.quantum.adapters.DatabaseAdapter#getShowSynonymsQuery(java.lang.String, java.lang.String)
85          */
86         public String getShowSynonymsQuery(String schema, String type) {
87                 // The type string is the same as the one needed by Oracle. If it changes a switch would be needed.
88                 return "select SYNONYM_NAME from ALL_SYNONYMS, ALL_OBJECTS where " +
89                                 " ALL_SYNONYMS.OWNER = '" + schema + "'" +
90                                 " and ALL_SYNONYMS.TABLE_OWNER = ALL_OBJECTS.OWNER" +
91                                 " and ALL_SYNONYMS.TABLE_NAME = ALL_OBJECTS.OBJECT_NAME" + 
92                                 " and ALL_OBJECTS.OBJECT_TYPE = '" + type + "'" ;
93                 }
94 }