LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/include/ucbhelper - resultsetmetadata.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 4 4 100.0 %
Date: 2013-07-09 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 _UCBHELPER_RESULTSETMETADATA_HXX
      21             : #define _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         220 : struct ResultSetColumnData
      53             : {
      54             :     /** @see ResultSetMetaData::isAutoIncrement */
      55             :     sal_Bool        isAutoIncrement;
      56             : 
      57             :     /** @see ResultSetMetaData::isCaseSensitive */
      58             :     sal_Bool        isCaseSensitive;
      59             : 
      60             :     /** @see ResultSetMetaData::isSearchable */
      61             :     sal_Bool        isSearchable;
      62             : 
      63             :     /** @see ResultSetMetaData::isCurrency */
      64             :     sal_Bool        isCurrency;
      65             : 
      66             :     /** @see ResultSetMetaData::isNullable */
      67             :     sal_Int32       isNullable;
      68             : 
      69             :     /** @see ResultSetMetaData::isSigned */
      70             :     sal_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             :     sal_Bool        isReadOnly;
      98             : 
      99             :     /** @see ResultSetMetaData::isWritable */
     100             :     sal_Bool        isWritable;
     101             : 
     102             :     /** @see ResultSetMetaData::isDefinitelyWritable */
     103             :     sal_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          80 : ResultSetColumnData::ResultSetColumnData()
     115             : : isAutoIncrement( sal_False ),
     116             :   isCaseSensitive( sal_True ),
     117             :   isSearchable( sal_False ),
     118             :   isCurrency( sal_False ),
     119             :   isNullable( ::com::sun::star::sdbc::ColumnValue::NULLABLE ),
     120             :   isSigned( sal_False ),
     121             :   columnDisplaySize( 16 ),
     122             :   precision( -1 ),
     123             :   scale( 0 ),
     124             :   isReadOnly( sal_True ),
     125             :   isWritable( sal_False ),
     126          80 :   isDefinitelyWritable( sal_False )
     127             : {
     128          80 : }
     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             :     sal_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             :             sal_Bool bReadOnly = sal_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             :     XINTERFACE_DECL()
     198             : 
     199             :     // XTypeProvider
     200             :     XTYPEPROVIDER_DECL()
     201             : 
     202             :     // XResultSetMetaData
     203             : 
     204             :     /**
     205             :       * Returns the number of columns of the resultset.
     206             :       *
     207             :       * @return the length of the property sequence.
     208             :       */
     209             :     virtual sal_Int32 SAL_CALL
     210             :     getColumnCount()
     211             :         throw( ::com::sun::star::sdbc::SQLException,
     212             :                ::com::sun::star::uno::RuntimeException );
     213             :     /**
     214             :       * Checks whether column is automatically numbered, which makes it
     215             :       * read-only.
     216             :       *
     217             :       * @param  column is the number of the column for that a value shall
     218             :       *         be returned. The first column is 1, the second is 2, ...
     219             :       * @return true, if column is automatically numbered.
     220             :       */
     221             :     virtual sal_Bool SAL_CALL
     222             :     isAutoIncrement( sal_Int32 column )
     223             :         throw( ::com::sun::star::sdbc::SQLException,
     224             :                ::com::sun::star::uno::RuntimeException );
     225             :     /**
     226             :       * Checks whether column is case sensitive.
     227             :       *
     228             :       * @param  column is the number of the column for that a value shall
     229             :       *         be returned. The first column is 1, the second is 2, ...
     230             :       * @return true, if column is case sensitive.
     231             :       */
     232             :     virtual sal_Bool SAL_CALL
     233             :     isCaseSensitive( sal_Int32 column )
     234             :         throw( ::com::sun::star::sdbc::SQLException,
     235             :                ::com::sun::star::uno::RuntimeException );
     236             :     /**
     237             :       * Checks whether the value stored in column can be used in a
     238             :       * WHERE clause.
     239             :       *
     240             :       * @param  column is the number of the column for that a value shall
     241             :       *         be returned. The first column is 1, the second is 2, ...
     242             :       * @return true, if the column is searchable.
     243             :       */
     244             :     virtual sal_Bool SAL_CALL
     245             :     isSearchable( sal_Int32 column )
     246             :         throw( ::com::sun::star::sdbc::SQLException,
     247             :                ::com::sun::star::uno::RuntimeException );
     248             :     /**
     249             :       * Checks whether column is a cash value.
     250             :       *
     251             :       * @param  column is the number of the column for that a value shall
     252             :       *         be returned. The first column is 1, the second is 2, ...
     253             :       * @return true, if the column is a cash value.
     254             :       */
     255             :     virtual sal_Bool SAL_CALL
     256             :     isCurrency( sal_Int32 column )
     257             :         throw( ::com::sun::star::sdbc::SQLException,
     258             :                ::com::sun::star::uno::RuntimeException );
     259             :     /**
     260             :       * Checks whether a NULL can be stored in column.
     261             :       *
     262             :       * @see com::sun::star::sdbc::ColumnValue
     263             :       *
     264             :       * @param  column is the number of the column for that a value shall
     265             :       *         be returned. The first column is 1, the second is 2, ...
     266             :       * @return ::com::sun::star::sdbc::ColumnValue::NULLABLE, if a NULL
     267             :       *         can be stored in the column.
     268             :       */
     269             :     virtual sal_Int32 SAL_CALL
     270             :     isNullable( sal_Int32 column )
     271             :         throw( ::com::sun::star::sdbc::SQLException,
     272             :                ::com::sun::star::uno::RuntimeException );
     273             :     /**
     274             :       * Checks whether the value stored in column is a signed number.
     275             :       *
     276             :       * @param  column is the number of the column for that a value shall
     277             :       *         be returned. The first column is 1, the second is 2, ...
     278             :       * @return true, if the value stored in column is a signed number.
     279             :       */
     280             :     virtual sal_Bool SAL_CALL
     281             :     isSigned( sal_Int32 column )
     282             :         throw( ::com::sun::star::sdbc::SQLException,
     283             :                ::com::sun::star::uno::RuntimeException );
     284             :     /**
     285             :       * Gets the normal maximum width in characters for column.
     286             :       *
     287             :       * @param  column is the number of the column for that a value shall
     288             :       *         be returned. The first column is 1, the second is 2, ...
     289             :       * @return the normal maximum width in characters for column.
     290             :       */
     291             :     virtual sal_Int32 SAL_CALL
     292             :     getColumnDisplaySize( sal_Int32 column )
     293             :         throw( ::com::sun::star::sdbc::SQLException,
     294             :                ::com::sun::star::uno::RuntimeException );
     295             :     /**
     296             :       * Gets the suggested column title for column, to be used in print-
     297             :       * outs and displays.
     298             :       *
     299             :       * @param  column is the number of the column for that a value shall
     300             :       *         be returned. The first column is 1, the second is 2, ...
     301             :       * @return the column label.
     302             :       */
     303             :     virtual OUString SAL_CALL
     304             :     getColumnLabel( sal_Int32 column )
     305             :         throw( ::com::sun::star::sdbc::SQLException,
     306             :                ::com::sun::star::uno::RuntimeException );
     307             :     /**
     308             :       * Gets the name of column.
     309             :       *
     310             :       * @param  column is the number of the column for that a value shall
     311             :       *         be returned. The first column is 1, the second is 2, ...
     312             :       * @return the name of the property that corresponds to column.
     313             :       */
     314             :     virtual OUString SAL_CALL
     315             :     getColumnName( sal_Int32 column )
     316             :         throw( ::com::sun::star::sdbc::SQLException,
     317             :                ::com::sun::star::uno::RuntimeException );
     318             :     /**
     319             :       * Gets the schema name for the table from which column of this
     320             :       * result set was derived.
     321             :       * Because this feature is not widely supported, the return value
     322             :       * for many DBMSs will be an empty string.
     323             :       *
     324             :       * @param  column is the number of the column for that a value shall
     325             :       *         be returned. The first column is 1, the second is 2, ...
     326             :       * @return the schema name of column or an empty string.
     327             :       */
     328             :     virtual OUString SAL_CALL
     329             :     getSchemaName( sal_Int32 column )
     330             :         throw( ::com::sun::star::sdbc::SQLException,
     331             :                ::com::sun::star::uno::RuntimeException );
     332             :     /**
     333             :       * For number types, getprecision gets the number of decimal digits
     334             :       * in column.
     335             :       * For character types, it gets the maximum length in characters for
     336             :       * column.
     337             :       * For binary types, it gets the maximum length in bytes for column.
     338             :       *
     339             :       * @param  column is the number of the column for that a value shall
     340             :       *         be returned. The first column is 1, the second is 2, ...
     341             :       * @return the precision for the column.
     342             :       */
     343             :     virtual sal_Int32 SAL_CALL
     344             :     getPrecision( sal_Int32 column )
     345             :         throw( ::com::sun::star::sdbc::SQLException,
     346             :                ::com::sun::star::uno::RuntimeException );
     347             :     /**
     348             :       * Gets the number of digits to the right of the decimal point for
     349             :       * values in column.
     350             :       *
     351             :       * @param  column is the number of the column for that a value shall
     352             :       *         be returned. The first column is 1, the second is 2, ...
     353             :       * @return the scale of the column.
     354             :       */
     355             :     virtual sal_Int32 SAL_CALL
     356             :     getScale( sal_Int32 column )
     357             :         throw( ::com::sun::star::sdbc::SQLException,
     358             :                ::com::sun::star::uno::RuntimeException );
     359             :     /**
     360             :       * Gets the name of the table from which column of this result set
     361             :       * was derived or "" if there is none (for example, for a join).
     362             :       * Because this feature is not widely supported, the return value
     363             :       * for many DBMSs will be an empty string.
     364             :       *
     365             :       * @param  column is the number of the column for that a value shall
     366             :       *         be returned. The first column is 1, the second is 2, ...
     367             :       * @return the table name for column or an empty string.
     368             :       */
     369             :     virtual OUString SAL_CALL
     370             :     getTableName( sal_Int32 column )
     371             :         throw( ::com::sun::star::sdbc::SQLException,
     372             :                ::com::sun::star::uno::RuntimeException );
     373             :     virtual OUString SAL_CALL
     374             :     /**
     375             :       * Gets the catalog name for the table from which column of this
     376             :       * result set was derived.
     377             :       * Because this feature is not widely supported, the return value
     378             :       * for many DBMSs will be an empty string.
     379             :       *
     380             :       * @param  column is the number of the column for that a value shall
     381             :       *         be returned. The first column is 1, the second is 2, ...
     382             :       * @return the catalog name for column or an empty string.
     383             :       */
     384             :     getCatalogName( sal_Int32 column )
     385             :         throw( ::com::sun::star::sdbc::SQLException,
     386             :                ::com::sun::star::uno::RuntimeException );
     387             :     /**
     388             :       * Gets the JDBC type for the value stored in column. ... The STRUCT
     389             :       * and DISTINCT type codes are always returned for structured and
     390             :       * distinct types, regardless of whether the value will be mapped
     391             :       * according to the standard mapping or be a custom mapping.
     392             :       *
     393             :       * @param  column is the number of the column for that a value shall
     394             :       *         be returned. The first column is 1, the second is 2, ...
     395             :       * @return the type of the property that corresponds to column - mapped
     396             :       *         from UNO-Type to SQL-Type.
     397             :       */
     398             :     virtual sal_Int32 SAL_CALL
     399             :     getColumnType( sal_Int32 column )
     400             :         throw( ::com::sun::star::sdbc::SQLException,
     401             :                ::com::sun::star::uno::RuntimeException );
     402             :     /**
     403             :       * Gets the type name used by this particular data source for the
     404             :       * values stored in column. If the type code for the type of value
     405             :       * stored in column is STRUCT, DISTINCT or JAVA_OBJECT, this method
     406             :       * returns a fully-qualified SQL type name.
     407             :       *
     408             :       * @param  column is the number of the column for that a value shall
     409             :       *         be returned. The first column is 1, the second is 2, ...
     410             :       * @return the column type name.
     411             :       */
     412             :     virtual OUString SAL_CALL
     413             :     getColumnTypeName( sal_Int32 column )
     414             :         throw( ::com::sun::star::sdbc::SQLException,
     415             :                ::com::sun::star::uno::RuntimeException );
     416             :     /**
     417             :       * Indicates whether a column is definitely not writable.
     418             :       *
     419             :       * @param  column is the number of the column for that a value shall
     420             :       *         be returned. The first column is 1, the second is 2, ...
     421             :       * @return true, if the column is definetely not writable.
     422             :       */
     423             :     virtual sal_Bool SAL_CALL
     424             :     isReadOnly( sal_Int32 column )
     425             :         throw( ::com::sun::star::sdbc::SQLException,
     426             :                ::com::sun::star::uno::RuntimeException );
     427             :     /**
     428             :       * Indicates whether it is possible for a write on the column to succeed.
     429             :       *
     430             :       * @param  column is the number of the column for that a value shall
     431             :       *         be returned. The first column is 1, the second is 2, ...
     432             :       * @return true, if it is possible for a write to succeed.
     433             :       */
     434             :     virtual sal_Bool SAL_CALL
     435             :     isWritable( sal_Int32 column )
     436             :         throw( ::com::sun::star::sdbc::SQLException,
     437             :                ::com::sun::star::uno::RuntimeException );
     438             :     /**
     439             :       * Indicates whether a write on the column will definitely succeed.
     440             :       *
     441             :       * @param  column is the number of the column for that a value shall
     442             :       *         be returned. The first column is 1, the second is 2, ...
     443             :       * @return true, if a write on the column will definetely succeed.
     444             :       */
     445             :     virtual sal_Bool SAL_CALL
     446             :     isDefinitelyWritable( sal_Int32 column )
     447             :         throw( ::com::sun::star::sdbc::SQLException,
     448             :                ::com::sun::star::uno::RuntimeException );
     449             :     /**
     450             :       * Returns the fully-qualified name of the service whose instances
     451             :       * are manufactured if the method
     452             :       * com::sun::star::sdbc::ResultSet::getObject is called to retrieve a
     453             :       * value from the column.
     454             :       *
     455             :       * @param  column is the number of the column for that a value shall
     456             :       *         be returned. The first column is 1, the second is 2, ...
     457             :       * @return the service name for column or an empty string, if no service
     458             :       *         is applicable.
     459             :       */
     460             :     virtual OUString SAL_CALL
     461             :     getColumnServiceName( sal_Int32 column )
     462             :         throw( ::com::sun::star::sdbc::SQLException,
     463             :                ::com::sun::star::uno::RuntimeException );
     464             : };
     465             : 
     466             : } // namespace ucbhelper
     467             : 
     468             : #endif /* !_UCBHELPER_RESULTSETMETADATA_HXX */
     469             : 
     470             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10