1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 package complex.connectivity; 28 29 import complex.connectivity.hsqldb.TestCacheSize; 30 import com.sun.star.frame.XModel; 31 import com.sun.star.frame.XStorable; 32 33 import com.sun.star.lang.*; 34 import com.sun.star.document.XDocumentSubStorageSupplier; 35 import complexlib.ComplexTestCase; 36 37 38 import org.hsqldb.lib.StopWatch; 39 import com.sun.star.uno.UnoRuntime; 40 import com.sun.star.beans.PropertyState; 41 import com.sun.star.lang.XMultiServiceFactory; 42 import com.sun.star.embed.XStorage; 43 import com.sun.star.sdbc.XDataSource; 44 import com.sun.star.sdbc.XDriver; 45 import connectivity.tools.HsqlDatabase; 46 47 public class HsqlDriverTest extends ComplexTestCase { 48 49 50 public String[] getTestMethodNames() { 51 return new String[] { "test" }; 52 } 53 54 @Override 55 public String getTestObjectName() { 56 return "DriverTest"; 57 } 58 59 public void assurePublic(String sMessage,boolean check){ 60 super.assure(sMessage,check); 61 } 62 63 public void test(){ 64 XDataSource ds = null; 65 System.gc(); 66 try { 67 HsqlDatabase database = new HsqlDatabase( (XMultiServiceFactory)param.getMSF() ); 68 ds = database.getDataSource().getXDataSource(); 69 } catch(Exception ex) { 70 throw new RuntimeException("factory: unable to construct data source" ); 71 } 72 73 try{ 74 XDocumentSubStorageSupplier doc = (XDocumentSubStorageSupplier)UnoRuntime.queryInterface(XDocumentSubStorageSupplier.class,ds); 75 XStorage stor = doc.getDocumentSubStorage("database",4); 76 try{ 77 if ( stor.isStreamElement("db.log") ) 78 stor.removeElement("db.log"); 79 } catch(Exception e){} 80 try{ 81 if ( stor.isStreamElement("db.properties") ) 82 stor.removeElement("db.properties"); 83 } catch(Exception e){} 84 try{ 85 if ( stor.isStreamElement("db.script") ) 86 stor.removeElement("db.script"); 87 } catch(Exception e){} 88 try{ 89 if ( stor.isStreamElement("db.script.new") ) 90 stor.removeElement("db.script.new"); 91 } catch(Exception e){} 92 XStorable mod = (XStorable)UnoRuntime.queryInterface(XStorable.class,ds); 93 mod.store(); 94 XComponent xComp = (XComponent)UnoRuntime.queryInterface(XComponent.class,stor); 95 if ( xComp != null ) 96 xComp.dispose(); 97 } catch(Exception e){} 98 99 com.sun.star.beans.PropertyValue[] info = null; 100 XDriver drv = null; 101 try{ 102 XDocumentSubStorageSupplier doc = (XDocumentSubStorageSupplier)UnoRuntime.queryInterface(XDocumentSubStorageSupplier.class,ds); 103 XModel mod = (XModel)UnoRuntime.queryInterface(XModel.class,ds); 104 XStorage stor = doc.getDocumentSubStorage("database",4); 105 info = new com.sun.star.beans.PropertyValue[]{ 106 new com.sun.star.beans.PropertyValue("Storage",0,stor,PropertyState.DIRECT_VALUE) 107 ,new com.sun.star.beans.PropertyValue("URL",0,mod.getURL(),PropertyState.DIRECT_VALUE) 108 }; 109 drv = (XDriver)UnoRuntime.queryInterface(XDriver.class,((XMultiServiceFactory)param.getMSF()).createInstance("com.sun.star.sdbcx.comp.hsqldb.Driver")); 110 111 112 TestCacheSize test = new TestCacheSize(((XMultiServiceFactory)param.getMSF()),info,drv); 113 114 StopWatch sw = new StopWatch(); 115 116 try{ 117 test.setUp(); 118 test.testFillUp(); 119 test.checkResults(); 120 test.tearDown(); 121 System.out.println("Total Test Time: " + sw.elapsedTime()); 122 } catch(Exception e){} 123 124 try{ 125 XStorable mod2 = (XStorable)UnoRuntime.queryInterface(XStorable.class,ds); 126 mod2.store(); 127 } catch(Exception e){} 128 }catch(Exception e){} 129 } 130 public void test2(){ 131 System.gc(); 132 133 com.sun.star.beans.PropertyValue[] info = null; 134 XDriver drv = null; 135 try{ 136 info = new com.sun.star.beans.PropertyValue[]{ 137 new com.sun.star.beans.PropertyValue("JavaDriverClass",0,"org.hsqldb.jdbcDriver",PropertyState.DIRECT_VALUE) 138 ,new com.sun.star.beans.PropertyValue("ParameterNameSubstitution",0, false,PropertyState.DIRECT_VALUE) 139 }; 140 drv = (XDriver)UnoRuntime.queryInterface(XDriver.class,((XMultiServiceFactory)param.getMSF()).createInstance("com.sun.star.comp.sdbc.JDBCDriver")); 141 TestCacheSize test = new TestCacheSize(((XMultiServiceFactory)param.getMSF()),info,drv); 142 test.setURL("jdbc:hsqldb:g:\\hsql\\db"); 143 144 145 StopWatch sw = new StopWatch(); 146 147 try{ 148 test.setUp(); 149 test.testFillUp(); 150 test.checkResults(); 151 test.tearDown(); 152 System.out.println("Total Test Time: " + sw.elapsedTime()); 153 } catch(Exception e){} 154 }catch(Exception e){} 155 } 156 } 157