01: /*
02: * The contents of this file are subject to the terms of the Common Development
03: * and Distribution License (the License). You may not use this file except in
04: * compliance with the License.
05: *
06: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
07: * or http://www.netbeans.org/cddl.txt.
08: *
09: * When distributing Covered Code, include this CDDL Header Notice in each file
10: * and include the License file at http://www.netbeans.org/cddl.txt.
11: * If applicable, add the following below the CDDL Header, with the fields
12: * enclosed by brackets [] replaced by your own identifying information:
13: * "Portions Copyrighted [year] [name of copyright owner]"
14: *
15: * The Original Software is NetBeans. The Initial Developer of the Original
16: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17: * Microsystems, Inc. All Rights Reserved.
18: */
19: package org.netbeans.modules.sql.framework.codegen.db2v7;
20:
21: import org.netbeans.modules.sql.framework.codegen.StatementContext;
22: import org.netbeans.modules.sql.framework.codegen.base.BaseCaseGenerator;
23: import org.netbeans.modules.sql.framework.model.SQLCaseOperator;
24: import org.netbeans.modules.sql.framework.model.SQLObject;
25: import com.sun.sql.framework.exception.BaseException;
26:
27: /**
28: * Velocity-based generator that generates SQL Case expressions with DB2-specific syntax
29: * quirks.
30: *
31: * @author Jonathan Giron
32: * @version $Revision$
33: */
34: public class DB2V7CaseGenerator extends BaseCaseGenerator {
35:
36: /**
37: * Overrides base implementation to properly handle situation where the default action
38: * is the null oeprator.
39: *
40: * @param operator SQLCaseOperator which will be interrogated to obtain default clause
41: * @param context StatementContext to be used in evaluating default action
42: * @return DB2-specific default clause
43: */
44: @Override
45: protected String buildDefaultClause(SQLCaseOperator operator,
46: StatementContext context) throws BaseException {
47: String defaultClause = "";
48:
49: SQLObject defaultAction = operator
50: .getSQLObject(SQLCaseOperator.DEFAULT);
51: if (defaultAction != null) {
52: if ("null".equalsIgnoreCase(defaultAction.getDisplayName())) {
53: defaultClause = "NULL";
54: } else {
55: defaultClause = "("
56: + this .getDB().getGeneratorFactory().generate(
57: defaultAction, context) + ")";
58: }
59: }
60: return defaultClause;
61: }
62: }
|