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
;
24 import lib
.TestEnvironment
;
25 import lib
.TestParameters
;
28 import com
.sun
.star
.beans
.XPropertySet
;
29 import com
.sun
.star
.container
.XNameAccess
;
30 import com
.sun
.star
.lang
.XMultiServiceFactory
;
31 import com
.sun
.star
.sdb
.CommandType
;
32 import com
.sun
.star
.sdb
.XSingleSelectQueryAnalyzer
;
33 import com
.sun
.star
.sdb
.XSingleSelectQueryComposer
;
34 import com
.sun
.star
.sdbc
.XDataSource
;
35 import com
.sun
.star
.sdbc
.XResultSet
;
36 import com
.sun
.star
.sdbcx
.XColumnsSupplier
;
37 import com
.sun
.star
.uno
.AnyConverter
;
38 import com
.sun
.star
.uno
.Type
;
39 import com
.sun
.star
.uno
.UnoRuntime
;
40 import com
.sun
.star
.uno
.XInterface
;
43 * Test for object which is represented by service
44 * <code>com.sun.star.sdb.DataSource</code>.
47 * Object implements the following interfaces :
49 * <li> <code>com::sun::star::sdbc::RowSet</code></li>
50 * <li> <code>com::sun::star::sdbcx::XRowLocate</code></li>
51 * <li> <code>com::sun::star::sdbc::XResultSetUpdate</code></li>
52 * <li> <code>com::sun::star::util::XCancellable</code></li>
53 * <li> <code>com::sun::star::sdbc::XParameters</code></li>
54 * <li> <code>com::sun::star::sdbc::XResultSetMetaDataSupplier</code></li>
55 * <li> <code>com::sun::star::sdbcx::XDeleteRows</code></li>
56 * <li> <code>com::sun::star::sdbc::XCloseable</code></li>
57 * <li> <code>com::sun::star::sdbcx::XColumnsSupplier</code></li>
58 * <li> <code>com::sun::star::sdb::XResultSetAccess</code></li>
59 * <li> <code>com::sun::star::sdbc::XResultSet</code></li>
60 * <li> <code>com::sun::star::sdbc::XColumnLocate</code></li>
61 * <li> <code>com::sun::star::sdbc::XRowSet</code></li>
62 * <li> <code>com::sun::star::sdb::RowSet</code></li>
63 * <li> <code>com::sun::star::sdbc::XRowUpdate</code></li>
64 * <li> <code>com::sun::star::sdb::XRowSetApproveBroadcaster</code></li>
65 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
66 * <li> <code>com::sun::star::sdbc::XRow</code></li>
67 * <li> <code>com::sun::star::sdbc::XWarningsSupplier</code></li>
68 * <li> <code>com::sun::star::lang::XComponent</code></li>
69 * <li> <code>com::sun::star::sdbcx::ResultSet</code></li>
70 * <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 predefined
76 * fields described in <code>util.DBTools</code>. The copy of this file is
77 * always made in temp directory for 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. For example:
83 * <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>
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 protected static final String dbSourceName
= "OSingleSelectQueryComposerDataSource";
139 * Creating a TestEnvironment for the interfaces to be tested.
141 * Object relations created :
142 * <ul>SingleSelectQueryAnalyzer
144 * <li> <code>'xComposer'</code> for
145 * {@link ifc.sdb._XSingleSelectQueryAnalyzer} interface
146 * <li> <code>'xQueryAna'</code> for
147 * {@link ifc.sdb._XSingleSelectQueryComposer} interface
148 * <li> <code>'xProp'</code> for
149 * {@link ifc.sdb._XSingleSelectQueryComposer} interface
150 * <li> <code>'colName'</code> for
151 * {@link ifc.sdb._XSingleSelectQueryComposer} interface
152 * <li> <code>'xResultSet'</code> for
153 * {@link ifc.sdb._XSingleSelectQueryComposer} interface
158 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
159 PrintWriter log
) throws Exception
{
161 XInterface oObj
= null;
162 Object oInterface
= null;
163 XMultiServiceFactory xMSF
= null;
164 xMSF
= Param
.getMSF();
166 XNameAccess xNameAccess
= UnoRuntime
.queryInterface(XNameAccess
.class,
167 xMSF
.createInstance("com.sun.star.sdb.DatabaseContext"));
168 // we use the first datasource
169 XDataSource xDS
= UnoRuntime
.queryInterface(XDataSource
.class,
170 xNameAccess
.getByName("Bibliography"));
172 log
.println("check XMultiServiceFactory");
173 XMultiServiceFactory xConn
= UnoRuntime
.queryInterface(
174 XMultiServiceFactory
.class, xDS
.getConnection("", ""));
176 log
.println("check getAvailableServiceNames");
177 String
[] sServiceNames
= xConn
.getAvailableServiceNames();
178 if (!sServiceNames
[0]
179 .equals("com.sun.star.sdb.SingleSelectQueryComposer")) {
180 log
.println("Service 'SingleSelectQueryComposer' not supported");
183 oInterface
= xConn
.createInstance(sServiceNames
[0]);
184 Object oRowSet
= xMSF
.createInstance("com.sun.star.sdb.RowSet");
186 XPropertySet xSetProp
= UnoRuntime
.queryInterface(XPropertySet
.class,
189 xSetProp
.setPropertyValue("DataSourceName", "Bibliography");
190 xSetProp
.setPropertyValue("Command", "biblio");
191 xSetProp
.setPropertyValue("CommandType",
192 Integer
.valueOf(CommandType
.TABLE
));
194 com
.sun
.star
.sdbc
.XRowSet xORowSet
= UnoRuntime
.queryInterface(
195 com
.sun
.star
.sdbc
.XRowSet
.class, oRowSet
);
199 XColumnsSupplier xColSup
= UnoRuntime
.queryInterface(
200 XColumnsSupplier
.class, oRowSet
);
202 XNameAccess xCols
= xColSup
.getColumns();
204 XPropertySet xCol
= (XPropertySet
) AnyConverter
.toObject(new Type(
206 xCols
.getByName(xCols
.getElementNames()[0]));
208 XSingleSelectQueryAnalyzer xQueryAna
= UnoRuntime
.queryInterface(
209 XSingleSelectQueryAnalyzer
.class, oInterface
);
211 // XSingleSelectQueryComposer
212 XSingleSelectQueryComposer xComposer
= UnoRuntime
.queryInterface(
213 XSingleSelectQueryComposer
.class, xQueryAna
);
214 xQueryAna
.setQuery("SELECT * FROM \"biblio\"");
216 oObj
= (XInterface
) oInterface
;
217 log
.println("ImplementationName: " + utils
.getImplName(oObj
));
219 log
.println(" creating a new environment for object");
220 TestEnvironment tEnv
= new TestEnvironment(oObj
);
222 // for XSingleSelectQueryAnalyzer
223 tEnv
.addObjRelation("xComposer", xComposer
);
225 // for XSingleSelectQueryComposer
226 tEnv
.addObjRelation("xQueryAna", xQueryAna
);
228 tEnv
.addObjRelation("xProp", xCol
);
229 tEnv
.addObjRelation("colName", xCols
.getElementNames()[0]);
231 XResultSet xResultSet
= UnoRuntime
.queryInterface(XResultSet
.class,
233 tEnv
.addObjRelation("xResultSet", xResultSet
);
237 } // finish method getTestEnvironment
240 * Closes connection of <code>RowSet</code> instance created.
243 protected void cleanup(TestParameters Param
, PrintWriter log
) {