Tag: cws_src680_dba202f User: fs Date: 06/01/23 08:15:23 Modified: /dba/connectivity/qa/connectivity/tools/ HsqlDatabase.java
Log: +closeAndDelete / +createTable File Changes: Directory: /dba/connectivity/qa/connectivity/tools/ =================================================== File [changed]: HsqlDatabase.java Url: http://dba.openoffice.org/source/browse/dba/connectivity/qa/connectivity/tools/HsqlDatabase.java?r1=1.1.2.1&r2=1.1.2.2 Delta lines: +96 -16 --------------------- --- HsqlDatabase.java 23 Jan 2006 12:16:49 -0000 1.1.2.1 +++ HsqlDatabase.java 23 Jan 2006 16:15:19 -0000 1.1.2.2 @@ -1,12 +1,37 @@ -/* - * HsqlDatabase.java +/************************************************************************* * - * Created on 18. Januar 2006, 11:40 + * OpenOffice.org - a multi-platform office productivity suite * - * To change this template, choose Tools | Options and locate the template under - * the Source Creation and Management node. Right-click the template and choose - * Open. You can then make changes to the template in the Source Editor. - */ + * $RCSfile: HsqlDatabase.java,v $ + * + * $Revision: 1.1.2.2 $ + * + * last change: $Author: fs $ $Date: 2006/01/23 16:15:19 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ package connectivity.tools; @@ -76,7 +101,7 @@ /** executes the given SQL statement via the defaultConnection */ - public void executeStatement( String statementString ) throws SQLException + public void executeSQL( String statementString ) throws SQLException { XStatement statement = defaultConnection().createStatement(); statement.execute( statementString ); @@ -120,15 +145,14 @@ m_databaseDocument = null; } - public String getDocumentURL() - { - return m_databaseDocumentFile; - } - - protected void finalize() throws Throwable + /** closes the document, and deletes the underlying file + */ + public void closeAndDelete() { close(); + if ( m_databaseDocumentFile != null ) + { try { File file = new File(m_databaseDocumentFile); @@ -137,6 +161,62 @@ catch(Exception e) { } + m_databaseDocumentFile = null; + } + } + + /** creates a table + */ + public void createTable( HsqlTableDescriptor _tableDesc ) throws SQLException + { + String createStatement = "CREATE TABLE \""; + createStatement += _tableDesc.getName(); + createStatement += "\" ( "; + + String primaryKeyList = ""; + + HsqlColumnDescriptor[] columns = _tableDesc.getColumns(); + for ( int i=0; i<columns.length; ++i ) + { + if ( i > 0 ) + createStatement += ", "; + + createStatement += "\"" + columns[i].Name; + createStatement += "\"" + columns[i].TypeName; + + if ( columns[i].NotNull ) + createStatement += " NOT NULL"; + + if ( columns[i].PrimaryKey ) + { + if ( primaryKeyList.length() > 0 ) + primaryKeyList += ", "; + primaryKeyList += "\"" + columns[i].Name + "\""; + } + } + + if ( primaryKeyList.length() > 0 ) + { + createStatement += ", PRIMARY KEY ("; + createStatement += primaryKeyList; + createStatement += ")"; + } + + createStatement += ")"; + + executeSQL( createStatement ); + } + + /** returns the URL of the ODB document represented by this instance + */ + public String getDocumentURL() + { + return m_databaseDocumentFile; + } + + protected void finalize() throws Throwable + { + closeAndDelete(); super.finalize(); } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
