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 package com.sun.star.comp.sdbc; 22 23 import java.util.concurrent.atomic.AtomicInteger; 24 25 import org.apache.openoffice.comp.sdbc.dbtools.comphelper.ResourceBasedEventLogger; 26 27 public class ConnectionLog extends ResourceBasedEventLogger { 28 public static enum ObjectType { 29 CONNECTION, 30 STATEMENT, 31 RESULT 32 } 33 34 private static final AtomicInteger[] uniqueIds; 35 36 static 37 { 38 uniqueIds = new AtomicInteger[ObjectType.values().length]; 39 for (int i = 0; i < uniqueIds.length; i++) { 40 uniqueIds[i] = new AtomicInteger(0); 41 } 42 } 43 44 private final int objectId; 45 ConnectionLog(ResourceBasedEventLogger logger, ObjectType objectType)46 public ConnectionLog(ResourceBasedEventLogger logger, ObjectType objectType) { 47 super(logger); 48 objectId = uniqueIds[objectType.ordinal()].getAndIncrement(); 49 } 50 getObjectId()51 public int getObjectId() { 52 return objectId; 53 } 54 55 @Override log(int logLevel, int messageResID, Object... arguments)56 public boolean log(int logLevel, int messageResID, Object... arguments) { 57 Object[] argsWithId = new Object[arguments.length + 1]; 58 argsWithId[0] = objectId; 59 System.arraycopy(arguments, 0, argsWithId, 1, arguments.length); 60 return super.log(logLevel, messageResID, argsWithId); 61 } 62 63 @Override logp(int logLevel, int messageResID, Object... arguments)64 public boolean logp(int logLevel, int messageResID, Object... arguments) { 65 Object[] argsWithId = new Object[arguments.length + 1]; 66 argsWithId[0] = objectId; 67 System.arraycopy(arguments, 0, argsWithId, 1, arguments.length); 68 return super.logp(logLevel, messageResID, arguments); 69 } 70 } 71