KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > triactive > jdo > store > SAPDBAdapter


1 /*
2  * Copyright 2003 (C) TJDO.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the TJDO License version 1.0.
6  * See the terms of the TJDO License in the documentation provided with this software.
7  *
8  * $Id: SAPDBAdapter.java,v 1.2 2004/03/22 04:58:13 jackknifebarber Exp $
9  */

10
11 package com.triactive.jdo.store;
12
13 import java.math.BigInteger JavaDoc;
14 import java.sql.DatabaseMetaData JavaDoc;
15 import java.sql.ResultSet JavaDoc;
16 import java.sql.Types JavaDoc;
17 import java.util.ArrayList JavaDoc;
18
19
20 /**
21  * Provides methods for adapting SQL language elements to the SAP DB
22  * database.
23  *
24  * @author <a HREF="mailto:mmartin5@austin.rr.com">Mike Martin</a>
25  * @version $Revision: 1.2 $
26  *
27  * @see DatabaseAdapter
28  */

29
30 class SAPDBAdapter extends DatabaseAdapter
31 {
32     /**
33      * Constructs an SAP DB adapter based on the given JDBC metadata.
34      *
35      * @param metadata the database metadata.
36      */

37
38     protected SAPDBAdapter(DatabaseMetaData JavaDoc metadata)
39     {
40         super(metadata);
41     }
42
43     public String JavaDoc getVendorID()
44     {
45         return "sapdb";
46     }
47
48     public TypeInfo newTypeInfo(ResultSet JavaDoc rs)
49     {
50         TypeInfo ti = new SAPDBTypeInfo(rs);
51
52         /*
53          * Exclude VARBINARY so it doesn't get used, at least not in auto-
54          * creation. It equates to VARCHAR() BYTE, which has a problem (as of
55          * 7.4.3) in that the returned column data gets trailing nulls appended
56          * to it up to the column's maximum length, meaning the original length
57          * is effectively lost.
58          */

59         if (ti.dataType == Types.VARBINARY)
60             return null;
61
62         return ti;
63     }
64
65     public boolean supportsAlterTableDropConstraint()
66     {
67         return false;
68     }
69
70     public boolean supportsBooleanComparison()
71     {
72         return false;
73     }
74
75     public boolean supportsDeferredConstraints()
76     {
77         return false;
78     }
79
80     public TableExpression newTableExpression(QueryStatement qs, Table table, SQLIdentifier rangeVar)
81     {
82         return new TableExprAsJoins(qs, table, rangeVar);
83     }
84
85     public String JavaDoc getAddPrimaryKeyStatement(SQLIdentifier pkName, PrimaryKey pk)
86     {
87         return "ALTER TABLE " + pk.getTable().getName() + " ADD " + pk;
88     }
89
90     public String JavaDoc getAddCandidateKeyStatement(SQLIdentifier ckName, CandidateKey ck)
91     {
92         return getCreateIndexStatement(ckName, new Index(ck));
93     }
94
95     public String JavaDoc getAddForeignKeyStatement(SQLIdentifier fkName, ForeignKey fk)
96     {
97         return "ALTER TABLE " + fk.getTable().getName() + " ADD " + fk;
98     }
99
100     public NumericExpression lengthMethod(CharacterExpression str)
101     {
102         ArrayList JavaDoc args = new ArrayList JavaDoc();
103         args.add(str);
104
105         return new NumericExpression("LENGTH", args);
106     }
107
108     public CharacterExpression substringMethod(CharacterExpression str,
109                                                NumericExpression begin)
110     {
111         ArrayList JavaDoc args = new ArrayList JavaDoc();
112         args.add(str);
113         args.add(begin.add(new IntegerLiteral(str.getQueryStatement(), BigInteger.ONE)));
114
115         return new CharacterExpression("SUBSTR", args);
116     }
117
118     public CharacterExpression substringMethod(CharacterExpression str,
119                                                NumericExpression begin,
120                                                NumericExpression end)
121     {
122         ArrayList JavaDoc args = new ArrayList JavaDoc();
123         args.add(str);
124         args.add(begin.add(new IntegerLiteral(str.getQueryStatement(), BigInteger.ONE)));
125         args.add(end.sub(begin));
126
127         return new CharacterExpression("SUBSTR", args);
128     }
129 }
130
Popular Tags