1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 package complex.connectivity; 24 25 import complex.connectivity.hsqldb.TestCacheSize; 26 import com.sun.star.frame.XModel; 27 import com.sun.star.frame.XStorable; 28 29 import com.sun.star.lang.*; 30 import com.sun.star.document.XDocumentSubStorageSupplier; 31 import complexlib.ComplexTestCase; 32 33 34 import org.hsqldb.lib.StopWatch; 35 import com.sun.star.uno.UnoRuntime; 36 import com.sun.star.beans.PropertyState; 37 import com.sun.star.lang.XMultiServiceFactory; 38 import com.sun.star.embed.XStorage; 39 import com.sun.star.sdbc.XDataSource; 40 import com.sun.star.sdbc.XDriver; 41 import connectivity.tools.HsqlDatabase; 42 43 public class HsqlDriverTest extends ComplexTestCase { 44 45 getTestMethodNames()46 public String[] getTestMethodNames() { 47 return new String[] { "test" }; 48 } 49 50 @Override getTestObjectName()51 public String getTestObjectName() { 52 return "DriverTest"; 53 } 54 assurePublic(String sMessage,boolean check)55 public void assurePublic(String sMessage,boolean check){ 56 super.assure(sMessage,check); 57 } 58 test()59 public void test(){ 60 XDataSource ds = null; 61 System.gc(); 62 try { 63 HsqlDatabase database = new HsqlDatabase( (XMultiServiceFactory)param.getMSF() ); 64 ds = database.getDataSource().getXDataSource(); 65 } catch(Exception ex) { 66 throw new RuntimeException("factory: unable to construct data source" ); 67 } 68 69 try{ 70 XDocumentSubStorageSupplier doc = (XDocumentSubStorageSupplier)UnoRuntime.queryInterface(XDocumentSubStorageSupplier.class,ds); 71 XStorage stor = doc.getDocumentSubStorage("database",4); 72 try{ 73 if ( stor.isStreamElement("db.log") ) 74 stor.removeElement("db.log"); 75 } catch(Exception e){} 76 try{ 77 if ( stor.isStreamElement("db.properties") ) 78 stor.removeElement("db.properties"); 79 } catch(Exception e){} 80 try{ 81 if ( stor.isStreamElement("db.script") ) 82 stor.removeElement("db.script"); 83 } catch(Exception e){} 84 try{ 85 if ( stor.isStreamElement("db.script.new") ) 86 stor.removeElement("db.script.new"); 87 } catch(Exception e){} 88 XStorable mod = (XStorable)UnoRuntime.queryInterface(XStorable.class,ds); 89 mod.store(); 90 XComponent xComp = (XComponent)UnoRuntime.queryInterface(XComponent.class,stor); 91 if ( xComp != null ) 92 xComp.dispose(); 93 } catch(Exception e){} 94 95 com.sun.star.beans.PropertyValue[] info = null; 96 XDriver drv = null; 97 try{ 98 XDocumentSubStorageSupplier doc = (XDocumentSubStorageSupplier)UnoRuntime.queryInterface(XDocumentSubStorageSupplier.class,ds); 99 XModel mod = (XModel)UnoRuntime.queryInterface(XModel.class,ds); 100 XStorage stor = doc.getDocumentSubStorage("database",4); 101 info = new com.sun.star.beans.PropertyValue[]{ 102 new com.sun.star.beans.PropertyValue("Storage",0,stor,PropertyState.DIRECT_VALUE) 103 ,new com.sun.star.beans.PropertyValue("URL",0,mod.getURL(),PropertyState.DIRECT_VALUE) 104 }; 105 drv = (XDriver)UnoRuntime.queryInterface(XDriver.class,((XMultiServiceFactory)param.getMSF()).createInstance("com.sun.star.sdbcx.comp.hsqldb.Driver")); 106 107 108 TestCacheSize test = new TestCacheSize(((XMultiServiceFactory)param.getMSF()),info,drv); 109 110 StopWatch sw = new StopWatch(); 111 112 try{ 113 test.setUp(); 114 test.testFillUp(); 115 test.checkResults(); 116 test.tearDown(); 117 System.out.println("Total Test Time: " + sw.elapsedTime()); 118 } catch(Exception e){} 119 120 try{ 121 XStorable mod2 = (XStorable)UnoRuntime.queryInterface(XStorable.class,ds); 122 mod2.store(); 123 } catch(Exception e){} 124 }catch(Exception e){} 125 } test2()126 public void test2(){ 127 System.gc(); 128 129 com.sun.star.beans.PropertyValue[] info = null; 130 XDriver drv = null; 131 try{ 132 info = new com.sun.star.beans.PropertyValue[]{ 133 new com.sun.star.beans.PropertyValue("JavaDriverClass",0,"org.hsqldb.jdbcDriver",PropertyState.DIRECT_VALUE) 134 ,new com.sun.star.beans.PropertyValue("ParameterNameSubstitution",0, false,PropertyState.DIRECT_VALUE) 135 }; 136 drv = (XDriver)UnoRuntime.queryInterface(XDriver.class,((XMultiServiceFactory)param.getMSF()).createInstance("com.sun.star.comp.sdbc.JDBCDriver")); 137 TestCacheSize test = new TestCacheSize(((XMultiServiceFactory)param.getMSF()),info,drv); 138 test.setURL("jdbc:hsqldb:g:\\hsql\\db"); 139 140 141 StopWatch sw = new StopWatch(); 142 143 try{ 144 test.setUp(); 145 test.testFillUp(); 146 test.checkResults(); 147 test.tearDown(); 148 System.out.println("Total Test Time: " + sw.elapsedTime()); 149 } catch(Exception e){} 150 }catch(Exception e){} 151 } 152 } 153