1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: DriverTest.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 package qa
.drivers
.hsqldb
;
32 import com
.sun
.star
.awt
.XWindow
;
33 import com
.sun
.star
.frame
.XModel
;
34 import com
.sun
.star
.text
.XTextDocument
;
35 import com
.sun
.star
.uno
.UnoRuntime
;
36 import com
.sun
.star
.util
.XCloseable
;
37 import com
.sun
.star
.sdbc
.*;
38 import com
.sun
.star
.beans
.PropertyValue
;
39 import com
.sun
.star
.container
.XNameAccess
;
40 import com
.sun
.star
.sdbc
.XDataSource
;
41 import com
.sun
.star
.frame
.XStorable
;
43 import com
.sun
.star
.lang
.*;
44 import com
.sun
.star
.document
.XDocumentSubStorageSupplier
;
45 import complexlib
.ComplexTestCase
;
47 import java
.io
.PrintWriter
;
52 import org
.hsqldb
.jdbcDriver
;
53 import qa
.drivers
.hsqldb
.DatabaseMetaData
;
54 import org
.hsqldb
.lib
.StopWatch
;
55 import com
.sun
.star
.sdbc
.*;
56 import com
.sun
.star
.container
.XNameAccess
;
57 import com
.sun
.star
.uno
.UnoRuntime
;
58 import com
.sun
.star
.beans
.PropertyValue
;
59 import com
.sun
.star
.beans
.PropertyState
;
60 import com
.sun
.star
.lang
.XMultiServiceFactory
;
61 import com
.sun
.star
.embed
.XStorage
;
63 public class DriverTest
extends ComplexTestCase
{
66 public String
[] getTestMethodNames() {
67 return new String
[] { "test" };
70 public String
getTestObjectName() {
74 public void assurePublic(String sMessage
,boolean check
){
75 addResult(sMessage
,check
);
79 mThreadTimeOut
= 10000000;
80 XDataSource ds
= null;
83 XNameAccess xNameAccess
= (XNameAccess
)UnoRuntime
.queryInterface(XNameAccess
.class,((XMultiServiceFactory
)param
.getMSF()).createInstance("com.sun.star.sdb.DatabaseContext"));
84 ds
= (XDataSource
)UnoRuntime
.queryInterface(XDataSource
.class,xNameAccess
.getByName("file:///g:/test.odb"));
85 } catch(Exception ex
) {
86 throw new RuntimeException("factory: unable to construct data source" );
90 XDocumentSubStorageSupplier doc
= (XDocumentSubStorageSupplier
)UnoRuntime
.queryInterface(XDocumentSubStorageSupplier
.class,ds
);
91 XStorage stor
= doc
.getDocumentSubStorage("database",4);
93 if ( stor
.isStreamElement("db.log") )
94 stor
.removeElement("db.log");
95 } catch(Exception e
){}
97 if ( stor
.isStreamElement("db.properties") )
98 stor
.removeElement("db.properties");
99 } catch(Exception e
){}
101 if ( stor
.isStreamElement("db.script") )
102 stor
.removeElement("db.script");
103 } catch(Exception e
){}
105 if ( stor
.isStreamElement("db.script.new") )
106 stor
.removeElement("db.script.new");
107 } catch(Exception e
){}
108 XStorable mod
= (XStorable
)UnoRuntime
.queryInterface(XStorable
.class,ds
);
110 XComponent xComp
= (XComponent
)UnoRuntime
.queryInterface(XComponent
.class,stor
);
113 } catch(Exception e
){}
115 com
.sun
.star
.beans
.PropertyValue
[] info
= null;
118 XDocumentSubStorageSupplier doc
= (XDocumentSubStorageSupplier
)UnoRuntime
.queryInterface(XDocumentSubStorageSupplier
.class,ds
);
119 XModel mod
= (XModel
)UnoRuntime
.queryInterface(XModel
.class,ds
);
120 XStorage stor
= doc
.getDocumentSubStorage("database",4);
121 info
= new com
.sun
.star
.beans
.PropertyValue
[]{
122 new com
.sun
.star
.beans
.PropertyValue("Storage",0,stor
,PropertyState
.DIRECT_VALUE
)
123 ,new com
.sun
.star
.beans
.PropertyValue("URL",0,mod
.getURL(),PropertyState
.DIRECT_VALUE
)
125 drv
= (XDriver
)UnoRuntime
.queryInterface(XDriver
.class,((XMultiServiceFactory
)param
.getMSF()).createInstance("com.sun.star.sdbcx.comp.hsqldb.Driver"));
128 TestCacheSize test
= new TestCacheSize(((XMultiServiceFactory
)param
.getMSF()),info
,drv
);
130 StopWatch sw
= new StopWatch();
137 System
.out
.println("Total Test Time: " + sw
.elapsedTime());
138 } catch(Exception e
){}
141 XStorable mod2
= (XStorable
)UnoRuntime
.queryInterface(XStorable
.class,ds
);
143 } catch(Exception e
){}
144 }catch(Exception e
){}
147 mThreadTimeOut
= 10000000;
150 com
.sun
.star
.beans
.PropertyValue
[] info
= null;
153 info
= new com
.sun
.star
.beans
.PropertyValue
[]{
154 new com
.sun
.star
.beans
.PropertyValue("JavaDriverClass",0,"org.hsqldb.jdbcDriver",PropertyState
.DIRECT_VALUE
)
155 ,new com
.sun
.star
.beans
.PropertyValue("ParameterNameSubstitution",0,new Boolean(false),PropertyState
.DIRECT_VALUE
)
157 drv
= (XDriver
)UnoRuntime
.queryInterface(XDriver
.class,((XMultiServiceFactory
)param
.getMSF()).createInstance("com.sun.star.comp.sdbc.JDBCDriver"));
158 TestCacheSize test
= new TestCacheSize(((XMultiServiceFactory
)param
.getMSF()),info
,drv
);
159 test
.setURL("jdbc:hsqldb:g:\\hsql\\db");
162 StopWatch sw
= new StopWatch();
169 System
.out
.println("Total Test Time: " + sw
.elapsedTime());
170 } catch(Exception e
){}
171 }catch(Exception e
){}