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.mashup.db.model;
042:
043: import java.sql.Connection;
044: import java.util.Collections;
045: import java.util.List;
046: import java.util.Properties;
047: import java.util.UUID;
048:
049: import org.netbeans.modules.etl.model.ETLObject;
050: import org.netbeans.modules.etl.model.impl.ETLObjectImpl;
051: import org.netbeans.modules.mashup.db.model.impl.FlatfileDatabaseModelImpl;
052: import org.netbeans.modules.sql.framework.model.DBConnectionDefinition;
053: import org.netbeans.modules.sql.framework.model.DBTable;
054: import org.netbeans.modules.sql.framework.model.JDBCConnectionProvider;
055:
056: /**
057: * @author Jonathan Giron
058: * @version $Revision$
059: */
060: public class FlatfileDefinition extends ETLObjectImpl implements
061: ETLObject, JDBCConnectionProvider {
062:
063: /* Database metadata model storing record/column formatting for underlying Flatfile DB */
064: private FlatfileDatabaseModelImpl modelImpl;
065:
066: /**
067: * Constructs a default instance of FlatfileDefinition.
068: */
069: public FlatfileDefinition() {
070: super (null);
071: }
072:
073: /**
074: * Constructs a new instance of FlatfileDefinition with the given name.
075: *
076: * @param name the name
077: */
078: public FlatfileDefinition(String name) {
079: super (name);
080: }
081:
082: /**
083: * @see org.netbeans.modules.mashup.db.model.FlatfileDefinition#getMetadataSourceOID
084: */
085: public String getMetadataSourceOID() {
086: return UUID.randomUUID().toString();
087: }
088:
089: public String getInstanceName() {
090: return null;
091: }
092:
093: public void setInstanceName(String newName) {
094: }
095:
096: /**
097: * @see org.netbeans.modules.model.database.DatabaseModel#getModelName
098: */
099: public String getModelName() {
100: if (modelImpl == null) {
101: createDatabaseModel();
102: }
103:
104: if (modelImpl != null) {
105: return modelImpl.getModelName();
106: }
107: String name = null;
108:
109: return name;
110: }
111:
112: /**
113: * @see org.netbeans.modules.model.database.DatabaseModel#getModelName
114: */
115: public String getModelDescription() {
116: if (modelImpl == null) {
117: createDatabaseModel();
118: }
119:
120: return (modelImpl != null) ? modelImpl.getModelDescription()
121: : "";
122: }
123:
124: /**
125: * Gets associated DBConnectionDefinition
126: *
127: * @return DBConnectionDefinition
128: */
129: public DBConnectionDefinition getConnectionDefinition() {
130: if (modelImpl == null) {
131: createDatabaseModel();
132: }
133:
134: return (modelImpl != null) ? modelImpl
135: .getConnectionDefinition() : null;
136: }
137:
138: /**
139: * @see org.netbeans.modules.model.database.DatabaseModel#getFullyQualifiedTableName(DBTable)
140: */
141: public String getFullyQualifiedTableName(DBTable tbl) {
142: if (modelImpl == null) {
143: createDatabaseModel();
144: }
145:
146: return (modelImpl != null) ? modelImpl
147: .getFullyQualifiedTableName(tbl) : "";
148: }
149:
150: /**
151: * @see org.netbeans.modules.model.database.DatabaseModel#getFullyQualifiedTableName(String,String,String)
152: */
153: public String getFullyQualifiedTableName(String table,
154: String schema, String catalog) {
155: if (modelImpl == null) {
156: createDatabaseModel();
157: }
158:
159: return (modelImpl != null) ? modelImpl
160: .getFullyQualifiedTableName(table, schema, catalog)
161: : "";
162: }
163:
164: /**
165: * @see org.netbeans.modules.model.database.DatabaseModel#getSource()
166: */
167: public Object getSource() {
168: return this ;
169: }
170:
171: /**
172: * @see org.netbeans.modules.model.database.DatabaseModel#getTable(String)
173: */
174: public DBTable getTable(String fqTableName) {
175: if (modelImpl == null) {
176: createDatabaseModel();
177: }
178:
179: return (modelImpl != null) ? modelImpl.getTable(fqTableName)
180: : null;
181: }
182:
183: /**
184: * @see org.netbeans.modules.model.database.DatabaseModel#getTable
185: */
186: public DBTable getTable(String tableName, String schemaName,
187: String catalogName) {
188: if (modelImpl == null) {
189: createDatabaseModel();
190: }
191:
192: return (modelImpl != null) ? modelImpl.getTable(tableName,
193: schemaName, catalogName) : null;
194: }
195:
196: /**
197: * @see org.netbeans.modules.model.database.DatabaseModel#getTables
198: */
199: public List getTables() {
200: if (modelImpl == null) {
201: createDatabaseModel();
202: }
203:
204: return (modelImpl != null) ? modelImpl.getTables()
205: : Collections.EMPTY_LIST;
206: }
207:
208: private void createDatabaseModel() {
209:
210: }
211:
212: /**
213: * @return Returns the modelImpl.
214: */
215: public FlatfileDatabaseModel getFlatfileDatabaseModel() {
216: if (modelImpl == null) {
217: createDatabaseModel();
218: }
219:
220: return modelImpl;
221: }
222:
223: /**
224: * @param modelImpl The modelImpl to set.
225: */
226: public void setFlatfileDatabaseModel(
227: FlatfileDatabaseModel theModelImpl) {
228: this .modelImpl = (FlatfileDatabaseModelImpl) theModelImpl;
229: this .modelImpl.setSource(this );
230: }
231:
232: /**
233: * @see org.netbeans.modules.model.database.JDBCConnectionProvider#getJDBCDriverClassNames()
234: */
235: public List getJDBCDriverClassNames() throws Exception {
236: if (modelImpl == null) {
237: createDatabaseModel();
238: }
239:
240: if (modelImpl != null) {
241: return modelImpl.getJDBCDriverClassNames();
242: }
243:
244: throw new Exception(
245: "Could not create DatabaseModel implementation for FlatfileDB Database");
246: }
247:
248: /**
249: * @see org.netbeans.modules.model.database.JDBCConnectionProvider#getJDBCDriverClassName()
250: */
251: public String getJDBCDriverClassName() throws Exception {
252: if (modelImpl == null) {
253: createDatabaseModel();
254: }
255:
256: if (modelImpl != null) {
257: return modelImpl.getJDBCDriverClassName();
258: }
259:
260: throw new Exception(
261: "Could not create DatabaseModel implementation for FlatfileDB Database");
262: }
263:
264: /**
265: * @see org.netbeans.modules.model.database.JDBCConnectionProvider#getJDBCDriverType()
266: */
267: public int getJDBCDriverType() throws Exception {
268: if (modelImpl == null) {
269: createDatabaseModel();
270: }
271:
272: if (modelImpl != null) {
273: return modelImpl.getJDBCDriverType();
274: }
275:
276: throw new Exception(
277: "Could not create DatabaseModel implementation for FlatfileDB Database");
278: }
279:
280: /**
281: * @see org.netbeans.modules.model.database.JDBCConnectionProvider#getJDBCDriverTypes(java.lang.String)
282: */
283: public int getJDBCDriverTypes(String className) throws Exception {
284: if (modelImpl == null) {
285: createDatabaseModel();
286: }
287:
288: if (modelImpl != null) {
289: return modelImpl.getJDBCDriverTypes(className);
290: }
291:
292: throw new Exception(
293: "Could not create DatabaseModel implementation for FlatfileDB Database");
294: }
295:
296: /**
297: * @see org.netbeans.modules.model.database.JDBCConnectionProvider#getJDBCConnection()
298: */
299: public Connection getJDBCConnection() throws Exception {
300: if (modelImpl == null) {
301: createDatabaseModel();
302: }
303:
304: if (modelImpl != null) {
305: return modelImpl.getJDBCConnection();
306: }
307:
308: throw new Exception(
309: "Could not create DatabaseModel implementation for FlatfileDB Database");
310:
311: }
312:
313: /**
314: * @see org.netbeans.modules.model.database.JDBCConnectionProvider#getJDBCConnection(java.lang.ClassLoader)
315: */
316: public Connection getJDBCConnection(ClassLoader cl)
317: throws Exception {
318: if (modelImpl == null) {
319: createDatabaseModel();
320: }
321:
322: if (modelImpl != null) {
323: return modelImpl.getJDBCConnection(cl);
324: }
325:
326: throw new Exception(
327: "Could not create DatabaseModel implementation for FlatfileDB Database");
328: }
329:
330: /**
331: * @see org.netbeans.modules.model.database.JDBCConnectionProvider#getJDBCConnection(java.util.Properties)
332: */
333: public Connection getJDBCConnection(Properties connProps)
334: throws Exception {
335: if (connProps == null) {
336: throw new IllegalArgumentException(
337: "connProps argument is null!");
338: }
339:
340: if (modelImpl == null) {
341: createDatabaseModel();
342: }
343:
344: if (modelImpl != null) {
345: return modelImpl.getJDBCConnection(connProps);
346: }
347:
348: throw new Exception(
349: "Could not create DatabaseModel implementation for FlatfileDB Database");
350: }
351:
352: /**
353: * @see org.netbeans.modules.model.database.JDBCConnectionProvider#getJDBCConnection(java.util.Properties,
354: * java.lang.ClassLoader)
355: */
356: public Connection getJDBCConnection(Properties connProps,
357: ClassLoader cl) throws Exception {
358: if (connProps == null) {
359: throw new IllegalArgumentException(
360: "connProps argument is null!");
361: }
362:
363: if (modelImpl == null) {
364: createDatabaseModel();
365: }
366:
367: if (modelImpl != null) {
368: return modelImpl.getJDBCConnection(connProps, cl);
369: }
370:
371: throw new Exception(
372: "Could not create DatabaseModel implementation for FlatfileDB Database");
373: }
374:
375: /**
376: * @see org.netbeans.modules.model.database.JDBCConnectionProvider#getJDBCConnection(java.lang.String,
377: * java.lang.String, java.lang.String)
378: */
379: public Connection getJDBCConnection(String jdbcUrl, String uid,
380: String passwd) throws Exception {
381: if (modelImpl == null) {
382: createDatabaseModel();
383: }
384:
385: if (modelImpl != null) {
386: return modelImpl.getJDBCConnection(jdbcUrl, uid, passwd);
387: }
388:
389: throw new Exception(
390: "Could not create DatabaseModel implementation for FlatfileDB Database");
391: }
392:
393: /**
394: * @see org.netbeans.modules.model.database.JDBCConnectionProvider#getJDBCConnection(java.lang.String,
395: * java.lang.String, java.lang.String, java.lang.ClassLoader)
396: */
397: public Connection getJDBCConnection(String jdbcUrl, String uid,
398: String passwd, ClassLoader cl) throws Exception {
399: if (modelImpl == null) {
400: createDatabaseModel();
401: }
402:
403: if (modelImpl != null) {
404: return modelImpl
405: .getJDBCConnection(jdbcUrl, uid, passwd, cl);
406: }
407:
408: throw new Exception(
409: "Could not create DatabaseModel implementation for FlatfileDB Database");
410: }
411: }
|