Tag: cws_dev300_dba30d
User: fs      
Date: 2008-05-22 11:25:40+0000
Modified:
   dba/connectivity/qa/connectivity/tools/DataSource.java

Log:
 #i88576# +DataSource(String) / +getXDataSource / +getName

File Changes:

Directory: /dba/connectivity/qa/connectivity/tools/
===================================================

File [changed]: DataSource.java
Url: 
http://dba.openoffice.org/source/browse/dba/connectivity/qa/connectivity/tools/DataSource.java?r1=1.3&r2=1.3.20.1
Delta lines:  +45 -2
--------------------
--- DataSource.java     2008-04-10 07:47:11+0000        1.3
+++ DataSource.java     2008-05-22 11:25:38+0000        1.3.20.1
@@ -7,7 +7,7 @@
  * OpenOffice.org - a multi-platform office productivity suite
  *
  * $RCSfile: DataSource.java,v $
- * $Revision: 1.3 $
+ * $Revision: 1.3.20.1 $
  *
  * This file is part of OpenOffice.org.
  *
@@ -30,6 +30,7 @@
 
 package connectivity.tools;
 
+import com.sun.star.beans.UnknownPropertyException;
 import com.sun.star.container.ElementExistException;
 import com.sun.star.container.NoSuchElementException;
 import com.sun.star.container.XNameAccess;
@@ -41,8 +42,11 @@
 import com.sun.star.sdb.XQueryDefinitionsSupplier;
 import com.sun.star.sdbc.XDataSource;
 import com.sun.star.sdbcx.XTablesSupplier;
+import com.sun.star.uno.Exception;
 import com.sun.star.uno.UnoRuntime;
 import com.sun.star.util.XRefreshable;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 public class DataSource
 {
@@ -50,12 +54,28 @@
     XMultiServiceFactory    m_orb;
     XDataSource             m_dataSource;
 
+    public DataSource( XMultiServiceFactory _orb, String _registeredName ) 
throws Exception
+    {
+        m_orb = _orb;
+
+        XNameAccess dbContext = 
(XNameAccess)UnoRuntime.queryInterface(XNameAccess.class,
+            _orb.createInstance("com.sun.star.sdb.DatabaseContext"));
+
+        m_dataSource = 
(XDataSource)UnoRuntime.queryInterface(XDataSource.class,
+            dbContext.getByName( _registeredName ) );
+    }
+
     public DataSource( XMultiServiceFactory _orb, XDataSource _dataSource )
     {
         m_orb = _orb;
         m_dataSource = _dataSource;
     }
 
+    final public XDataSource getXDataSource()
+    {
+        return m_dataSource;
+    }
+            
     /** creates a query with a given name and SQL command
     */
     public void createQuery( String _name, String _sqlCommand ) throws 
ElementExistException, WrappedTargetException, 
com.sun.star.lang.IllegalArgumentException
@@ -125,4 +145,27 @@
             XRefreshable.class, suppTables.getTables() );
         refreshTables.refresh();
     }
+
+    /** returns the name of the data source
+     * 
+     * If a data source is registered at the database context, the name is the 
registration
+     * name. Otherwise, its the URL which the respective database document is 
based on.
+     * 
+     * Note that the above definition is from the UNO API, not from this 
wrapper here.
+     */
+    public String getName()
+    {
+        String name = null;
+        try
+        {
+            XPropertySet dataSourceProps = (XPropertySet) 
UnoRuntime.queryInterface(
+            XPropertySet.class, m_dataSource );
+            name = (String)dataSourceProps.getPropertyValue("Name");
+        }
+        catch (Exception ex)
+        {
+            Logger.getLogger(DataSource.class.getName()).log(Level.SEVERE, 
null, ex);
+        }
+        return name;
+    }
 };




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to