001: /*
002: * Copyright 2003 (C) TJDO.
003: * All rights reserved.
004: *
005: * This software is distributed under the terms of the TJDO License version 1.0.
006: * See the terms of the TJDO License in the documentation provided with this software.
007: *
008: * $Id: SAPDBAdapter.java,v 1.2 2004/03/22 04:58:13 jackknifebarber Exp $
009: */
010:
011: package com.triactive.jdo.store;
012:
013: import java.math.BigInteger;
014: import java.sql.DatabaseMetaData;
015: import java.sql.ResultSet;
016: import java.sql.Types;
017: import java.util.ArrayList;
018:
019: /**
020: * Provides methods for adapting SQL language elements to the SAP DB
021: * database.
022: *
023: * @author <a href="mailto:mmartin5@austin.rr.com">Mike Martin</a>
024: * @version $Revision: 1.2 $
025: *
026: * @see DatabaseAdapter
027: */
028:
029: class SAPDBAdapter extends DatabaseAdapter {
030: /**
031: * Constructs an SAP DB adapter based on the given JDBC metadata.
032: *
033: * @param metadata the database metadata.
034: */
035:
036: protected SAPDBAdapter(DatabaseMetaData metadata) {
037: super (metadata);
038: }
039:
040: public String getVendorID() {
041: return "sapdb";
042: }
043:
044: public TypeInfo newTypeInfo(ResultSet rs) {
045: TypeInfo ti = new SAPDBTypeInfo(rs);
046:
047: /*
048: * Exclude VARBINARY so it doesn't get used, at least not in auto-
049: * creation. It equates to VARCHAR() BYTE, which has a problem (as of
050: * 7.4.3) in that the returned column data gets trailing nulls appended
051: * to it up to the column's maximum length, meaning the original length
052: * is effectively lost.
053: */
054: if (ti.dataType == Types.VARBINARY)
055: return null;
056:
057: return ti;
058: }
059:
060: public boolean supportsAlterTableDropConstraint() {
061: return false;
062: }
063:
064: public boolean supportsBooleanComparison() {
065: return false;
066: }
067:
068: public boolean supportsDeferredConstraints() {
069: return false;
070: }
071:
072: public TableExpression newTableExpression(QueryStatement qs,
073: Table table, SQLIdentifier rangeVar) {
074: return new TableExprAsJoins(qs, table, rangeVar);
075: }
076:
077: public String getAddPrimaryKeyStatement(SQLIdentifier pkName,
078: PrimaryKey pk) {
079: return "ALTER TABLE " + pk.getTable().getName() + " ADD " + pk;
080: }
081:
082: public String getAddCandidateKeyStatement(SQLIdentifier ckName,
083: CandidateKey ck) {
084: return getCreateIndexStatement(ckName, new Index(ck));
085: }
086:
087: public String getAddForeignKeyStatement(SQLIdentifier fkName,
088: ForeignKey fk) {
089: return "ALTER TABLE " + fk.getTable().getName() + " ADD " + fk;
090: }
091:
092: public NumericExpression lengthMethod(CharacterExpression str) {
093: ArrayList args = new ArrayList();
094: args.add(str);
095:
096: return new NumericExpression("LENGTH", args);
097: }
098:
099: public CharacterExpression substringMethod(CharacterExpression str,
100: NumericExpression begin) {
101: ArrayList args = new ArrayList();
102: args.add(str);
103: args.add(begin.add(new IntegerLiteral(str.getQueryStatement(),
104: BigInteger.ONE)));
105:
106: return new CharacterExpression("SUBSTR", args);
107: }
108:
109: public CharacterExpression substringMethod(CharacterExpression str,
110: NumericExpression begin, NumericExpression end) {
111: ArrayList args = new ArrayList();
112: args.add(str);
113: args.add(begin.add(new IntegerLiteral(str.getQueryStatement(),
114: BigInteger.ONE)));
115: args.add(end.sub(begin));
116:
117: return new CharacterExpression("SUBSTR", args);
118: }
119: }
|