diff options
Diffstat (limited to 'dbaccess/source/core/api/OptimisticSet.cxx')
-rw-r--r-- | dbaccess/source/core/api/OptimisticSet.cxx | 92 |
1 files changed, 31 insertions, 61 deletions
diff --git a/dbaccess/source/core/api/OptimisticSet.cxx b/dbaccess/source/core/api/OptimisticSet.cxx index ed522c1aa..8e8fc2386 100644 --- a/dbaccess/source/core/api/OptimisticSet.cxx +++ b/dbaccess/source/core/api/OptimisticSet.cxx @@ -1,14 +1,13 @@ + +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * + * * Copyright 2008 by Sun Microsystems, Inc. * * OpenOffice.org - a multi-platform office productivity suite * - * $RCSfile: OptimisticSet.cxx,v $ - * $Revision: 1.73 $ - * * This file is part of OpenOffice.org. * * OpenOffice.org is free software: you can redistribute it and/or modify @@ -98,7 +97,7 @@ namespace } DBG_NAME(OptimisticSet) -// ------------------------------------------------------------------------- + OptimisticSet::OptimisticSet(const ::comphelper::ComponentContext& _rContext, const Reference< XConnection>& i_xConnection, const Reference< XSingleSelectQueryAnalyzer >& _xComposer, @@ -113,12 +112,12 @@ OptimisticSet::OptimisticSet(const ::comphelper::ComponentContext& _rContext, RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::OptimisticSet" ); DBG_CTOR(OptimisticSet,NULL); } -// ----------------------------------------------------------------------------- + OptimisticSet::~OptimisticSet() { DBG_DTOR(OptimisticSet,NULL); } -// ----------------------------------------------------------------------------- + void OptimisticSet::construct(const Reference< XResultSet>& _xDriverSet,const ::rtl::OUString& i_sRowSetFilter) { RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::construct" ); @@ -174,23 +173,23 @@ void OptimisticSet::construct(const Reference< XResultSet>& _xDriverSet,const :: m_xStatement = m_xConnection->prepareStatement(xAnalyzer->getQueryWithSubstitution()); ::comphelper::disposeComponent(xAnalyzer); } -// ------------------------------------------------------------------------- + // ::com::sun::star::sdbcx::XDeleteRows Sequence< sal_Int32 > SAL_CALL OptimisticSet::deleteRows( const Sequence< Any >& /*rows*/ ,const connectivity::OSQLTable& /*_xTable*/) throw(SQLException, RuntimeException) { Sequence< sal_Int32 > aRet; return aRet; } -// ------------------------------------------------------------------------- + void SAL_CALL OptimisticSet::updateRow(const ORowSetRow& _rInsertRow ,const ORowSetRow& _rOrginalRow,const connectivity::OSQLTable& /*_xTable*/ ) throw(SQLException, RuntimeException) { RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::updateRow" ); if ( m_aJoinedKeyColumns.empty() ) throw SQLException(); // list all cloumns that should be set - static ::rtl::OUString s_sPara = ::rtl::OUString::createFromAscii(" = ?"); + static ::rtl::OUString s_sPara(RTL_CONSTASCII_USTRINGPARAM(" = ?")); ::rtl::OUString aQuote = getIdentifierQuoteString(); - static ::rtl::OUString aAnd = ::rtl::OUString::createFromAscii(" AND "); + static ::rtl::OUString aAnd(RTL_CONSTASCII_USTRINGPARAM(" AND ")); ::rtl::OUString sIsNull(RTL_CONSTASCII_USTRINGPARAM(" IS NULL")); ::rtl::OUString sParam(RTL_CONSTASCII_USTRINGPARAM(" = ?")); @@ -201,7 +200,6 @@ void SAL_CALL OptimisticSet::updateRow(const ORowSetRow& _rInsertRow ,const ORow TSQLStatements aIndexConditions; TSQLStatements aSql; - // sal_Int32 i = 1; // here we build the condition part for the update statement SelectColumnsMetaData::const_iterator aIter = m_pColumnNames->begin(); SelectColumnsMetaData::const_iterator aEnd = m_pColumnNames->end(); @@ -258,10 +256,8 @@ void SAL_CALL OptimisticSet::updateRow(const ORowSetRow& _rInsertRow ,const ORow sSql.append(s_sSET); sSql.append(aSqlIter->second); ::rtl::OUStringBuffer& rCondition = aKeyConditions[aSqlIter->first]; - bool bAddWhere = true; if ( rCondition.getLength() ) { - bAddWhere = false; sSql.appendAscii(" WHERE "); sSql.append( rCondition ); } @@ -269,7 +265,7 @@ void SAL_CALL OptimisticSet::updateRow(const ORowSetRow& _rInsertRow ,const ORow } } } -// ------------------------------------------------------------------------- + void SAL_CALL OptimisticSet::insertRow( const ORowSetRow& _rInsertRow,const connectivity::OSQLTable& /*_xTable*/ ) throw(SQLException, RuntimeException) { RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::insertRow" ); @@ -278,10 +274,10 @@ void SAL_CALL OptimisticSet::insertRow( const ORowSetRow& _rInsertRow,const conn TSQLStatements aKeyConditions; ::std::map< ::rtl::OUString,bool > aResultSetChanged; ::rtl::OUString aQuote = getIdentifierQuoteString(); - static ::rtl::OUString aAnd = ::rtl::OUString::createFromAscii(" AND "); + static ::rtl::OUString aAnd(RTL_CONSTASCII_USTRINGPARAM(" AND ")); ::rtl::OUString sIsNull(RTL_CONSTASCII_USTRINGPARAM(" IS NULL")); ::rtl::OUString sParam(RTL_CONSTASCII_USTRINGPARAM(" = ?")); - + // here we build the condition part for the update statement SelectColumnsMetaData::const_iterator aIter = m_pColumnNames->begin(); SelectColumnsMetaData::const_iterator aEnd = m_pColumnNames->end(); @@ -289,7 +285,7 @@ void SAL_CALL OptimisticSet::insertRow( const ORowSetRow& _rInsertRow,const conn { if ( aResultSetChanged.find( aIter->second.sTableName ) == aResultSetChanged.end() ) aResultSetChanged[aIter->second.sTableName] = false; - + const ::rtl::OUString sQuotedColumnName = ::dbtools::quoteName( aQuote,aIter->second.sRealName); if ( (_rInsertRow->get())[aIter->second.nPosition].isModified() ) { @@ -368,19 +364,19 @@ void SAL_CALL OptimisticSet::insertRow( const ORowSetRow& _rInsertRow,const conn if ( xRow.is() && xRes->next() ) { m_bResultSetChanged = true; - continue; + continue; } } catch(const SQLException&) { } } - + executeInsert(_rInsertRow,sSql.makeStringAndClear(),aSqlIter->first); } } } -// ------------------------------------------------------------------------- + void SAL_CALL OptimisticSet::deleteRow(const ORowSetRow& _rDeleteRow,const connectivity::OSQLTable& /*_xTable*/ ) throw(SQLException, RuntimeException) { ::rtl::OUString sParam(RTL_CONSTASCII_USTRINGPARAM(" = ?")); @@ -394,7 +390,6 @@ void SAL_CALL OptimisticSet::deleteRow(const ORowSetRow& _rDeleteRow,const conne TSQLStatements aIndexConditions; TSQLStatements aSql; - // sal_Int32 i = 1; // here we build the condition part for the update statement SelectColumnsMetaData::const_iterator aIter = m_pColumnNames->begin(); SelectColumnsMetaData::const_iterator aEnd = m_pColumnNames->end(); @@ -426,12 +421,12 @@ void SAL_CALL OptimisticSet::deleteRow(const ORowSetRow& _rDeleteRow,const conne } } } -// ------------------------------------------------------------------------- + void OptimisticSet::executeDelete(const ORowSetRow& _rDeleteRow,const ::rtl::OUString& i_sSQL,const ::rtl::OUString& i_sTableName) { RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::executeDelete" ); - // now create end execute the prepared statement + // now create and execute the prepared statement Reference< XPreparedStatement > xPrep(m_xConnection->prepareStatement(i_sSQL)); Reference< XParameters > xParameter(xPrep,UNO_QUERY); @@ -454,41 +449,17 @@ void OptimisticSet::executeDelete(const ORowSetRow& _rDeleteRow,const ::rtl::OUS m_bDeleted = sal_True; } } -// ----------------------------------------------------------------------------- + ::rtl::OUString OptimisticSet::getComposedTableName(const ::rtl::OUString& /*_sCatalog*/, const ::rtl::OUString& /*_sSchema*/, const ::rtl::OUString& /*_sTable*/) { RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::getComposedTableName" ); ::rtl::OUString aComposedName; -/* - Reference<XDatabaseMetaData> xMetaData = m_xConnection->getMetaData(); - if( xMetaData.is() && xMetaData->supportsTableCorrelationNames() ) - { - aComposedName = ::dbtools::composeTableName( xMetaData, _sCatalog, _sSchema, _sTable, sal_False, ::dbtools::eInDataManipulation ); - // first we have to check if the composed tablename is in the select clause or if an alias is used - Reference<XTablesSupplier> xTabSup(m_xComposer,UNO_QUERY); - Reference<XNameAccess> xSelectTables = xTabSup->getTables(); - OSL_ENSURE(xSelectTables.is(),"No Select tables!"); - if(xSelectTables.is()) - { - if(!xSelectTables->hasByName(aComposedName)) - { // the composed name isn't used in the select clause so we have to find out which name is used instead - ::rtl::OUString sCatalog,sSchema,sTable; - ::dbtools::qualifiedNameComponents(xMetaData,m_sUpdateTableName,sCatalog,sSchema,sTable,::dbtools::eInDataManipulation); - aComposedName = ::dbtools::composeTableNameForSelect( m_xConnection, sCatalog, sSchema, sTable ); - } - else - aComposedName = ::dbtools::composeTableNameForSelect( m_xConnection, _sCatalog, _sSchema, _sTable ); - } - } - else - aComposedName = ::dbtools::composeTableNameForSelect( m_xConnection, _sCatalog, _sSchema, _sTable ); -*/ return aComposedName; } -// ----------------------------------------------------------------------------- + void OptimisticSet::fillJoinedColumns_throw(const ::std::vector< TNodePair >& i_aJoinColumns) { ::std::vector< TNodePair >::const_iterator aIter = i_aJoinColumns.begin(); @@ -507,9 +478,9 @@ void OptimisticSet::fillJoinedColumns_throw(const ::std::vector< TNodePair >& i_ fillJoinedColumns_throw(sLeft.makeStringAndClear(),sRight.makeStringAndClear()); } } -// ----------------------------------------------------------------------------- + void OptimisticSet::fillJoinedColumns_throw(const ::rtl::OUString& i_sLeftColumn,const ::rtl::OUString& i_sRightColumn) -{ +{ sal_Int32 nLeft = 0,nRight = 0; SelectColumnsMetaData::const_iterator aLeftIter = m_pKeyColumnNames->find(i_sLeftColumn); SelectColumnsMetaData::const_iterator aRightIter = m_pKeyColumnNames->find(i_sRightColumn); @@ -547,14 +518,14 @@ void OptimisticSet::fillJoinedColumns_throw(const ::rtl::OUString& i_sLeftColumn else m_aJoinedColumns[nRight] = nLeft; } -// ----------------------------------------------------------------------------- + bool OptimisticSet::isResultSetChanged() const { bool bOld = m_bResultSetChanged; m_bResultSetChanged = false; return bOld; } -// ----------------------------------------------------------------------------- + void OptimisticSet::reset(const Reference< XResultSet>& _xDriverSet) { OCacheSet::construct(_xDriverSet,::rtl::OUString()); @@ -563,7 +534,7 @@ void OptimisticSet::reset(const Reference< XResultSet>& _xDriverSet) m_aKeyMap.insert(OKeySetMatrix::value_type(0,OKeySetValue(NULL,::std::pair<sal_Int32,Reference<XRow> >(0,NULL)))); m_aKeyIter = m_aKeyMap.begin(); } -// ----------------------------------------------------------------------------- + void OptimisticSet::mergeColumnValues(sal_Int32 i_nColumnIndex,ORowSetValueVector::Vector& io_aInsertRow,ORowSetValueVector::Vector& io_aRow,::std::vector<sal_Int32>& o_aChangedColumns) { o_aChangedColumns.push_back(i_nColumnIndex); @@ -605,7 +576,7 @@ namespace } }; } -// ----------------------------------------------------------------------------- + bool OptimisticSet::updateColumnValues(const ORowSetValueVector::Vector& io_aCachedRow,ORowSetValueVector::Vector& io_aRow,const ::std::vector<sal_Int32>& i_aChangedColumns) { bool bRet = false; @@ -642,7 +613,7 @@ bool OptimisticSet::updateColumnValues(const ORowSetValueVector::Vector& io_aCac } return bRet; } -// ----------------------------------------------------------------------------- + bool OptimisticSet::columnValuesUpdated(ORowSetValueVector::Vector& o_aCachedRow,const ORowSetValueVector::Vector& i_aRow) { bool bRet = false; @@ -681,14 +652,14 @@ bool OptimisticSet::columnValuesUpdated(ORowSetValueVector::Vector& o_aCachedRow } return bRet; } -// ----------------------------------------------------------------------------- + void OptimisticSet::fillMissingValues(ORowSetValueVector::Vector& io_aRow) const { TSQLStatements aSql; TSQLStatements aKeyConditions; ::std::map< ::rtl::OUString,bool > aResultSetChanged; ::rtl::OUString aQuote = getIdentifierQuoteString(); - static ::rtl::OUString aAnd = ::rtl::OUString::createFromAscii(" AND "); + static ::rtl::OUString aAnd(RTL_CONSTASCII_USTRINGPARAM(" AND ")); ::rtl::OUString sIsNull(RTL_CONSTASCII_USTRINGPARAM(" IS NULL")); ::rtl::OUString sParam(RTL_CONSTASCII_USTRINGPARAM(" = ?")); // here we build the condition part for the update statement @@ -765,5 +736,4 @@ void OptimisticSet::fillMissingValues(ORowSetValueVector::Vector& io_aRow) const } } } -// ----------------------------------------------------------------------------- - +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |