001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.sql.framework.model.impl;
042:
043: import java.util.HashMap;
044: import java.util.Iterator;
045: import java.util.Map;
046:
047: import org.netbeans.modules.sql.framework.model.RuntimeOutput;
048: import org.netbeans.modules.sql.framework.model.SQLCondition;
049: import org.netbeans.modules.sql.framework.model.SQLConstants;
050: import org.netbeans.modules.sql.framework.model.SQLDBColumn;
051: import org.netbeans.modules.sql.framework.model.SQLLiteral;
052: import org.netbeans.modules.sql.framework.model.SQLObject;
053: import org.netbeans.modules.sql.framework.model.TargetColumn;
054:
055: import com.sun.sql.framework.exception.BaseException;
056: import com.sun.sql.framework.utils.RuntimeAttribute;
057: import org.netbeans.modules.sql.framework.model.DBTable;
058:
059: /**
060: * @author radval
061: */
062: public class RuntimeOutputImpl extends TargetTableImpl implements
063: RuntimeOutput {
064:
065: private static final String ATTR_BATCHSIZE = "batchSize";
066:
067: /** Creates a new instance of OutputTableImpl */
068: public RuntimeOutputImpl() {
069: super ();
070: init();
071: }
072:
073: /**
074: * New instance
075: *
076: * @param src - src
077: */
078: public RuntimeOutputImpl(DBTable src) {
079: super (src);
080: init();
081: }
082:
083: public Map getRuntimeAttributeMap() {
084: Map<String, RuntimeAttribute> inputAttrs = new HashMap<String, RuntimeAttribute>();
085:
086: Iterator attrIter = getColumnList().iterator();
087: while (attrIter.hasNext()) {
088: SQLDBColumn col = (SQLDBColumn) attrIter.next();
089: final String varName = col.getName();
090: final String defaultValue = col.getDefaultValue();
091: int jdbcType = col.getJdbcType();
092:
093: RuntimeAttribute attr = new RuntimeAttribute();
094: attr.setAttributeName(varName);
095: attr.setJdbcType(jdbcType);
096: if (defaultValue != null) {
097: attr.setAttributeValue(defaultValue);
098: }
099:
100: if (col instanceof TargetColumn) {
101: TargetColumn tgtColumn = (TargetColumn) col;
102: SQLObject inputObject = tgtColumn.getValue();
103:
104: if (inputObject != null
105: && inputObject.getObjectType() == SQLConstants.VISIBLE_LITERAL) {
106: SQLLiteral literal = (SQLLiteral) inputObject;
107: attr.setAttributeValue(literal.getValue());
108: }
109: }
110: inputAttrs.put(varName, attr);
111: }
112:
113: return inputAttrs;
114: }
115:
116: /**
117: * Returns XML representation of table metadata.
118: *
119: * @param prefix prefix for the xml.
120: * @param tableOnly flag for generating table only metadata.
121: * @return XML representation of the table metadata.
122: * @exception BaseException - exception
123: */
124: @Override
125: public String toXMLString(String prefix, boolean tableOnly)
126: throws BaseException {
127: StringBuilder xml = new StringBuilder(INIT_XMLBUF_SIZE);
128:
129: xml.append(prefix).append("<").append(TAG_RUNTIME_OUTPUT);
130: xml.append(" ").append(TABLE_NAME_ATTR).append("=\"").append(
131: name).append("\"");
132:
133: xml.append(" ").append(ID_ATTR).append("=\"").append(id)
134: .append("\"");
135:
136: if (displayName != null && displayName.trim().length() != 0) {
137: xml.append(" ").append(DISPLAY_NAME_ATTR).append("=\"")
138: .append(displayName).append("\"");
139: }
140:
141: xml.append(">\n");
142:
143: xml.append(toXMLAttributeTags(prefix));
144:
145: if (!tableOnly) {
146: writeColumns(prefix, xml);
147: }
148:
149: if (guiInfo != null) {
150: xml.append(guiInfo.toXMLString(prefix + INDENT));
151: }
152:
153: xml.append(prefix).append("</").append(TAG_RUNTIME_OUTPUT)
154: .append(">\n");
155:
156: return xml.toString();
157: }
158:
159: /**
160: * Gets String representing tag name for this table class.
161: *
162: * @return String representing element tag for this class
163: */
164: @Override
165: protected String getElementTagName() {
166: return TAG_RUNTIME_OUTPUT;
167: }
168:
169: private void init() {
170: type = SQLConstants.RUNTIME_OUTPUT;
171: this .setName(TAG_RUNTIME_OUTPUT);
172: }
173:
174: @Override
175: public void setHavingCondition(SQLCondition cond) {
176:
177: }
178:
179: @Override
180: public void setBatchSize(Integer newsize) {
181: this.setAttribute(ATTR_BATCHSIZE, newsize);
182: }
183: }
|