KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > jdbc > sql > InstantDbSqlDriver


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 package com.versant.core.jdbc.sql;
13
14 import com.versant.core.jdbc.metadata.*;
15 import com.versant.core.jdbc.sql.exp.SqlExp;
16 import com.versant.core.util.CharBuf;
17
18 import java.io.PrintWriter JavaDoc;
19
20 import com.versant.core.util.CharBuf;
21
22 /**
23  * A driver for Instant DB.
24  */

25 public class InstantDbSqlDriver extends SqlDriver {
26
27     /**
28      * Get the name of this driver.
29      */

30     public String JavaDoc getName() {
31         return "instantdb";
32     }
33
34     /**
35      * Does this driver use the ANSI join syntax (i.e. the join clauses appear
36      * in the from list e.g. postgres)?
37      */

38     public boolean isAnsiJoinSyntax() {
39         return true;
40     }
41
42     /**
43      * Is null a valid value for a column with a foreign key constraint?
44      */

45     public boolean isNullForeignKeyOk() {
46         return true;
47     }
48
49     /**
50      * Create a default name generator instance for JdbcStore's using this
51      * driver.
52      */

53     public JdbcNameGenerator createJdbcNameGenerator() {
54         DefaultJdbcNameGenerator n = createDefaultJdbcNameGenerator();
55         n.setMaxColumnNameLength(31);
56         n.setMaxTableNameLength(31);
57         n.setMaxConstraintNameLength(31);
58         n.setMaxIndexNameLength(31);
59         return n;
60     }
61
62     /**
63      * Append the allow nulls part of the definition for a column in a
64      * create table statement.
65      */

66     protected void appendCreateColumnNulls(JdbcTable t, JdbcColumn c,
67             CharBuf s) {
68         if (c.nulls) s.append(" null");
69     }
70
71     /**
72      * Add the primary key constraint part of a create table statement to s.
73      */

74     protected void appendPrimaryKeyConstraint(JdbcTable t, CharBuf s) {
75         s.append("constraint ");
76         s.append(t.pkConstraintName);
77         s.append(" primary key (");
78         appendColumnNameList(t.pk, s);
79         s.append(')');
80     }
81
82     /**
83      * Append an 'add constraint' statement for c.
84      */

85     protected void appendRefConstraint(CharBuf s, JdbcConstraint c) {
86     }
87
88     /**
89      * Write an SQL statement to a script with appropriate separator.
90      */

91     protected void print(PrintWriter JavaDoc out, String JavaDoc sql) {
92         out.print(sql);
93         out.println(";");
94         out.println();
95     }
96
97     /**
98      * Append the from list entry for a table.
99      */

100     public void appendSqlFrom(JdbcTable table, String JavaDoc alias,
101             CharBuf s) {
102         s.append(table.name);
103         if (alias != null) {
104             s.append(" AS ");
105             s.append(alias);
106         }
107     }
108
109     /**
110      * Append the from list entry for a table that is the right hand table
111      * in a join i.e. it is being joined to.
112      * @param exp This is the expression that joins the tables
113      * @param outer If true then this is an outer join
114      */

115     public void appendSqlFromJoin(JdbcTable table, String JavaDoc alias, SqlExp exp,
116             boolean outer, CharBuf s) {
117         if (outer) s.append(" LEFT JOIN ");
118         else s.append(" JOIN ");
119         s.append(table.name);
120         if (alias != null) {
121             s.append(" AS ");
122             s.append(alias);
123         }
124         if (exp != null) {
125             s.append(" ON (");
126             exp.appendSQL(this, s, null);
127             s.append(')');
128         }
129     }
130
131 }
132
Popular Tags