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
.sdbc
.XResultSet
;
39 import com
.sun
.star
.sdbcx
.XColumnsSupplier
;
40 import com
.sun
.star
.uno
.AnyConverter
;
41 import com
.sun
.star
.uno
.Type
;
42 import com
.sun
.star
.uno
.UnoRuntime
;
43 import com
.sun
.star
.uno
.XInterface
;
46 * Test for object which is represented by service
47 * <code>com.sun.star.sdb.DataSource</code>. <p>
49 * Object implements the following interfaces :
51 * <li> <code>com::sun::star::sdbc::RowSet</code></li>
52 * <li> <code>com::sun::star::sdbcx::XRowLocate</code></li>
53 * <li> <code>com::sun::star::sdbc::XResultSetUpdate</code></li>
54 * <li> <code>com::sun::star::util::XCancellable</code></li>
55 * <li> <code>com::sun::star::sdbc::XParameters</code></li>
56 * <li> <code>com::sun::star::sdbc::XResultSetMetaDataSupplier</code></li>
57 * <li> <code>com::sun::star::sdbcx::XDeleteRows</code></li>
58 * <li> <code>com::sun::star::sdbc::XCloseable</code></li>
59 * <li> <code>com::sun::star::sdbcx::XColumnsSupplier</code></li>
60 * <li> <code>com::sun::star::sdb::XResultSetAccess</code></li>
61 * <li> <code>com::sun::star::sdbc::XResultSet</code></li>
62 * <li> <code>com::sun::star::sdbc::XColumnLocate</code></li>
63 * <li> <code>com::sun::star::sdbc::XRowSet</code></li>
64 * <li> <code>com::sun::star::sdb::RowSet</code></li>
65 * <li> <code>com::sun::star::sdbc::XRowUpdate</code></li>
66 * <li> <code>com::sun::star::sdb::XRowSetApproveBroadcaster</code></li>
67 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
68 * <li> <code>com::sun::star::sdbc::XRow</code></li>
69 * <li> <code>com::sun::star::sdbc::XWarningsSupplier</code></li>
70 * <li> <code>com::sun::star::lang::XComponent</code></li>
71 * <li> <code>com::sun::star::sdbcx::ResultSet</code></li>
72 * <li> <code>com::sun::star::sdbc::ResultSet</code></li>
74 * The following files used by this test :
76 * <li><b> TestDB/TestDB.dbf </b> : the database file with some
77 * predefined fields described in <code>util.DBTools</code>.
78 * The copy of this file is always made in temp directory for
79 * testing purposes.</li>
81 * The following parameters in ini-file used by this test:
83 * <li><code>test.db.url</code> - URL to MySQL database.
84 * For example: <code>mysql://mercury:3306/api_current</code></li>
85 * <li><code>test.db.user</code> - user for MySQL database</li>
86 * <li><code>test.db.password</code> - password for MySQL database</li>
89 * @see com.sun.star.sdbc.RowSet
90 * @see com.sun.star.sdbcx.XRowLocate
91 * @see com.sun.star.sdbc.XResultSetUpdate
92 * @see com.sun.star.util.XCancellable
93 * @see com.sun.star.sdbc.XParameters
94 * @see com.sun.star.sdbc.XResultSetMetaDataSupplier
95 * @see com.sun.star.sdbcx.XDeleteRows
96 * @see com.sun.star.sdbc.XCloseable
97 * @see com.sun.star.sdbcx.XColumnsSupplier
98 * @see com.sun.star.sdb.XResultSetAccess
99 * @see com.sun.star.sdbc.XResultSet
100 * @see com.sun.star.sdbc.XColumnLocate
101 * @see com.sun.star.sdbc.XRowSet
102 * @see com.sun.star.sdb.RowSet
103 * @see com.sun.star.sdbc.XRowUpdate
104 * @see com.sun.star.sdb.XRowSetApproveBroadcaster
105 * @see com.sun.star.beans.XPropertySet
106 * @see com.sun.star.sdbc.XRow
107 * @see com.sun.star.sdbc.XWarningsSupplier
108 * @see com.sun.star.lang.XComponent
109 * @see com.sun.star.sdbcx.ResultSet
110 * @see com.sun.star.sdbc.ResultSet
111 * @see ifc.sdbc._RowSet
112 * @see ifc.sdbcx._XRowLocate
113 * @see ifc.sdbc._XResultSetUpdate
114 * @see ifc.util._XCancellable
115 * @see ifc.sdbc._XParameters
116 * @see ifc.sdbc._XResultSetMetaDataSupplier
117 * @see ifc.sdbcx._XDeleteRows
118 * @see ifc.sdbc._XCloseable
119 * @see ifc.sdbcx._XColumnsSupplier
120 * @see ifc.sdb._XResultSetAccess
121 * @see ifc.sdbc._XResultSet
122 * @see ifc.sdbc._XColumnLocate
123 * @see ifc.sdbc._XRowSet
124 * @see ifc.sdb._RowSet
125 * @see ifc.sdbc._XRowUpdate
126 * @see ifc.sdb._XRowSetApproveBroadcaster
127 * @see ifc.beans._XPropertySet
128 * @see ifc.sdbc._XRow
129 * @see ifc.sdbc._XWarningsSupplier
130 * @see ifc.lang._XComponent
131 * @see ifc.sdbcx._ResultSet
132 * @see ifc.sdbc._ResultSet
134 public class OSingleSelectQueryComposer
extends TestCase
{
136 String tableName
= null;
137 DBTools
.DataSourceInfo srcInf
= null;
138 boolean isMySQLDB
= false;
139 protected final static String dbSourceName
= "OSingleSelectQueryComposerDataSource";
140 public XConnection conn
= null;
144 protected void initialize ( TestParameters Param
, PrintWriter log
)
145 throws StatusException
{
150 * Creating a Testenvironment for the interfaces to be tested.
152 * Object relations created :
153 * <ul>SingleSelectQueryAnalyzer
155 * <li> <code>'xComposer'</code> for
156 * {@link ifc.sdb._XSingleSelectQueryAnalyzer} interface
157 * <li> <code>'xQueryAna'</code> for
158 * {@link ifc.sdb._XSingleSelectQueryComposer} interface
159 * <li> <code>'xProp'</code> for
160 * {@link ifc.sdb._XSingleSelectQueryComposer} interface
161 * <li> <code>'colName'</code> for
162 * {@link ifc.sdb._XSingleSelectQueryComposer} interface
163 * <li> <code>'xResultSet'</code> for
164 * {@link ifc.sdb._XSingleSelectQueryComposer} interface
169 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
172 XInterface oObj
= null;
173 Object oInterface
= null;
174 XMultiServiceFactory xMSF
= null ;
176 xMSF
= Param
.getMSF();
178 XNameAccess xNameAccess
= UnoRuntime
.queryInterface(
180 xMSF
.createInstance("com.sun.star.sdb.DatabaseContext"));
181 // we use the first datasource
182 XDataSource xDS
= UnoRuntime
.queryInterface(
183 XDataSource
.class, xNameAccess
.getByName( "Bibliography" ));
185 log
.println("check XMultiServiceFactory");
186 XMultiServiceFactory xConn
= UnoRuntime
.queryInterface(XMultiServiceFactory
.class,
187 xDS
.getConnection("", ""));
189 log
.println("check getAvailableServiceNames");
190 String
[] sServiceNames
= xConn
.getAvailableServiceNames();
191 if (! sServiceNames
[0].equals("com.sun.star.sdb.SingleSelectQueryComposer"))
193 log
.println("Service 'SingleSelectQueryComposer' not supported");
196 oInterface
= xConn
.createInstance( sServiceNames
[0]);
198 if (oInterface
== null) {
199 log
.println("Service wasn't created") ;
200 throw new StatusException("Service wasn't created",
201 new NullPointerException()) ;
204 Object oRowSet
= xMSF
.createInstance("com.sun.star.sdb.RowSet") ;
206 XPropertySet xSetProp
= UnoRuntime
.queryInterface
207 (XPropertySet
.class, oRowSet
) ;
209 xSetProp
.setPropertyValue("DataSourceName", "Bibliography") ;
210 xSetProp
.setPropertyValue("Command", "biblio") ;
211 xSetProp
.setPropertyValue("CommandType",
212 Integer
.valueOf(CommandType
.TABLE
)) ;
214 com
.sun
.star
.sdbc
.XRowSet xORowSet
= UnoRuntime
.queryInterface(com
.sun
.star
.sdbc
.XRowSet
.class,
219 XColumnsSupplier xColSup
= UnoRuntime
.queryInterface(XColumnsSupplier
.class, oRowSet
);
221 XNameAccess xCols
= xColSup
.getColumns();
223 XPropertySet xCol
= (XPropertySet
) AnyConverter
.toObject(
224 new Type(XPropertySet
.class),
225 xCols
.getByName(xCols
.getElementNames()[0]));
227 XSingleSelectQueryAnalyzer xQueryAna
= UnoRuntime
.queryInterface(XSingleSelectQueryAnalyzer
.class,
230 // XSingleSelectQueryComposer
231 XSingleSelectQueryComposer xComposer
= UnoRuntime
.queryInterface(XSingleSelectQueryComposer
.class,
233 xQueryAna
.setQuery("SELECT * FROM \"biblio\"");
235 oObj
= (XInterface
) oInterface
;
236 log
.println("ImplementationName: " + utils
.getImplName(oObj
));
238 log
.println( " creating a new environment for object" );
239 TestEnvironment tEnv
= new TestEnvironment( oObj
);
241 // for XSingleSelectQueryAnalyzer
242 tEnv
.addObjRelation("xComposer", xComposer
);
244 // for XSingleSelectQueryComposer
245 tEnv
.addObjRelation("xQueryAna", xQueryAna
);
247 tEnv
.addObjRelation("xProp", xCol
);
248 tEnv
.addObjRelation("colName", xCols
.getElementNames()[0]);
250 XResultSet xResultSet
= UnoRuntime
.queryInterface(XResultSet
.class, oRowSet
);
251 tEnv
.addObjRelation("xResultSet", xResultSet
);
255 } catch(com
.sun
.star
.uno
.Exception e
) {
256 log
.println("Can't create object" );
257 e
.printStackTrace(log
) ;
258 throw new StatusException("Can't create object", e
) ;
261 } // finish method getTestEnvironment
264 * Closes connection of <code>RowSet</code> instance created.
267 protected void cleanup( TestParameters Param
, PrintWriter log
) {