Package connectivity.tools.sdb

Examples of connectivity.tools.sdb.Connection


    void createStruture() throws SQLException
    {
        m_database.executeSQL("DROP TABLE \"TEST1\" IF EXISTS");
        m_database.executeSQL("CREATE TABLE \"TEST1\" (\"ID\" integer not null primary key, \"col2\" varchar(50) )");

        final Connection connection = m_database.defaultConnection();
        final XPreparedStatement prep = connection.prepareStatement("INSERT INTO \"TEST1\" values (?,?)");
        final XParameters para = UnoRuntime.queryInterface( XParameters.class, prep );
        for (int i = 1; i <= MAX_TABLE_ROWS; ++i)
        {
            para.setInt(1, i);
            para.setString(2, "Test" + i);
            prep.executeUpdate();
        }

        connection.refreshTables();
    }
View Full Code Here


    }

    /* ------------------------------------------------------------------ */
    private boolean ensureTables() throws com.sun.star.uno.Exception,  java.lang.Exception
    {
        Connection connection = new Connection( m_dataSource.getConnection( "", "" ) );
        assure( "could not connect to the data source", connection != null );

        // drop the table, if it already exists
        if  !implExecuteStatement( "DROP TABLE \"" + s_tableName + "\" IF EXISTS" )
            || !implExecuteStatement( getCreateTableStatement() )
            )
        {
            failed( "could not create the required sample table!" );
            return false;
        }

        String sInsertionPrefix = "INSERT INTO \"" + s_tableName + "\" VALUES (";
        String[] aValues = getSampleDataValueString();
        for ( int i=0; i<aValues.length; ++i )
            if ( !implExecuteStatement( sInsertionPrefix + aValues[ i ] + ")" ) )
            {
                failed( "could not create the required sample data" );
                return false;
            }

        connection.refreshTables();

        // do not need the connection anymore
        connection.close();

        return true;
    }
View Full Code Here

    private void impl_createDatabase() throws java.lang.Exception
    {
        try
        {
            m_database = new HsqlDatabase( m_orb );
            Connection connection = m_database.defaultConnection();
            System.out.println( m_database.getDocumentURL() );

            final String[][] fieldDefinitions = impl_getFieldTypeDefinitions();
            final String[] keyTypes = fieldDefinitions[0];
            final String[] keyCreationArgs = fieldDefinitions[1];

            Vector< HsqlColumnDescriptor > foreignKeyColumns = new Vector< HsqlColumnDescriptor >();
            foreignKeyColumns.add( new HsqlColumnDescriptor( "ID", "integer", HsqlColumnDescriptor.PRIMARY ) );

            Vector< String[] > foreignKeyValues = new Vector< String[] >();

            StringBuffer foreignKeyInsertSQL = new StringBuffer();
            foreignKeyInsertSQL.append( "INSERT INTO \"" + m_foreignKeyTableName + "\" VALUES (?" );

            final String[] displayValues = impl_getDisplayValues();

            for ( int i=0; i<keyTypes.length; ++i )
            {
                final String tableName = keyTypes[i] + "_pk";
                final String columnPKName = keyTypes[i] + "_pk";
                final String columnFKName = keyTypes[i] + "_fk";
                final String columnType = keyTypes[i] + ( keyCreationArgs[i] != null ? keyCreationArgs[i] : "" );
                m_database.createTable( new HsqlTableDescriptor( tableName,
                    new HsqlColumnDescriptor[] {
                        new HsqlColumnDescriptor( columnPKName, columnType, HsqlColumnDescriptor.PRIMARY ),
                        new HsqlColumnDescriptor( "content", "varchar(50)" )
                    }
                ) );

                // insert a few rows
                StringBuffer sql = new StringBuffer();
                sql.append( "INSERT INTO \"" );
                sql.append( tableName );
                sql.append( "\" VALUES (?, ?)");
                XPreparedStatement statement = connection.prepareStatement( sql.toString() );
                XParameters statementParameters = UnoRuntime.queryInterface( XParameters.class, statement );

                final String[] keyValues = impl_getTypedValue( keyTypes[i], 0 );

                for ( int row=0; row<displayValues.length; ++row )
                {
                    statementParameters.setString( 1, keyValues[row] );
                    statementParameters.setString( 2, displayValues[row] );
                    statement.execute();
                }

                // remember a column descriptor for later creation of the table with the foreign keys
                foreignKeyColumns.addnew HsqlColumnDescriptor( columnFKName, columnType, HsqlColumnDescriptor.REQUIRED,
                    tableName, columnPKName ) );

                // remember the data to fill into this table
                foreignKeyValues.add( keyValues );
                foreignKeyInsertSQL.append( ", ?" );
            }

            // create the table taking all those foreign keys
            m_database.createTable( new HsqlTableDescriptor( m_foreignKeyTableName, foreignKeyColumns.toArray( new HsqlColumnDescriptor[0] ) ) );
            // fill in some data
            foreignKeyInsertSQL.append( ")" );
            XPreparedStatement statement = connection.prepareStatement( foreignKeyInsertSQL.toString() );
            XParameters statementParameters = UnoRuntime.queryInterface( XParameters.class, statement );
            for ( int row=0; row<2; ++row )
            {
                statementParameters.setInt( 1, row );
                for ( int i=0; i<keyTypes.length; ++i )
View Full Code Here

      PropertyValue[] loadArgs = new PropertyValue[] {
        new PropertyValue( "PickListEntry", 0, false, PropertyState.DIRECT_VALUE )
      };
            loader.loadComponentFromURL( m_database.getDocumentURL(), "_blank", 0, loadArgs );
            getDocumentUI().connect();
            m_connection = new Connection( getDocumentUI().getActiveConnection() );
    }
        else
        {
            m_connection = m_database.defaultConnection();
        }
View Full Code Here

     * the ownership of the connection, so you don't need to (and should not) dispose/close it.
     */
    public Connection defaultConnection() throws SQLException
    {
        if ( m_connection == null )
            m_connection = new Connection( m_databaseDocument.getDataSource().getConnection("", "") );
       
        return m_connection;
    }
View Full Code Here

      PropertyValue[] loadArgs = new PropertyValue[] {
        new PropertyValue( "PickListEntry", 0, false, PropertyState.DIRECT_VALUE )
      };
            loader.loadComponentFromURL( m_database.getDocumentURL(), "_blank", 0, loadArgs );
            getDocumentUI().connect();
            m_connection = new Connection( getDocumentUI().getActiveConnection() );
    }
        else
        {
            m_connection = m_database.defaultConnection();
        }
View Full Code Here

    void createStruture() throws SQLException
    {
        m_database.executeSQL("DROP TABLE \"TEST1\" IF EXISTS");
        m_database.executeSQL("CREATE TABLE \"TEST1\" (\"ID\" integer not null primary key, \"col2\" varchar(50) )");

        final Connection connection = m_database.defaultConnection();
        final XPreparedStatement prep = connection.prepareStatement("INSERT INTO \"TEST1\" values (?,?)");
        final XParameters para = UnoRuntime.queryInterface( XParameters.class, prep );
        for (int i = 1; i <= MAX_TABLE_ROWS; ++i)
        {
            para.setInt(1, i);
            para.setString(2, "Test" + i);
            prep.executeUpdate();
        }

        connection.refreshTables();
    }
View Full Code Here

      PropertyValue[] loadArgs = new PropertyValue[] {
        new PropertyValue( "PickListEntry", 0, false, PropertyState.DIRECT_VALUE )
      };
            loader.loadComponentFromURL( m_database.getDocumentURL(), "_blank", 0, loadArgs );
            getDocumentUI().connect();
            m_connection = new Connection( getDocumentUI().getActiveConnection() );
    }
        else
        {
            m_connection = m_database.defaultConnection();
        }
View Full Code Here

    private void impl_createDatabase() throws java.lang.Exception
    {
        try
        {
            m_database = new HsqlDatabase( m_orb );
            Connection connection = m_database.defaultConnection();
            System.out.println( m_database.getDocumentURL() );

            final String[][] fieldDefinitions = impl_getFieldTypeDefinitions();
            final String[] keyTypes = fieldDefinitions[0];
            final String[] keyCreationArgs = fieldDefinitions[1];

            Vector< HsqlColumnDescriptor > foreignKeyColumns = new Vector< HsqlColumnDescriptor >();
            foreignKeyColumns.add( new HsqlColumnDescriptor( "ID", "integer", HsqlColumnDescriptor.PRIMARY ) );

            Vector< String[] > foreignKeyValues = new Vector< String[] >();

            StringBuffer foreignKeyInsertSQL = new StringBuffer();
            foreignKeyInsertSQL.append( "INSERT INTO \"" + m_foreignKeyTableName + "\" VALUES (?" );

            final String[] displayValues = impl_getDisplayValues();

            for ( int i=0; i<keyTypes.length; ++i )
            {
                final String tableName = keyTypes[i] + "_pk";
                final String columnPKName = keyTypes[i] + "_pk";
                final String columnFKName = keyTypes[i] + "_fk";
                final String columnType = keyTypes[i] + ( keyCreationArgs[i] != null ? keyCreationArgs[i] : "" );
                m_database.createTable( new HsqlTableDescriptor( tableName,
                    new HsqlColumnDescriptor[] {
                        new HsqlColumnDescriptor( columnPKName, columnType, HsqlColumnDescriptor.PRIMARY ),
                        new HsqlColumnDescriptor( "content", "varchar(50)" )
                    }
                ) );

                // insert a few rows
                StringBuffer sql = new StringBuffer();
                sql.append( "INSERT INTO \"" );
                sql.append( tableName );
                sql.append( "\" VALUES (?, ?)");
                XPreparedStatement statement = connection.prepareStatement( sql.toString() );
                XParameters statementParameters = UnoRuntime.queryInterface( XParameters.class, statement );

                final String[] keyValues = impl_getTypedValue( keyTypes[i], 0 );

                for ( int row=0; row<displayValues.length; ++row )
                {
                    statementParameters.setString( 1, keyValues[row] );
                    statementParameters.setString( 2, displayValues[row] );
                    statement.execute();
                }

                // remember a column descriptor for later creation of the table with the foreign keys
                foreignKeyColumns.addnew HsqlColumnDescriptor( columnFKName, columnType, HsqlColumnDescriptor.REQUIRED,
                    tableName, columnPKName ) );

                // remember the data to fill into this table
                foreignKeyValues.add( keyValues );
                foreignKeyInsertSQL.append( ", ?" );
            }

            // create the table taking all those foreign keys
            m_database.createTable( new HsqlTableDescriptor( m_foreignKeyTableName, foreignKeyColumns.toArray( new HsqlColumnDescriptor[0] ) ) );
            // fill in some data
            foreignKeyInsertSQL.append( ")" );
            XPreparedStatement statement = connection.prepareStatement( foreignKeyInsertSQL.toString() );
            XParameters statementParameters = UnoRuntime.queryInterface( XParameters.class, statement );
            for ( int row=0; row<2; ++row )
            {
                statementParameters.setInt( 1, row );
                for ( int i=0; i<keyTypes.length; ++i )
View Full Code Here

    }

    /* ------------------------------------------------------------------ */
    private boolean ensureTables() throws com.sun.star.uno.Exception,  java.lang.Exception
    {
        Connection connection = new Connection( m_dataSource.getConnection( "", "" ) );
        assure( "could not connect to the data source", connection != null );

        // drop the table, if it already exists
        if  !implExecuteStatement( "DROP TABLE \"" + s_tableName + "\" IF EXISTS" )
            || !implExecuteStatement( getCreateTableStatement() )
            )
        {
            failed( "could not create the required sample table!" );
            return false;
        }

        String sInsertionPrefix = "INSERT INTO \"" + s_tableName + "\" VALUES (";
        String[] aValues = getSampleDataValueString();
        for ( int i=0; i<aValues.length; ++i )
            if ( !implExecuteStatement( sInsertionPrefix + aValues[ i ] + ")" ) )
            {
                failed( "could not create the required sample data" );
                return false;
            }

        connection.refreshTables();

        // do not need the connection anymore
        connection.close();

        return true;
    }
View Full Code Here

TOP

Related Classes of connectivity.tools.sdb.Connection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.