KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > extractor > Extractor


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

22
23 package org.xquark.extractor;
24
25 import java.io.File JavaDoc;
26 import java.io.PrintWriter JavaDoc;
27 import java.net.MalformedURLException JavaDoc;
28 import java.sql.Connection JavaDoc;
29 import java.sql.DatabaseMetaData JavaDoc;
30 import java.sql.SQLException JavaDoc;
31 import java.util.*;
32
33 import javax.naming.InitialContext JavaDoc;
34 import javax.naming.NamingException JavaDoc;
35 import javax.sql.DataSource JavaDoc;
36
37 import org.apache.commons.collections.map.LRUMap;
38 import org.xquark.extractor.common.Constants;
39 import org.xquark.extractor.common.MessageLibrary;
40 import org.xquark.extractor.metadata.*;
41 import org.xquark.extractor.runtime.ExtractorConfiguration;
42 import org.xquark.extractor.runtime.Selection;
43 import org.xquark.jdbc.datasource.JDBCDataSource;
44 import org.xquark.jdbc.datasource.JDBCDataSourceFactory;
45 import org.xquark.jdbc.datasource.SingleConnectionDataSource;
46 import org.xquark.jdbc.typing.DBMSInfoMap;
47 import org.xquark.jdbc.typing.JDBCProperties;
48 import org.xquark.xml.xdbc.*;
49 import org.xquark.xquery.ModuleManager;
50 import org.xquark.xquery.metadata.MetaDataImpl;
51
52 /**
53  * Extractor XML/DBC DataSource implementation.
54  */

55 public class Extractor implements XMLDataSource, Constants {
56
57     private static final String JavaDoc RCSRevision = "$Revision: 1.33 $";
58     private static final String JavaDoc RCSName = "$Name: $";
59
60     public static final String JavaDoc JNDI_SCHEME = "jndi:";
61     
62     static {
63         MessageLibrary.setup("org.xquark.extractor.common.resources.MessageLibrary", new Locale("en", "US"));
64     }
65
66     private DataSource JavaDoc dataSource = null;
67     private Properties configuration = null;
68     private MetaDataManager metaDataManager = null;
69     private MetaDataImpl metaData = null;
70     private Map cachedStatements = Collections.synchronizedMap(new LRUMap(100));
71
72     private String JavaDoc name = "Extractor";
73     // TODO: check if this should not go somewhere else
74
private boolean useScrollableResultSets = false;
75     private String JavaDoc configURI = null;
76     private String JavaDoc userName = null;
77     private String JavaDoc databaseName = null;
78     private String JavaDoc databaseVersion = null;
79         
80     /**
81      * Constructor to use with a configuration file URL or a JNDI name
82      * referencing a JDBC datasource instance. The configuration file is
83      * expected to contain JDBC connection parameters or a JNDI name. Choose
84      * this last solution if you both need to specify a configuration file and a
85      * JNDI name. See the <em>XQuery Language Reference Guide"</em> for more
86      * information about configuration files.
87      *
88      * @param URI
89      * either the configuration file URL, or a JNDI reference that
90      * MUST be prefixed with the "jndi:" string to be recognized as
91      * this.
92      * @throws XMLDBCException
93      * API exception
94      */

95     public Extractor(String JavaDoc URI) throws XMLDBCException {
96         this(URI, null);
97     }
98     
99     /**
100      * Use this constructor when you need a specific classloader that will be
101      * used to load JDBC drivers.
102      *
103      * @param URI
104      * either a file URL, or a JNDI reference that MUST be prefixed
105      * with the "jndi:" string to be recognized as this.
106      * @param loader
107      * an application-provided class loader that will be used to load
108      * JDBC drivers.
109      * @throws XMLDBCException
110      * API exception
111      * @see #Extractor(String)
112      */

113     public Extractor(String JavaDoc URI, ClassLoader JavaDoc loader) throws XMLDBCException {
114         if (URI.startsWith(JNDI_SCHEME))
115             initDataSource(getJNDIDataSource(URI.substring(JNDI_SCHEME.length())));
116         else
117             initDataSource(URI, loader);
118     }
119     
120     /**
121      * Constructor to use with an extractor configuration file. See the
122      * <em>XQuery Language Reference Guide</em> for more information about
123      * configuration files.
124      *
125      * @param configFile
126      * a Java symbolic file.
127      * @throws XMLDBCException
128      * API exception
129      */

130     public Extractor(File JavaDoc configFile) throws XMLDBCException {
131         this(configFile, null);
132     }
133     
134     /**
135      * Use this constructor when you need a specific classloader that will be
136      * used to load JDBC drivers.
137      *
138      * @param configFile
139      * a Java symbolic file
140      * @param loader
141      * an application-provided class loader that will be used to load
142      * JDBC drivers.
143      * @throws XMLDBCException
144      * API exception
145      * @see #Extractor(File)
146      */

147     public Extractor(File JavaDoc configFile, ClassLoader JavaDoc loader)
148     throws XMLDBCException {
149         try {
150             String JavaDoc configURI = configFile.toURL().toString();
151             initDataSource(configURI, loader);
152         }
153         catch (MalformedURLException JavaDoc e) {
154             throw new XMLDBCException("Invalid configuration file name " + configFile, e);
155         }
156     }
157     
158     /**
159      * Constructor to use with a JDBC data source.
160      *
161      * @param ds
162      * a JDBC data source.
163      * @throws XMLDBCException
164      * API exception
165      */

166     public Extractor(DataSource JavaDoc ds) throws XMLDBCException {
167         initDataSource(ds);
168     }
169
170     /**
171      * Constructor to use with a JDBC data source and an extractor configuration
172      * file URL. See the <em>XQuery Language Reference Guide</em> for more
173      * information about configuration files.
174      *
175      * @param ds
176      * a JDBC data source.
177      * @param configURL
178      * the URL of the configuration file.
179      * @throws XMLDBCException
180      * API exception
181      */

182     public Extractor(DataSource JavaDoc ds, String JavaDoc configURL) throws XMLDBCException {
183         if (configURI != null)
184             initDataSource(ds, configURI);
185         else
186             initDataSource(ds);
187     }
188
189     /**
190      * Constructor to use with a JDBC data source and an extractor configuration
191      * file. See the <em>XQuery Language Reference Guide</em> for more
192      * information about configuration files.
193      *
194      * @param ds
195      * a JDBC data source.
196      * @param configFile
197      * a Java symbolic file
198      * @throws XMLDBCException
199      * API exception
200      */

201     public Extractor(DataSource JavaDoc ds, File JavaDoc configFile) throws XMLDBCException {
202         if (configFile != null) {
203             try {
204                 String JavaDoc configURI = configFile.toURL().toString();
205                 initDataSource(ds, configURI);
206             }
207             catch (MalformedURLException JavaDoc e) {
208                 throw new XMLDBCException("Invalid configuration file name " + configFile, e);
209             }
210         }
211         else
212             initDataSource(ds);
213     }
214
215     /**
216      * Construction to use when JDBC connection parameters are available.
217      *
218      * @param jdbcURL
219      * the JDBC URL of the JDBC data source.
220      * @param username
221      * the login name for the JDBC data source.
222      * @param password
223      * the password for the login name.
224      * @throws XMLDBCException
225      * API exception
226      */

227     public Extractor(String JavaDoc jdbcURL, String JavaDoc username, String JavaDoc password) throws XMLDBCException {
228         JDBCDataSourceFactory dsFactory = JDBCDataSourceFactory.newInstance();
229         try {
230             initDataSource(dsFactory.newDataSource(jdbcURL, username, password));
231         }
232         catch (SQLException JavaDoc ex) {
233             throw new XMLDBCException("Error while accessing datasource "
234                     + username+ '@' + jdbcURL, ex);
235         }
236     }
237     
238     /**
239      * Use this constructor when you need a specific classloader that will be
240      * used to load JDBC drivers.
241      *
242      * @param jdbcURL
243      * the JDBC URL of the JDBC data source.
244      * @param username
245      * the login name for the JDBC data source.
246      * @param password
247      * the password for the login name.
248      * @param loader
249      * an application-provided class loader that will be used to load
250      * JDBC drivers.
251      * @throws XMLDBCException
252      * API exception
253      * @see #Extractor(String, String, String)
254      */

255     public Extractor(String JavaDoc jdbcURL, String JavaDoc username, String JavaDoc password, ClassLoader JavaDoc loader)
256     throws XMLDBCException {
257         JDBCDataSourceFactory dsFactory = JDBCDataSourceFactory.newInstance(loader);
258         try {
259             initDataSource(dsFactory.newDataSource(jdbcURL, username, password));
260         }
261         catch (SQLException JavaDoc ex) {
262             throw new XMLDBCException("Error while accessing datasource "
263                     + username + '@' + jdbcURL, ex);
264         }
265     }
266     
267     /**
268      * Constructs an Extractor using a single JDBC connection. This connection
269      * should not be used while the XQBridge object is active.
270      *
271      * @param jdbcConnection
272      * a jdbc connection.
273      * @throws XMLDBCException
274      * API exception
275      * @deprecated prevents the use of an external or internal data source.
276      */

277     public Extractor(Connection JavaDoc jdbcConnection) throws XMLDBCException {
278         this(jdbcConnection, null);
279     }
280     
281     /**
282      * Constructs an Extractor using a single JDBC connection and a
283      * configuration file. The connection should not be used while the
284      * XQBridge object is active.
285      *
286      * @param jdbcConnection
287      * a jdbc connection.
288      * @param configURL
289      * the URL of the configuration file.
290      * @throws XMLDBCException
291      * API exception
292      * @deprecated prevents the use of an external or internal data source.
293      */

294     public Extractor(Connection JavaDoc jdbcConnection, String JavaDoc configURL) throws XMLDBCException {
295         this(jdbcConnection, configURL, null);
296     }
297
298     /**
299      * Use this constructor when you need a specific classloader that will be
300      * used to load JDBC drivers.
301      *
302      * @param jdbcConnection
303      * a jdbc connection.
304      * @param configURL
305      * the URL of the configuration file.
306      * @param loader
307      * an application-provided class loader that will be used to load
308      * JDBC drivers.
309      * @throws XMLDBCException
310      * API exception
311      * @deprecated prevents the use of an external or internal data source.
312      * @see #Extractor(Connection, String)
313      */

314     public Extractor(Connection JavaDoc jdbcConnection, String JavaDoc configURL, ClassLoader JavaDoc loader)
315     throws XMLDBCException {
316         try {
317             if (jdbcConnection == null)
318                 initDataSource(configURL, loader);
319             else if (configURL != null)
320                 initDataSource(new SingleConnectionDataSource(jdbcConnection), configURL);
321             else
322                 initDataSource(new SingleConnectionDataSource(jdbcConnection));
323         }
324         catch (SQLException JavaDoc ex) {
325             throw new XMLDBCException("Error while accessing datasource: " + ex.getMessage(), ex);
326         }
327     }
328     
329     private void initDataSource(String JavaDoc configURI, ClassLoader JavaDoc loader) throws XMLDBCException {
330         this.configURI = configURI;
331         try {
332             configuration = ExtractorConfiguration.loadConfiguration(configURI);
333         }
334         catch (MalformedURLException JavaDoc e) {
335             throw new XMLDBCException("Invalid XML/DBC URI "
336                     + ExtractorDriver.EXTRACTOR_URL_PREFIX + configURI, e);
337         }
338         if (configuration.getProperty(LABEL_SPEC_NAME) != null)
339             name = configuration.getProperty(LABEL_SPEC_NAME);
340         if (configuration.getProperty(LABEL_SPEC_JNDI) != null) {
341             dataSource = getJNDIDataSource(configuration.getProperty(LABEL_SPEC_JNDI));
342         } else {
343             String JavaDoc driver = configuration.getProperty(LABEL_SPEC_DRIVER);
344             String JavaDoc url = configuration.getProperty(LABEL_SPEC_URL);
345             String JavaDoc user = configuration.getProperty(LABEL_SPEC_USER);
346             String JavaDoc password = configuration.getProperty(LABEL_SPEC_PASSWORD);
347             Properties jdbcProps = new Properties();
348             jdbcProps.setProperty("user", user);
349             jdbcProps.setProperty("password", password);
350             JDBCDataSourceFactory dsFactory = JDBCDataSourceFactory.newInstance(loader);
351             try {
352                 dataSource = dsFactory.newDataSource(driver, url, jdbcProps);
353             } catch (SQLException JavaDoc ex) {
354                 throw new XMLDBCException("Error while creating datasource: "+ex.getMessage(), ex);
355             }
356         }
357         Connection JavaDoc jdbcConnection = null;
358         try {
359             jdbcConnection = dataSource.getConnection();
360             DatabaseMetaData JavaDoc dm = jdbcConnection.getMetaData();
361             databaseName = dm.getDatabaseProductName();
362             databaseVersion = dm.getDatabaseProductVersion();
363         } catch (SQLException JavaDoc ex) {
364             throw new XMLDBCException("Error while accessing datasource: "+ex.getMessage(), ex);
365         } finally {
366             try {
367                 if (jdbcConnection != null)
368                     jdbcConnection.close();
369             } catch (SQLException JavaDoc e) {
370             }
371         }
372     }
373     
374     private void initDataSource(DataSource JavaDoc ds) throws XMLDBCException {
375         dataSource = ds;
376         String JavaDoc url = null;
377         String JavaDoc user = null;
378         Connection JavaDoc jdbcConnection = null;
379         try {
380             jdbcConnection = ds.getConnection();
381             DatabaseMetaData JavaDoc dm = jdbcConnection.getMetaData();
382             url = dm.getURL();
383             user = dm.getUserName();
384             databaseName = dm.getDatabaseProductName();
385             databaseVersion = dm.getDatabaseProductVersion();
386             configuration = ExtractorConfiguration.getDefaultProperties(url, user);
387         } catch (SQLException JavaDoc ex) {
388             throw new XMLDBCException("Error while accessing datasource: "+ex.getMessage(), ex);
389         } finally {
390             try {
391                 if (jdbcConnection != null)
392                     jdbcConnection.close();
393             } catch (SQLException JavaDoc e) {
394             }
395         }
396     }
397
398     private void initDataSource(DataSource JavaDoc ds, String JavaDoc configURI) throws XMLDBCException {
399         dataSource = ds;
400         this.configURI = configURI;
401         try {
402             configuration = ExtractorConfiguration.loadConfiguration(configURI);
403             if (configuration.getProperty(LABEL_SPEC_NAME) != null)
404                 name = configuration.getProperty(LABEL_SPEC_NAME);
405         } catch (MalformedURLException JavaDoc e) {
406             throw new XMLDBCException("Invalid XML/DBC URI "+ExtractorDriver.EXTRACTOR_URL_PREFIX+configURI, e);
407         }
408         String JavaDoc url = null;
409         String JavaDoc user = null;
410         Connection JavaDoc jdbcConnection = null;
411         try {
412             jdbcConnection = ds.getConnection();
413             DatabaseMetaData JavaDoc dm = jdbcConnection.getMetaData();
414             url = dm.getURL();
415             user = dm.getUserName();
416             databaseName = dm.getDatabaseProductName();
417             databaseVersion = dm.getDatabaseProductVersion();
418         } catch (SQLException JavaDoc ex) {
419             throw new XMLDBCException("Error while accessing datasource: "+ex.getMessage(), ex);
420         } finally {
421             try {
422                 if (jdbcConnection != null)
423                     jdbcConnection.close();
424             } catch (SQLException JavaDoc e) {
425             }
426         }
427         if (url != null && user != null) {
428             String JavaDoc confUrl = configuration.getProperty(LABEL_SPEC_URL);
429             if (confUrl == null)
430                 configuration.setProperty(LABEL_SPEC_URL, url);
431             else if (!url.equals(confUrl))
432                 throw new XMLDBCException("Datasource and configuration file URLs do not match");
433             String JavaDoc confUser = configuration.getProperty(LABEL_SPEC_USER);
434             if (confUser == null)
435                 configuration.setProperty(LABEL_SPEC_USER, user);
436             else if (!user.equals(confUser))
437                 throw new XMLDBCException("Datasource and configuration file user names do not match");
438         }
439     }
440         
441     private DataSource JavaDoc getJNDIDataSource(String JavaDoc ref) throws XMLDBCException {
442         try {
443             InitialContext JavaDoc ctx = new InitialContext JavaDoc();
444             return (DataSource JavaDoc)ctx.lookup(ref);
445         } catch (NamingException JavaDoc e) {
446             throw new XMLDBCException("Error while locating JNDI object "+ref, e);
447         }
448     }
449     
450     /**
451      * Sets the internal JDBC datasource log writer.
452      * @param writer
453      */

454     public void setLogWriter(PrintWriter JavaDoc writer) {
455         try {
456             dataSource.setLogWriter(writer);
457         }
458         catch (SQLException JavaDoc ex) {
459         }
460     }
461
462     /**
463      * Get the internal JDBC datasource log writer.
464      * @return java.io.PrintWriter
465      */

466     public PrintWriter JavaDoc getLogWriter() {
467         try {
468             return dataSource.getLogWriter();
469         }
470         catch (SQLException JavaDoc e) {
471             return null;
472         }
473     }
474
475     /**
476      * Set the internal JDBC datasource login timeout.
477      * @param seconds the login timeout in seconds.
478      */

479     public void setLoginTimeout(int seconds) {
480         try {
481             dataSource.setLoginTimeout(seconds);
482         } catch (UnsupportedOperationException JavaDoc ex) {
483         } catch (SQLException JavaDoc ex) {
484         }
485     }
486
487     /**
488      * Get the internal JDBC datasource login timeout.
489      * @return the login timeout in seconds.
490      */

491     public int getLoginTimeout() {
492         try {
493             return dataSource.getLoginTimeout();
494         } catch (UnsupportedOperationException JavaDoc ex) {
495             return -1;
496         } catch (SQLException JavaDoc ex) {
497             return -1;
498         }
499     }
500     
501     /**
502      * Closes the extractor and the underlying resources among which the internal
503      * JDBC data source except if it was passed at construction time.
504      * @throws XMLDBCException
505      * API exception
506      */

507     public void close() throws XMLDBCException {
508         if (dataSource instanceof JDBCDataSource) {
509             try {
510                 ((JDBCDataSource)dataSource).close();
511                 dataSource = null;
512             }
513             catch (SQLException JavaDoc ex) {
514                 throw new XMLDBCException("Error while closing extractor", ex);
515             }
516         }
517     }
518
519     /**
520      * Returns the internal JDBC data source.
521      * @return the internal JDBC source.
522      */

523     public DataSource JavaDoc getJdbcDataSource() {
524         return dataSource;
525     }
526     
527     /**
528      * Creates a new XML/DBC connection instance.
529      * @return an XMLConnection to the XML/SQL datasource.
530      * @throws XMLDBCException
531      * API exception
532      */

533     public XMLConnection getConnection() throws XMLDBCException {
534         return getExtractorConnection();
535     }
536     
537     /**
538      * Creates a new XML/DBC connection instance for the extractor, avoiding
539      * a cast on {@link #getConnection()} to access Extractor specific features.
540      * @return an ExtractorConnection
541      * @throws XMLDBCException
542      * API exception
543      */

544     public ExtractorConnection getExtractorConnection() throws XMLDBCException {
545         try {
546             return new ExtractorConnection(this, dataSource.getConnection());
547         }
548         catch (SQLException JavaDoc e) {
549             throw new XMLDBCException(e.getMessage(), e);
550         }
551     }
552     
553     /**
554      * Not implemented by Extractor.
555      * @see org.xquark.xml.xdbc.XMLDataSource#getConnection(java.lang.String, java.lang.String)
556      */

557     public XMLConnection getConnection(String JavaDoc user, String JavaDoc password)
558     throws XMLDBCException {
559         throw new XMLDBCException("Unsupported operation getConnection(user, password). Use getConnection() instead.");
560     }
561
562     /**
563      * Accessor to the "use scrollable result set" option.
564      * @return true, if the extractor must use scrollable JDBC result sets.
565      */

566     public synchronized boolean useScrollableResultSets() {
567         return useScrollableResultSets;
568     }
569
570     /**
571      * To indicate the Extractor that scrollable JDBC result sets must be used.
572      * @param use a boolean.
573      */

574     public synchronized void setUseScrollableResultSets(boolean use) {
575         useScrollableResultSets = use;
576     }
577
578     /**
579      * Gets the user name used to log to the Extractor.
580      * @return a string
581      */

582     public String JavaDoc getUserName() {
583         return configuration.getProperty(LABEL_SPEC_USER);
584     }
585     
586     /**
587      * Gets the XML/DBC URL of the Extractor (XML data source).
588      * @return generally the JDBC URL prefixed with "xdbc:xquark:extractor:".
589      */

590     public String JavaDoc getURL() {
591         return ExtractorDriver.EXTRACTOR_URL_PREFIX + configuration.getProperty(LABEL_SPEC_URL);
592     }
593     
594     String JavaDoc getDatabaseName() {
595         return databaseName;
596     }
597     
598     String JavaDoc getDatabaseVersion() {
599         return databaseVersion;
600     }
601     
602     synchronized MetaDataManager getMetaDataManager(Connection JavaDoc jdbcConnection, boolean refresh) throws XMLDBCException {
603         if (refresh || metaDataManager == null) {
604             initMetaData(jdbcConnection);
605         }
606         return metaDataManager;
607     }
608     
609     synchronized MetaDataImpl getDataSourceMetaData(Connection JavaDoc jdbcConnection, boolean refresh) throws XMLDBCException {
610         if (refresh || metaData == null) {
611             initMetaData(jdbcConnection);
612         }
613         return metaData;
614     }
615     
616     Map getCachedStatements() {
617         return cachedStatements;
618     }
619     
620     private void initMetaData(Connection JavaDoc jdbcConnection) throws XMLDBCException {
621         /* create a CustomizedEncoder*/
622         CustomizedEncoder encoder = new CustomizedEncoder();
623         Properties substitutionMap = (Properties) configuration.get(LABEL_SPEC_SUBST);
624         encoder.setSubstitutionMap(substitutionMap);
625         Integer JavaDoc nameCase = (Integer JavaDoc) configuration.get(LABEL_SPEC_SUBST_NAMECASE);
626         if (null == nameCase) {
627             nameCase = new Integer JavaDoc(CASE_MIXED);
628         }
629         encoder.setNameCase(nameCase.intValue());
630         Selection selection = (Selection) configuration.get("selections");
631         if (selection != null && selection.noSubElementDef())
632             selection = null;
633
634         try {
635             metaDataManager = new MetaDataManager(DBMSInfoMap.getDBMSInfo(jdbcConnection));
636             String JavaDoc dbName = databaseName;
637             if (dbName.startsWith("Oracle")) {
638                 loadMetaDataForOracle(jdbcConnection, selection, encoder);
639             } else if (dbName.startsWith("Microsoft SQL Server")) {
640                 loadMetaDataForMicrosoftSqlServer(jdbcConnection, selection, encoder);
641             } else if (dbName.startsWith("Adaptive Server Enterprise")) {
642                 loadMetaDataForSybase(jdbcConnection, selection, encoder);
643             } else if (dbName.startsWith("PROGRESS")) {
644                 loadMetaDataForProgress(jdbcConnection, selection, encoder);
645             } else if (dbName.startsWith("MySQL")) {
646                 loadMetaDataForMySql(jdbcConnection, selection, encoder);
647             } else {
648                 throw new XMLDBCNotSupportedException(MessageLibrary.getMessage("D_N_SUP_DB_VENDOR", dbName), null);
649             }
650         } catch (SQLException JavaDoc ex) {
651             throw new XMLDBCException("Error while loading metadata", ex);
652         }
653         ModuleManager moduleManager = null;
654         if (metaData != null)
655             moduleManager = metaData.getModuleManager();
656         metaData = metaDataManager.buildMetaDataForParser(name);
657         if (moduleManager != null) {
658             for (Iterator it = moduleManager.getModules().iterator();it.hasNext();) {
659             }
660         }
661         cachedStatements.clear();
662     }
663
664     private void loadMetaDataForMicrosoftSqlServer(Connection JavaDoc jdbcConnection, Selection selection, QNameEncoder encoder)
665     throws SQLException JavaDoc
666     {
667         /* Load metadata in MetadataManager */
668         Loader metadataLoader = new org.xquark.extractor.microsoft.Loader(jdbcConnection, metaDataManager.getDbmsInfo(), encoder);
669         metaDataManager.setMetaData(metadataLoader.loadSite(selection, new JDBCProperties() {
670             public boolean useResultSet4ColumnMetadata() {
671                 return false;
672             }
673             public boolean useStaticMappingFromNativeType() {
674                 return true;
675             }
676         }));
677         // metaDataManager.setTableMap(metadataLoader._tableMap); // QUESTION : why removed ?
678
}
679
680     private void loadMetaDataForSybase(Connection JavaDoc jdbcConnection, Selection selection, QNameEncoder encoder)
681     throws SQLException JavaDoc
682     {
683         /* Load metadata in MetadataManager */
684         Loader metadataLoader = new org.xquark.extractor.sybase.Loader(jdbcConnection, metaDataManager.getDbmsInfo(), encoder);
685         metaDataManager.setMetaData(metadataLoader.loadSite(selection, new JDBCProperties() {
686             public boolean useResultSet4ColumnMetadata() {
687                 return false;
688             }
689             public boolean useStaticMappingFromNativeType() {
690                 return true;
691             }
692         }));
693         // metaDataManager.setTableMap(metadataLoader._tableMap); // QUESTION : why removed ?
694
}
695
696     private void loadMetaDataForOracle(Connection JavaDoc jdbcConnection, Selection selection, QNameEncoder encoder)
697     throws SQLException JavaDoc
698     {
699         /* Load metadata in MetadataManager */
700         Loader metadataLoader = new org.xquark.extractor.oracle.Loader(jdbcConnection, metaDataManager.getDbmsInfo(), encoder);
701         metaDataManager.setMetaData(metadataLoader.loadSite(selection, new JDBCProperties() {
702             public boolean useResultSet4ColumnMetadata() {
703                 return false;
704             }
705             public boolean useStaticMappingFromNativeType() {
706                 return true;
707             }
708         }));
709         metaDataManager.setTableMap(metadataLoader._tableMap);
710     }
711
712     private void loadMetaDataForProgress(Connection JavaDoc jdbcConnection, Selection selection, QNameEncoder encoder)
713     throws SQLException JavaDoc
714     {
715         /* Load metadata in MetadataManager */
716         Loader metadataLoader = new org.xquark.extractor.progress.Loader(jdbcConnection, metaDataManager.getDbmsInfo(), encoder);
717         metaDataManager.setMetaData(metadataLoader.loadSite(selection, new JDBCProperties() {
718             public boolean useResultSet4ColumnMetadata() {
719                 return false;
720             }
721             public boolean useStaticMappingFromNativeType() {
722                 return true;
723             }
724         }));
725         metaDataManager.setTableMap(metadataLoader._tableMap);
726     }
727
728     private void loadMetaDataForMySql(Connection JavaDoc jdbcConnection, Selection selection, QNameEncoder encoder)
729     throws SQLException JavaDoc
730     {
731         /* Load metadata in MetadataManager */
732         Loader metadataLoader = new org.xquark.extractor.mysql.Loader(jdbcConnection, metaDataManager.getDbmsInfo(), encoder);
733         metaDataManager.setMetaData(metadataLoader.loadSite(selection, new JDBCProperties() {
734             public boolean useResultSet4ColumnMetadata() {
735                 return false;
736             }
737             public boolean useStaticMappingFromNativeType() {
738                 return true;
739             }
740         }));
741         metaDataManager.setTableMap(metadataLoader._tableMap);
742     }
743
744     /**
745      * Show the configuration of the wrapper
746      */

747     void display() {
748         if (configuration == null)
749             return;
750         for (Enumeration e = configuration.propertyNames(); e.hasMoreElements();) {
751             String JavaDoc key = (String JavaDoc) e.nextElement();
752             System.out.println("[" + key + "] : [" + configuration.getProperty(key) + "]");
753         }
754     }
755     
756 }
757
Popular Tags