001: /*
002: * Copyright (c) 1998 - 2005 Versant Corporation
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * Versant Corporation - initial API and implementation
010: */
011: package com.versant.core.jdbc.sql;
012:
013: import com.versant.core.jdbc.metadata.*;
014: import com.versant.core.jdbc.sql.exp.SqlExp;
015: import com.versant.core.util.CharBuf;
016:
017: import java.io.PrintWriter;
018:
019: import com.versant.core.util.CharBuf;
020:
021: /**
022: * A driver for Instant DB.
023: */
024: public class InstantDbSqlDriver extends SqlDriver {
025:
026: /**
027: * Get the name of this driver.
028: */
029: public String getName() {
030: return "instantdb";
031: }
032:
033: /**
034: * Does this driver use the ANSI join syntax (i.e. the join clauses appear
035: * in the from list e.g. postgres)?
036: */
037: public boolean isAnsiJoinSyntax() {
038: return true;
039: }
040:
041: /**
042: * Is null a valid value for a column with a foreign key constraint?
043: */
044: public boolean isNullForeignKeyOk() {
045: return true;
046: }
047:
048: /**
049: * Create a default name generator instance for JdbcStore's using this
050: * driver.
051: */
052: public JdbcNameGenerator createJdbcNameGenerator() {
053: DefaultJdbcNameGenerator n = createDefaultJdbcNameGenerator();
054: n.setMaxColumnNameLength(31);
055: n.setMaxTableNameLength(31);
056: n.setMaxConstraintNameLength(31);
057: n.setMaxIndexNameLength(31);
058: return n;
059: }
060:
061: /**
062: * Append the allow nulls part of the definition for a column in a
063: * create table statement.
064: */
065: protected void appendCreateColumnNulls(JdbcTable t, JdbcColumn c,
066: CharBuf s) {
067: if (c.nulls)
068: s.append(" null");
069: }
070:
071: /**
072: * Add the primary key constraint part of a create table statement to s.
073: */
074: protected void appendPrimaryKeyConstraint(JdbcTable t, CharBuf s) {
075: s.append("constraint ");
076: s.append(t.pkConstraintName);
077: s.append(" primary key (");
078: appendColumnNameList(t.pk, s);
079: s.append(')');
080: }
081:
082: /**
083: * Append an 'add constraint' statement for c.
084: */
085: protected void appendRefConstraint(CharBuf s, JdbcConstraint c) {
086: }
087:
088: /**
089: * Write an SQL statement to a script with appropriate separator.
090: */
091: protected void print(PrintWriter out, String sql) {
092: out.print(sql);
093: out.println(";");
094: out.println();
095: }
096:
097: /**
098: * Append the from list entry for a table.
099: */
100: public void appendSqlFrom(JdbcTable table, String alias, CharBuf s) {
101: s.append(table.name);
102: if (alias != null) {
103: s.append(" AS ");
104: s.append(alias);
105: }
106: }
107:
108: /**
109: * Append the from list entry for a table that is the right hand table
110: * in a join i.e. it is being joined to.
111: * @param exp This is the expression that joins the tables
112: * @param outer If true then this is an outer join
113: */
114: public void appendSqlFromJoin(JdbcTable table, String alias,
115: SqlExp exp, boolean outer, CharBuf s) {
116: if (outer)
117: s.append(" LEFT JOIN ");
118: else
119: s.append(" JOIN ");
120: s.append(table.name);
121: if (alias != null) {
122: s.append(" AS ");
123: s.append(alias);
124: }
125: if (exp != null) {
126: s.append(" ON (");
127: exp.appendSQL(this , s, null);
128: s.append(')');
129: }
130: }
131:
132: }
|