2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package mod
._dbaccess
;
21 import java
.io
.PrintWriter
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
30 import com
.sun
.star
.beans
.XPropertySet
;
31 import com
.sun
.star
.container
.XNameAccess
;
32 import com
.sun
.star
.lang
.XMultiServiceFactory
;
33 import com
.sun
.star
.sdb
.CommandType
;
34 import com
.sun
.star
.sdb
.XSingleSelectQueryAnalyzer
;
35 import com
.sun
.star
.sdb
.XSingleSelectQueryComposer
;
36 import com
.sun
.star
.sdbc
.XConnection
;
37 import com
.sun
.star
.sdbc
.XDataSource
;
38 import com
.sun
.star
.sdbcx
.XColumnsSupplier
;
39 import com
.sun
.star
.uno
.AnyConverter
;
40 import com
.sun
.star
.uno
.Type
;
41 import com
.sun
.star
.uno
.UnoRuntime
;
42 import com
.sun
.star
.uno
.XInterface
;
45 * Test for object which is represented by service
46 * <code>com.sun.star.sdb.DataSource</code>. <p>
48 * Object implements the following interfaces :
50 * <li> <code>com::sun::star::sdbc::RowSet</code></li>
51 * <li> <code>com::sun::star::sdbcx::XRowLocate</code></li>
52 * <li> <code>com::sun::star::sdbc::XResultSetUpdate</code></li>
53 * <li> <code>com::sun::star::util::XCancellable</code></li>
54 * <li> <code>com::sun::star::sdbc::XParameters</code></li>
55 * <li> <code>com::sun::star::sdbc::XResultSetMetaDataSupplier</code></li>
56 * <li> <code>com::sun::star::sdbcx::XDeleteRows</code></li>
57 * <li> <code>com::sun::star::sdbc::XCloseable</code></li>
58 * <li> <code>com::sun::star::sdbcx::XColumnsSupplier</code></li>
59 * <li> <code>com::sun::star::sdb::XResultSetAccess</code></li>
60 * <li> <code>com::sun::star::sdbc::XResultSet</code></li>
61 * <li> <code>com::sun::star::sdbc::XColumnLocate</code></li>
62 * <li> <code>com::sun::star::sdbc::XRowSet</code></li>
63 * <li> <code>com::sun::star::sdb::RowSet</code></li>
64 * <li> <code>com::sun::star::sdbc::XRowUpdate</code></li>
65 * <li> <code>com::sun::star::sdb::XRowSetApproveBroadcaster</code></li>
66 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
67 * <li> <code>com::sun::star::sdbc::XRow</code></li>
68 * <li> <code>com::sun::star::sdbc::XWarningsSupplier</code></li>
69 * <li> <code>com::sun::star::lang::XComponent</code></li>
70 * <li> <code>com::sun::star::sdbcx::ResultSet</code></li>
71 * <li> <code>com::sun::star::sdbc::ResultSet</code></li>
73 * The following files used by this test :
75 * <li><b> TestDB/TestDB.dbf </b> : the database file with some
76 * predefined fields described in <code>util.DBTools</code>.
77 * The copy of this file is always made in temp directory for
78 * testing purposes.</li>
80 * The following parameters in ini-file used by this test:
82 * <li><code>test.db.url</code> - URL to MySQL database.
83 * For example: <code>mysql://mercury:3306/api_current</code></li>
84 * <li><code>test.db.user</code> - user for MySQL database</li>
85 * <li><code>test.db.password</code> - password for MySQL database</li>
88 * @see com.sun.star.sdbc.RowSet
89 * @see com.sun.star.sdbcx.XRowLocate
90 * @see com.sun.star.sdbc.XResultSetUpdate
91 * @see com.sun.star.util.XCancellable
92 * @see com.sun.star.sdbc.XParameters
93 * @see com.sun.star.sdbc.XResultSetMetaDataSupplier
94 * @see com.sun.star.sdbcx.XDeleteRows
95 * @see com.sun.star.sdbc.XCloseable
96 * @see com.sun.star.sdbcx.XColumnsSupplier
97 * @see com.sun.star.sdb.XResultSetAccess
98 * @see com.sun.star.sdbc.XResultSet
99 * @see com.sun.star.sdbc.XColumnLocate
100 * @see com.sun.star.sdbc.XRowSet
101 * @see com.sun.star.sdb.RowSet
102 * @see com.sun.star.sdbc.XRowUpdate
103 * @see com.sun.star.sdb.XRowSetApproveBroadcaster
104 * @see com.sun.star.beans.XPropertySet
105 * @see com.sun.star.sdbc.XRow
106 * @see com.sun.star.sdbc.XWarningsSupplier
107 * @see com.sun.star.lang.XComponent
108 * @see com.sun.star.sdbcx.ResultSet
109 * @see com.sun.star.sdbc.ResultSet
110 * @see ifc.sdbc._RowSet
111 * @see ifc.sdbcx._XRowLocate
112 * @see ifc.sdbc._XResultSetUpdate
113 * @see ifc.util._XCancellable
114 * @see ifc.sdbc._XParameters
115 * @see ifc.sdbc._XResultSetMetaDataSupplier
116 * @see ifc.sdbcx._XDeleteRows
117 * @see ifc.sdbc._XCloseable
118 * @see ifc.sdbcx._XColumnsSupplier
119 * @see ifc.sdb._XResultSetAccess
120 * @see ifc.sdbc._XResultSet
121 * @see ifc.sdbc._XColumnLocate
122 * @see ifc.sdbc._XRowSet
123 * @see ifc.sdb._RowSet
124 * @see ifc.sdbc._XRowUpdate
125 * @see ifc.sdb._XRowSetApproveBroadcaster
126 * @see ifc.beans._XPropertySet
127 * @see ifc.sdbc._XRow
128 * @see ifc.sdbc._XWarningsSupplier
129 * @see ifc.lang._XComponent
130 * @see ifc.sdbcx._ResultSet
131 * @see ifc.sdbc._ResultSet
133 public class OSingleSelectQueryComposer
extends TestCase
{
135 String tableName
= null;
136 DBTools
.DataSourceInfo srcInf
= null;
137 boolean isMySQLDB
= false;
138 protected final static String dbSourceName
= "OSingleSelectQueryComposerDataSource";
139 public XConnection conn
= null;
142 protected void initialize ( TestParameters Param
, PrintWriter log
)
143 throws StatusException
{
148 * Creating a Testenvironment for the interfaces to be tested.
150 * Object relations created :
151 * <ul>SingleSelectQueryAnalyzer
153 * <li> <code>'xComposer'</code> for
154 * {@link ifc.sdb._XSingleSelectQueryAnalyzer} interface
155 * <li> <code>'xQueryAna'</code> for
156 * {@link ifc.sdb._XSingleSelectQueryComposer} interface
157 * <li> <code>'xProp'</code> for
158 * {@link ifc.sdb._XSingleSelectQueryComposer} interface
159 * <li> <code>'colName'</code> for
160 * {@link ifc.sdb._XSingleSelectQueryComposer} interface
164 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
167 XInterface oObj
= null;
168 Object oInterface
= null;
169 XMultiServiceFactory xMSF
= null ;
171 xMSF
= (XMultiServiceFactory
)Param
.getMSF();
173 XNameAccess xNameAccess
= UnoRuntime
.queryInterface(
175 xMSF
.createInstance("com.sun.star.sdb.DatabaseContext"));
176 // we use the first datasource
177 XDataSource xDS
= UnoRuntime
.queryInterface(
178 XDataSource
.class, xNameAccess
.getByName( "Bibliography" ));
180 log
.println("check XMultiServiceFactory");
181 XMultiServiceFactory xConn
= UnoRuntime
.queryInterface(XMultiServiceFactory
.class,
182 xDS
.getConnection(new String(),new String()));
184 log
.println("check getAvailableServiceNames");
185 String
[] sServiceNames
= xConn
.getAvailableServiceNames();
186 if (! sServiceNames
[0].equals("com.sun.star.sdb.SingleSelectQueryComposer"))
188 log
.println("Service 'SingleSelectQueryComposer' not supported");
191 oInterface
= xConn
.createInstance( sServiceNames
[0]);
193 if (oInterface
== null) {
194 log
.println("Service wasn't created") ;
195 throw new StatusException("Service wasn't created",
196 new NullPointerException()) ;
199 Object oRowSet
= xMSF
.createInstance("com.sun.star.sdb.RowSet") ;
201 XPropertySet xSetProp
= UnoRuntime
.queryInterface
202 (XPropertySet
.class, oRowSet
) ;
204 xSetProp
.setPropertyValue("DataSourceName", "Bibliography") ;
205 xSetProp
.setPropertyValue("Command", "biblio") ;
206 xSetProp
.setPropertyValue("CommandType",
207 new Integer(CommandType
.TABLE
)) ;
209 com
.sun
.star
.sdbc
.XRowSet xORowSet
= UnoRuntime
.queryInterface(com
.sun
.star
.sdbc
.XRowSet
.class,
214 XColumnsSupplier xColSup
= UnoRuntime
.queryInterface(XColumnsSupplier
.class, oRowSet
);
216 XNameAccess xCols
= xColSup
.getColumns();
218 XPropertySet xCol
= (XPropertySet
) AnyConverter
.toObject(
219 new Type(XPropertySet
.class),
220 xCols
.getByName(xCols
.getElementNames()[0]));
222 XSingleSelectQueryAnalyzer xQueryAna
= UnoRuntime
.queryInterface(XSingleSelectQueryAnalyzer
.class,
225 // XSingleSelectQueryComposer
226 XSingleSelectQueryComposer xComposer
= UnoRuntime
.queryInterface(XSingleSelectQueryComposer
.class,
228 xQueryAna
.setQuery("SELECT * FROM \"biblio\"");
230 oObj
= (XInterface
) oInterface
;
231 log
.println("ImplementationName: " + utils
.getImplName(oObj
));
233 log
.println( " creating a new environment for object" );
234 TestEnvironment tEnv
= new TestEnvironment( oObj
);
236 // for XSingleSelectQueryAnalyzer
237 tEnv
.addObjRelation("xComposer", xComposer
);
239 // for XSingleSelectQueryComposer
240 tEnv
.addObjRelation("xQueryAna", xQueryAna
);
242 tEnv
.addObjRelation("xProp", xCol
);
243 tEnv
.addObjRelation("colName", xCols
.getElementNames()[0]);
247 } catch(com
.sun
.star
.uno
.Exception e
) {
248 log
.println("Can't create object" );
249 e
.printStackTrace(log
) ;
250 throw new StatusException("Can't create object", e
) ;
253 } // finish method getTestEnvironment
256 * Closes connection of <code>RowSet</code> instance created.
258 protected void cleanup( TestParameters Param
, PrintWriter log
) {