LCOV - code coverage report
Current view: top level - include/ucbhelper - resultsetmetadata.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 4 4 100.0 %
Date: 2015-06-13 12:38:46 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_UCBHELPER_RESULTSETMETADATA_HXX
      21             : #define INCLUDED_UCBHELPER_RESULTSETMETADATA_HXX
      22             : 
      23             : #include <vector>
      24             : #include <com/sun/star/uno/Reference.hxx>
      25             : #include <com/sun/star/uno/Sequence.hxx>
      26             : #include <com/sun/star/lang/XTypeProvider.hpp>
      27             : #include <com/sun/star/sdbc/ColumnValue.hpp>
      28             : #include <com/sun/star/sdbc/XResultSetMetaData.hpp>
      29             : #include <cppuhelper/weak.hxx>
      30             : #include <ucbhelper/macros.hxx>
      31             : #include <ucbhelper/ucbhelperdllapi.h>
      32             : 
      33             : namespace com { namespace sun { namespace star {
      34             :     namespace lang  { class XMultiServiceFactory; }
      35             :     namespace beans { struct Property; }
      36             : } } }
      37             : 
      38             : namespace ucbhelper_impl {
      39             :     struct ResultSetMetaData_Impl;
      40             : }
      41             : 
      42             : namespace ucbhelper
      43             : {
      44             : 
      45             : 
      46             : 
      47             : /**
      48             :  * This is a structure that holds additional meta data for one column
      49             :  * of a resultset. The default values set in the constructor should be a
      50             :  * good guess for many UCB use cases.
      51             :  */
      52         210 : struct ResultSetColumnData
      53             : {
      54             :     /** @see ResultSetMetaData::isAutoIncrement */
      55             :     bool        isAutoIncrement;
      56             : 
      57             :     /** @see ResultSetMetaData::isCaseSensitive */
      58             :     bool        isCaseSensitive;
      59             : 
      60             :     /** @see ResultSetMetaData::isSearchable */
      61             :     bool        isSearchable;
      62             : 
      63             :     /** @see ResultSetMetaData::isCurrency */
      64             :     bool        isCurrency;
      65             : 
      66             :     /** @see ResultSetMetaData::isNullable */
      67             :     sal_Int32       isNullable;
      68             : 
      69             :     /** @see ResultSetMetaData::isSigned */
      70             :     bool        isSigned;
      71             : 
      72             :     /** @see ResultSetMetaData::getColumnDisplaySize */
      73             :     sal_Int32       columnDisplaySize;
      74             : 
      75             :     /** @see ResultSetMetaData::getColumnLabel */
      76             :     OUString columnLabel;
      77             : 
      78             :     /** @see ResultSetMetaData::getSchemaName */
      79             :     OUString schemaName;
      80             : 
      81             :     /** @see ResultSetMetaData::getPrecision */
      82             :     sal_Int32       precision;
      83             : 
      84             :     /** @see ResultSetMetaData::getScale */
      85             :     sal_Int32       scale;
      86             : 
      87             :     /** @see ResultSetMetaData::getTableName */
      88             :     OUString tableName;
      89             : 
      90             :     /** @see ResultSetMetaData::getCatalogName */
      91             :     OUString catalogName;
      92             : 
      93             :     /** @see ResultSetMetaData::getColumnTypeName */
      94             :     OUString columnTypeName;
      95             : 
      96             :     /** @see ResultSetMetaData::isReadOnly */
      97             :     bool        isReadOnly;
      98             : 
      99             :     /** @see ResultSetMetaData::isWritable */
     100             :     bool        isWritable;
     101             : 
     102             :     /** @see ResultSetMetaData::isDefinitelyWritable */
     103             :     bool        isDefinitelyWritable;
     104             : 
     105             :     /** @see ResultSetMetaData::getColumnServiceName */
     106             :     OUString columnServiceName;
     107             : 
     108             :     inline ResultSetColumnData();
     109             : };
     110             : 
     111             : // Note: Never change the initial values! Implementations using this struct
     112             : //       may havily depend on the behaviour of the default constructor.
     113             : 
     114          70 : ResultSetColumnData::ResultSetColumnData()
     115             : : isAutoIncrement( false ),
     116             :   isCaseSensitive( true ),
     117             :   isSearchable( false ),
     118             :   isCurrency( false ),
     119             :   isNullable( ::com::sun::star::sdbc::ColumnValue::NULLABLE ),
     120             :   isSigned( false ),
     121             :   columnDisplaySize( 16 ),
     122             :   precision( -1 ),
     123             :   scale( 0 ),
     124             :   isReadOnly( true ),
     125             :   isWritable( false ),
     126          70 :   isDefinitelyWritable( false )
     127             : {
     128          70 : }
     129             : 
     130             : 
     131             : 
     132             : /**
     133             :  * This is an implementation of the interface XResultSetMetaData. It can be
     134             :  * used to implement the interface
     135             :  * com::sun::star::sdbc::XResultSetMetaDataSupplier, which is required for
     136             :  * implementations of service com.sun.star.ucb.ContentResultSet.
     137             :  */
     138             : class UCBHELPER_DLLPUBLIC ResultSetMetaData :
     139             :                 public ::cppu::OWeakObject,
     140             :                 public ::com::sun::star::lang::XTypeProvider,
     141             :                 public ::com::sun::star::sdbc::XResultSetMetaData
     142             : {
     143             : private:
     144             :     ucbhelper_impl::ResultSetMetaData_Impl* m_pImpl;
     145             : 
     146             : protected:
     147             :     ::com::sun::star::uno::Reference<
     148             :         ::com::sun::star::uno::XComponentContext >     m_xContext;
     149             :     ::com::sun::star::uno::Sequence<
     150             :         ::com::sun::star::beans::Property >            m_aProps;
     151             :     bool m_bReadOnly;
     152             : 
     153             : public:
     154             : 
     155             :     /**
     156             :       * Constructor.
     157             :       *
     158             :       * @param rxSMgr is a Servive Manager.
     159             :       * @param rProps is a sequence of properties (partially) describing the
     160             :       *        columns of a resultset.
     161             :       * @param bReadOnly is used to specify whether the whole(!) resultset
     162             :       *        is read-only.
     163             :       */
     164             :     ResultSetMetaData(
     165             :             const ::com::sun::star::uno::Reference<
     166             :                 ::com::sun::star::uno::XComponentContext >& rxContext,
     167             :             const ::com::sun::star::uno::Sequence<
     168             :                 ::com::sun::star::beans::Property >& rProps,
     169             :             bool bReadOnly = true );
     170             : 
     171             :     /**
     172             :       * Constructor.
     173             :       *
     174             :       * @param rxSMgr is a Servive Manager.
     175             :       * @param rProps is a sequence of properties (partially) describing the
     176             :       *        columns of a resultset.
     177             :       * @param rColumnData contains additional meta data for the columns of
     178             :       *        a resultset, which override the default values returned by the
     179             :       *        appropriate methods of this class. The length of rColumnData
     180             :       *        must be the same as length of rProps.
     181             :       *        rColumnData[ 0 ] corresponds to data in rProps[ 0 ],
     182             :       *        rColumnData[ 1 ] corresponds to data in rProps[ 1 ], ...
     183             :       */
     184             :     ResultSetMetaData(
     185             :             const ::com::sun::star::uno::Reference<
     186             :                 ::com::sun::star::uno::XComponentContext >& rxContext,
     187             :             const ::com::sun::star::uno::Sequence<
     188             :                 ::com::sun::star::beans::Property >& rProps,
     189             :             const std::vector< ResultSetColumnData >& rColumnData );
     190             : 
     191             :     /**
     192             :       * Destructor.
     193             :       */
     194             :     virtual ~ResultSetMetaData();
     195             : 
     196             :     // XInterface
     197             :     virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType )
     198             :         throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     199             :     virtual void SAL_CALL acquire()
     200             :         throw() SAL_OVERRIDE;
     201             :     virtual void SAL_CALL release()
     202             :         throw() SAL_OVERRIDE;
     203             : 
     204             :     // XTypeProvider
     205             :     virtual com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL
     206             :     getImplementationId()
     207             :         throw( com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     208             :     virtual com::sun::star::uno::Sequence< com::sun::star::uno::Type > SAL_CALL
     209             :     getTypes()
     210             :         throw( com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     211             : 
     212             :     // XResultSetMetaData
     213             : 
     214             :     /**
     215             :       * Returns the number of columns of the resultset.
     216             :       *
     217             :       * @return the length of the property sequence.
     218             :       */
     219             :     virtual sal_Int32 SAL_CALL
     220             :     getColumnCount()
     221             :         throw( ::com::sun::star::sdbc::SQLException,
     222             :                ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     223             :     /**
     224             :       * Checks whether column is automatically numbered, which makes it
     225             :       * read-only.
     226             :       *
     227             :       * @param  column is the number of the column for that a value shall
     228             :       *         be returned. The first column is 1, the second is 2, ...
     229             :       * @return true, if column is automatically numbered.
     230             :       */
     231             :     virtual sal_Bool SAL_CALL
     232             :     isAutoIncrement( sal_Int32 column )
     233             :         throw( ::com::sun::star::sdbc::SQLException,
     234             :                ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     235             :     /**
     236             :       * Checks whether column is case sensitive.
     237             :       *
     238             :       * @param  column is the number of the column for that a value shall
     239             :       *         be returned. The first column is 1, the second is 2, ...
     240             :       * @return true, if column is case sensitive.
     241             :       */
     242             :     virtual sal_Bool SAL_CALL
     243             :     isCaseSensitive( sal_Int32 column )
     244             :         throw( ::com::sun::star::sdbc::SQLException,
     245             :                ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     246             :     /**
     247             :       * Checks whether the value stored in column can be used in a
     248             :       * WHERE clause.
     249             :       *
     250             :       * @param  column is the number of the column for that a value shall
     251             :       *         be returned. The first column is 1, the second is 2, ...
     252             :       * @return true, if the column is searchable.
     253             :       */
     254             :     virtual sal_Bool SAL_CALL
     255             :     isSearchable( sal_Int32 column )
     256             :         throw( ::com::sun::star::sdbc::SQLException,
     257             :                ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     258             :     /**
     259             :       * Checks whether column is a cash value.
     260             :       *
     261             :       * @param  column is the number of the column for that a value shall
     262             :       *         be returned. The first column is 1, the second is 2, ...
     263             :       * @return true, if the column is a cash value.
     264             :       */
     265             :     virtual sal_Bool SAL_CALL
     266             :     isCurrency( sal_Int32 column )
     267             :         throw( ::com::sun::star::sdbc::SQLException,
     268             :                ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     269             :     /**
     270             :       * Checks whether a NULL can be stored in column.
     271             :       *
     272             :       * @see com::sun::star::sdbc::ColumnValue
     273             :       *
     274             :       * @param  column is the number of the column for that a value shall
     275             :       *         be returned. The first column is 1, the second is 2, ...
     276             :       * @return ::com::sun::star::sdbc::ColumnValue::NULLABLE, if a NULL
     277             :       *         can be stored in the column.
     278             :       */
     279             :     virtual sal_Int32 SAL_CALL
     280             :     isNullable( sal_Int32 column )
     281             :         throw( ::com::sun::star::sdbc::SQLException,
     282             :                ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     283             :     /**
     284             :       * Checks whether the value stored in column is a signed number.
     285             :       *
     286             :       * @param  column is the number of the column for that a value shall
     287             :       *         be returned. The first column is 1, the second is 2, ...
     288             :       * @return true, if the value stored in column is a signed number.
     289             :       */
     290             :     virtual sal_Bool SAL_CALL
     291             :     isSigned( sal_Int32 column )
     292             :         throw( ::com::sun::star::sdbc::SQLException,
     293             :                ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     294             :     /**
     295             :       * Gets the normal maximum width in characters for column.
     296             :       *
     297             :       * @param  column is the number of the column for that a value shall
     298             :       *         be returned. The first column is 1, the second is 2, ...
     299             :       * @return the normal maximum width in characters for column.
     300             :       */
     301             :     virtual sal_Int32 SAL_CALL
     302             :     getColumnDisplaySize( sal_Int32 column )
     303             :         throw( ::com::sun::star::sdbc::SQLException,
     304             :                ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     305             :     /**
     306             :       * Gets the suggested column title for column, to be used in print-
     307             :       * outs and displays.
     308             :       *
     309             :       * @param  column is the number of the column for that a value shall
     310             :       *         be returned. The first column is 1, the second is 2, ...
     311             :       * @return the column label.
     312             :       */
     313             :     virtual OUString SAL_CALL
     314             :     getColumnLabel( sal_Int32 column )
     315             :         throw( ::com::sun::star::sdbc::SQLException,
     316             :                ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     317             :     /**
     318             :       * Gets the name of column.
     319             :       *
     320             :       * @param  column is the number of the column for that a value shall
     321             :       *         be returned. The first column is 1, the second is 2, ...
     322             :       * @return the name of the property that corresponds to column.
     323             :       */
     324             :     virtual OUString SAL_CALL
     325             :     getColumnName( sal_Int32 column )
     326             :         throw( ::com::sun::star::sdbc::SQLException,
     327             :                ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     328             :     /**
     329             :       * Gets the schema name for the table from which column of this
     330             :       * result set was derived.
     331             :       * Because this feature is not widely supported, the return value
     332             :       * for many DBMSs will be an empty string.
     333             :       *
     334             :       * @param  column is the number of the column for that a value shall
     335             :       *         be returned. The first column is 1, the second is 2, ...
     336             :       * @return the schema name of column or an empty string.
     337             :       */
     338             :     virtual OUString SAL_CALL
     339             :     getSchemaName( sal_Int32 column )
     340             :         throw( ::com::sun::star::sdbc::SQLException,
     341             :                ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     342             :     /**
     343             :       * For number types, getprecision gets the number of decimal digits
     344             :       * in column.
     345             :       * For character types, it gets the maximum length in characters for
     346             :       * column.
     347             :       * For binary types, it gets the maximum length in bytes for column.
     348             :       *
     349             :       * @param  column is the number of the column for that a value shall
     350             :       *         be returned. The first column is 1, the second is 2, ...
     351             :       * @return the precision for the column.
     352             :       */
     353             :     virtual sal_Int32 SAL_CALL
     354             :     getPrecision( sal_Int32 column )
     355             :         throw( ::com::sun::star::sdbc::SQLException,
     356             :                ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     357             :     /**
     358             :       * Gets the number of digits to the right of the decimal point for
     359             :       * values in column.
     360             :       *
     361             :       * @param  column is the number of the column for that a value shall
     362             :       *         be returned. The first column is 1, the second is 2, ...
     363             :       * @return the scale of the column.
     364             :       */
     365             :     virtual sal_Int32 SAL_CALL
     366             :     getScale( sal_Int32 column )
     367             :         throw( ::com::sun::star::sdbc::SQLException,
     368             :                ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     369             :     /**
     370             :       * Gets the name of the table from which column of this result set
     371             :       * was derived or "" if there is none (for example, for a join).
     372             :       * Because this feature is not widely supported, the return value
     373             :       * for many DBMSs will be an empty string.
     374             :       *
     375             :       * @param  column is the number of the column for that a value shall
     376             :       *         be returned. The first column is 1, the second is 2, ...
     377             :       * @return the table name for column or an empty string.
     378             :       */
     379             :     virtual OUString SAL_CALL
     380             :     getTableName( sal_Int32 column )
     381             :         throw( ::com::sun::star::sdbc::SQLException,
     382             :                ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     383             :     virtual OUString SAL_CALL
     384             :     /**
     385             :       * Gets the catalog name for the table from which column of this
     386             :       * result set was derived.
     387             :       * Because this feature is not widely supported, the return value
     388             :       * for many DBMSs will be an empty string.
     389             :       *
     390             :       * @param  column is the number of the column for that a value shall
     391             :       *         be returned. The first column is 1, the second is 2, ...
     392             :       * @return the catalog name for column or an empty string.
     393             :       */
     394             :     getCatalogName( sal_Int32 column )
     395             :         throw( ::com::sun::star::sdbc::SQLException,
     396             :                ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     397             :     /**
     398             :       * Gets the JDBC type for the value stored in column. ... The STRUCT
     399             :       * and DISTINCT type codes are always returned for structured and
     400             :       * distinct types, regardless of whether the value will be mapped
     401             :       * according to the standard mapping or be a custom mapping.
     402             :       *
     403             :       * @param  column is the number of the column for that a value shall
     404             :       *         be returned. The first column is 1, the second is 2, ...
     405             :       * @return the type of the property that corresponds to column - mapped
     406             :       *         from UNO-Type to SQL-Type.
     407             :       */
     408             :     virtual sal_Int32 SAL_CALL
     409             :     getColumnType( sal_Int32 column )
     410             :         throw( ::com::sun::star::sdbc::SQLException,
     411             :                ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     412             :     /**
     413             :       * Gets the type name used by this particular data source for the
     414             :       * values stored in column. If the type code for the type of value
     415             :       * stored in column is STRUCT, DISTINCT or JAVA_OBJECT, this method
     416             :       * returns a fully-qualified SQL type name.
     417             :       *
     418             :       * @param  column is the number of the column for that a value shall
     419             :       *         be returned. The first column is 1, the second is 2, ...
     420             :       * @return the column type name.
     421             :       */
     422             :     virtual OUString SAL_CALL
     423             :     getColumnTypeName( sal_Int32 column )
     424             :         throw( ::com::sun::star::sdbc::SQLException,
     425             :                ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     426             :     /**
     427             :       * Indicates whether a column is definitely not writable.
     428             :       *
     429             :       * @param  column is the number of the column for that a value shall
     430             :       *         be returned. The first column is 1, the second is 2, ...
     431             :       * @return true, if the column is definetely not writable.
     432             :       */
     433             :     virtual sal_Bool SAL_CALL
     434             :     isReadOnly( sal_Int32 column )
     435             :         throw( ::com::sun::star::sdbc::SQLException,
     436             :                ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     437             :     /**
     438             :       * Indicates whether it is possible for a write on the column to succeed.
     439             :       *
     440             :       * @param  column is the number of the column for that a value shall
     441             :       *         be returned. The first column is 1, the second is 2, ...
     442             :       * @return true, if it is possible for a write to succeed.
     443             :       */
     444             :     virtual sal_Bool SAL_CALL
     445             :     isWritable( sal_Int32 column )
     446             :         throw( ::com::sun::star::sdbc::SQLException,
     447             :                ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     448             :     /**
     449             :       * Indicates whether a write on the column will definitely succeed.
     450             :       *
     451             :       * @param  column is the number of the column for that a value shall
     452             :       *         be returned. The first column is 1, the second is 2, ...
     453             :       * @return true, if a write on the column will definetely succeed.
     454             :       */
     455             :     virtual sal_Bool SAL_CALL
     456             :     isDefinitelyWritable( sal_Int32 column )
     457             :         throw( ::com::sun::star::sdbc::SQLException,
     458             :                ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     459             :     /**
     460             :       * Returns the fully-qualified name of the service whose instances
     461             :       * are manufactured if the method
     462             :       * com::sun::star::sdbc::ResultSet::getObject is called to retrieve a
     463             :       * value from the column.
     464             :       *
     465             :       * @param  column is the number of the column for that a value shall
     466             :       *         be returned. The first column is 1, the second is 2, ...
     467             :       * @return the service name for column or an empty string, if no service
     468             :       *         is applicable.
     469             :       */
     470             :     virtual OUString SAL_CALL
     471             :     getColumnServiceName( sal_Int32 column )
     472             :         throw( ::com::sun::star::sdbc::SQLException,
     473             :                ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     474             : };
     475             : 
     476             : } // namespace ucbhelper
     477             : 
     478             : #endif /* ! INCLUDED_UCBHELPER_RESULTSETMETADATA_HXX */
     479             : 
     480             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11