1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_connectivity.hxx"
26 
27 #include "java/sql/ConnectionLog.hxx"
28 
29 /** === begin UNO includes === **/
30 #include <com/sun/star/util/Date.hpp>
31 #include <com/sun/star/util/Time.hpp>
32 #include <com/sun/star/util/DateTime.hpp>
33 /** === end UNO includes === **/
34 
35 #include <stdio.h>
36 
37 //........................................................................
38 namespace connectivity { namespace java { namespace sql {
39 //........................................................................
40 
41 	/** === begin UNO using === **/
42     using ::com::sun::star::uno::Reference;
43     using ::com::sun::star::uno::XComponentContext;
44 	/** === end UNO using === **/
45 
46 	//--------------------------------------------------------------------
47     namespace
48     {
lcl_getFreeID(ConnectionLog::ObjectType _eType)49         sal_Int32 lcl_getFreeID( ConnectionLog::ObjectType _eType )
50         {
51             static oslInterlockedCount s_nCounts[ ConnectionLog::ObjectTypeCount ] = { 0, 0 };
52             return osl_incrementInterlockedCount( s_nCounts + _eType );
53         }
54     }
55 
56 	//====================================================================
57 	//= ConnectionLog
58 	//====================================================================
59 	//--------------------------------------------------------------------
ConnectionLog(const::comphelper::ResourceBasedEventLogger & _rDriverLog)60     ConnectionLog::ConnectionLog( const ::comphelper::ResourceBasedEventLogger& _rDriverLog )
61         :ConnectionLog_Base( _rDriverLog )
62         ,m_nObjectID( lcl_getFreeID( CONNECTION ) )
63     {
64     }
65 
66 	//--------------------------------------------------------------------
ConnectionLog(const ConnectionLog & _rSourceLog)67     ConnectionLog::ConnectionLog( const ConnectionLog& _rSourceLog )
68         :ConnectionLog_Base( _rSourceLog )
69         ,m_nObjectID( _rSourceLog.m_nObjectID )
70     {
71     }
72 
73 	//--------------------------------------------------------------------
ConnectionLog(const ConnectionLog & _rSourceLog,ConnectionLog::ObjectType _eType)74     ConnectionLog::ConnectionLog( const ConnectionLog& _rSourceLog, ConnectionLog::ObjectType _eType )
75         :ConnectionLog_Base( _rSourceLog )
76         ,m_nObjectID( lcl_getFreeID( _eType ) )
77     {
78     }
79 
80 //........................................................................
81 } } } // namespace connectivity::java::sql
82 //........................................................................
83 
84 //........................................................................
85 namespace comphelper { namespace log { namespace convert
86 {
87 //........................................................................
88 
89 	/** === begin UNO using === **/
90     using ::com::sun::star::uno::Reference;
91     using ::com::sun::star::uno::XComponentContext;
92     using ::com::sun::star::util::Date;
93     using ::com::sun::star::util::Time;
94     using ::com::sun::star::util::DateTime;
95 	/** === end UNO using === **/
96 
97     //--------------------------------------------------------------------
convertLogArgToString(const Date & _rDate)98     ::rtl::OUString convertLogArgToString( const Date& _rDate )
99     {
100         char buffer[ 30 ];
101         const size_t buffer_size = sizeof( buffer );
102         snprintf( buffer, buffer_size, "%04i-%02i-%02i",
103             (int)_rDate.Year, (int)_rDate.Month, (int)_rDate.Day );
104         return ::rtl::OUString::createFromAscii( buffer );
105     }
106 
107     //--------------------------------------------------------------------
convertLogArgToString(const Time & _rTime)108     ::rtl::OUString convertLogArgToString( const Time& _rTime )
109     {
110         char buffer[ 30 ];
111         const size_t buffer_size = sizeof( buffer );
112         snprintf( buffer, buffer_size, "%02i:%02i:%02i.%02i",
113             (int)_rTime.Hours, (int)_rTime.Minutes, (int)_rTime.Seconds, (int)_rTime.HundredthSeconds );
114         return ::rtl::OUString::createFromAscii( buffer );
115     }
116 
117     //--------------------------------------------------------------------
convertLogArgToString(const DateTime & _rDateTime)118     ::rtl::OUString convertLogArgToString( const DateTime& _rDateTime )
119     {
120         char buffer[ 30 ];
121         const size_t buffer_size = sizeof( buffer );
122         snprintf( buffer, buffer_size, "%04i-%02i-%02i %02i:%02i:%02i.%02i",
123             (int)_rDateTime.Year, (int)_rDateTime.Month, (int)_rDateTime.Day,
124             (int)_rDateTime.Hours, (int)_rDateTime.Minutes, (int)_rDateTime.Seconds, (int)_rDateTime.HundredthSeconds );
125         return ::rtl::OUString::createFromAscii( buffer );
126     }
127 
128 //........................................................................
129 } } }   // comphelper::log::convert
130 //........................................................................
131