tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdan...@apache.org
Subject svn commit: r443109 [2/2] - in /incubator/tuscany/java/das/rdb: ./ src/main/java/org/apache/tuscany/das/rdb/config/wrapper/ src/main/java/org/apache/tuscany/das/rdb/generator/impl/ src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/ src/main/ja...
Date Wed, 13 Sep 2006 20:21:33 GMT
Modified: incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/Parameters.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/Parameters.java?view=diff&rev=443109&r1=443108&r2=443109
==============================================================================
--- incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/Parameters.java
(original)
+++ incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/Parameters.java
Wed Sep 13 13:21:31 2006
@@ -6,15 +6,15 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *   http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
- * under the License.    
+ * under the License.
  */
 package org.apache.tuscany.das.rdb.impl;
 
@@ -22,19 +22,19 @@
 import java.util.Iterator;
 import java.util.List;
 
-import org.apache.tuscany.das.rdb.util.DebugUtil;
+import org.apache.log4j.Logger;
+import org.apache.tuscany.das.rdb.util.LoggerFactory;
 
 import commonj.sdo.Type;
 
 public class Parameters {
+    private final Logger logger = LoggerFactory.INSTANCE.getLogger(Parameters.class);
 
 	private ArrayList parameters = new ArrayList();
 
 	private ArrayList inParams = new ArrayList();
 
-	private ArrayList outParams = new ArrayList();	
-
-	private static boolean debug = false;
+	private ArrayList outParams = new ArrayList();
 
 	public Parameters() {
 		super();
@@ -52,14 +52,14 @@
 		return inParams;
 	}
 
-	private void addParameter(ParameterImpl param) {		
+	private void addParameter(ParameterImpl param) {
 		if (param.getDirection() == ParameterImpl.IN)
 			inParams.add(param);
 		else if ((param.getDirection() == ParameterImpl.OUT)
 				|| (param.getDirection() == ParameterImpl.IN_OUT))
 			outParams.add(param);
 
-		this.parameters.add(param);		
+		this.parameters.add(param);
 	}
 
 	public void add(ParameterImpl param) {
@@ -75,8 +75,9 @@
 			if (param.getIndex() == index)
 				return param;
 		}
-		DebugUtil.debugln(getClass(), debug,
-				"Creating new parameter with index " + index);
+        if(this.logger.isDebugEnabled())
+            this.logger.debug("Creating new parameter with index " + index);
+
 		ParameterImpl newParam = new ParameterImpl(index);
 		newParam.setDirection(direction);
 		newParam.setType(sdoType);
@@ -97,7 +98,7 @@
 		param.setValue(value);
 	}
 
-    
+
     public ParameterImpl parameterWithIndex(int index) {
 		Iterator i = parameters.iterator();
 		while (i.hasNext()) {

Modified: incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/SPCommandImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/SPCommandImpl.java?view=diff&rev=443109&r1=443108&r2=443109
==============================================================================
--- incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/SPCommandImpl.java
(original)
+++ incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/SPCommandImpl.java
Wed Sep 13 13:21:31 2006
@@ -6,15 +6,15 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *   http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
- * under the License.    
+ * under the License.
  */
 package org.apache.tuscany.das.rdb.impl;
 
@@ -22,16 +22,18 @@
 import java.util.Iterator;
 import java.util.List;
 
+import org.apache.log4j.Logger;
 import org.apache.tuscany.das.rdb.config.Parameter;
 import org.apache.tuscany.das.rdb.config.wrapper.MappingWrapper;
-import org.apache.tuscany.das.rdb.util.DebugUtil;
+import org.apache.tuscany.das.rdb.util.LoggerFactory;
 
 import commonj.sdo.DataObject;
 import commonj.sdo.Type;
 import commonj.sdo.helper.TypeHelper;
 
 public class SPCommandImpl extends ReadCommandImpl {
-    
+    private final Logger logger = LoggerFactory.INSTANCE.getLogger(SPCommandImpl.class);
+
     public SPCommandImpl(String sqlString, MappingWrapper config, List params) {
         super(sqlString, config, null);
         Iterator i = params.iterator();
@@ -43,7 +45,7 @@
 			String typeName = p.getColumnType().substring(index + 1);
 
 			Type sdoType = TypeHelper.INSTANCE.getType(pkg, typeName);
-			
+
 
 			int direction = ParameterImpl.IN;
 			if ("OUT".equalsIgnoreCase(p.getDirection()))
@@ -51,8 +53,8 @@
 			else if ("INOUT".equalsIgnoreCase(p.getDirection()))
 				direction = ParameterImpl.IN_OUT;
 			parameters.findOrCreateParameterWithIndex(idx, direction, sdoType);
-		}    	
-        
+		}
+
     }
 
 	public DataObject executeQuery() {
@@ -61,10 +63,12 @@
 		try {
 			List results = statement.executeCall(parameters);
 			success = true;
-			
+
 			return buildGraph(results);
 		} catch (SQLException e) {
-			DebugUtil.debugln(getClass(), debug, e);
+            if(this.logger.isDebugEnabled())
+                this.logger.debug(e);
+
 			throw new RuntimeException(e);
 		} finally {
 			if (success)
@@ -73,7 +77,7 @@
 				statement.getConnection().errorCleanUp();
 		}
 	}
-	
+
 	public void execute() {
 
 		boolean success = false;

Modified: incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/Statement.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/Statement.java?view=diff&rev=443109&r1=443108&r2=443109
==============================================================================
--- incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/Statement.java
(original)
+++ incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/Statement.java
Wed Sep 13 13:21:31 2006
@@ -6,15 +6,15 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *   http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
- * under the License.    
+ * under the License.
  */
 package org.apache.tuscany.das.rdb.impl;
 
@@ -28,17 +28,17 @@
 import java.util.Iterator;
 import java.util.List;
 
-import org.apache.tuscany.das.rdb.util.DebugUtil;
+import org.apache.log4j.Logger;
+import org.apache.tuscany.das.rdb.util.LoggerFactory;
 
 // TODO - Can use some refactoring. Much code is duplicated in "execute" methods
 public class Statement {
+    private final Logger logger = LoggerFactory.INSTANCE.getLogger(Statement.class);
 
     protected final String queryString;
 
     protected ConnectionImpl jdbcConnection;
 
-    private static final boolean debug = false;
-
     private PreparedStatement preparedStatement;
 
     private boolean isPaging = false;
@@ -57,7 +57,7 @@
     }
 
     public List executeCall(Parameters parameters) throws SQLException {
-      
+
             CallableStatement cs = jdbcConnection.prepareCall(queryString);
 
             Iterator inParams = parameters.inParams().iterator();
@@ -70,7 +70,9 @@
             Iterator outParams = parameters.outParams().iterator();
             while (outParams.hasNext()) {
                 ParameterImpl param = (ParameterImpl) outParams.next();
-                DebugUtil.debugln(getClass(), debug, "Registering parameter " + param.getName());
+                if(this.logger.isDebugEnabled())
+                    this.logger.debug("Registering parameter " + param.getName());
+
                 cs.registerOutParameter(param.getIndex(), SDODataTypeHelper.sqlTypeFor(param.getType()));
             }
 
@@ -83,14 +85,14 @@
             while ( cs.getMoreResults(java.sql.Statement.KEEP_CURRENT_RESULT) ) {
             	results.add(cs.getResultSet());
             }
-            
+
             Iterator i = parameters.outParams().iterator();
             while (i.hasNext()) {
                 ParameterImpl param = (ParameterImpl) i.next();
                 param.setValue(cs.getObject(param.getIndex()));
             }
 
-            return results;       
+            return results;
 
     }
 
@@ -111,7 +113,10 @@
             ParameterImpl param = (ParameterImpl) outParams.next();
 //            if (param.getIndex() == 0)
 //                param.setIndex(queryString.getParameterIndex(param.getName()));
-            DebugUtil.debugln(getClass(), debug, "Registering parameter " + param.getName());
+
+            if(this.logger.isDebugEnabled())
+                this.logger.debug("Registering parameter " + param.getName());
+
             cs.registerOutParameter(param.getIndex(), SDODataTypeHelper.sqlTypeFor(param.getType()));
         }
 
@@ -130,14 +135,18 @@
      * has been specified and try setObject otherwise.
      */
     public int executeUpdate(Parameters parameters) throws SQLException {
-        DebugUtil.debugln(getClass(), debug, "Executing statement " + queryString);
+        if(this.logger.isDebugEnabled())
+            this.logger.debug("Executing statement " + queryString);
+
         PreparedStatement ps = getPreparedStatement();
         Iterator i = parameters.inParams().iterator();
         while (i.hasNext()) {
             ParameterImpl param = (ParameterImpl) i.next();
 
             Object value = param.getValue();
-            DebugUtil.debugln(getClass(), debug, "Setting parameter " + param.getIndex()
+ " to " + value);
+            if(this.logger.isDebugEnabled())
+                this.logger.debug("Setting parameter " + param.getIndex() + " to " + value);
+
             if (value == null) {
                 if (param.getType() == null) {
                 	try {
@@ -173,7 +182,9 @@
     }
 
     private PreparedStatement getPreparedStatement() throws SQLException {
-        DebugUtil.debugln(getClass(), debug, "Getting prepared statement");
+        if(this.logger.isDebugEnabled())
+            this.logger.debug("Getting prepared statement");
+
         if (preparedStatement == null)
             if (isPaging)
                 preparedStatement = jdbcConnection.preparePagedStatement(queryString);

Added: incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/util/LoggerFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/util/LoggerFactory.java?view=auto&rev=443109
==============================================================================
--- incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/util/LoggerFactory.java
(added)
+++ incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/util/LoggerFactory.java
Wed Sep 13 13:21:31 2006
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.das.rdb.util;
+
+/* Import necessary log4j API classes */
+import org.apache.log4j.*;
+
+/**
+ * Helper class for logging using external log utility : log4j
+ * This will use log4j and to configure it, please add/update log4j.properties
+ * 
+ * @author lresende
+ */
+
+public class LoggerFactory {
+    public final static LoggerFactory INSTANCE = new LoggerFactory();
+    
+    private static Layout _defaultLayout = null;
+    private static Appender _defaultAppender = null;
+
+    static{
+        synchronized (LoggerFactory.class) {
+            _defaultLayout = new PatternLayout(LoggerLayout.Layout());
+            _defaultAppender = new ConsoleAppender(_defaultLayout);
+        }
+    }
+
+    private LoggerFactory() {
+
+    }
+
+    public Logger getLogger(Class loggingClass){
+         Logger logger = Logger.getLogger(loggingClass);
+         logger.setLevel(Level.OFF);
+         logger.addAppender(_defaultAppender);
+         
+         return logger;
+     }
+
+
+    public Logger getLogger(Class loggingClass, Level logLevel){
+        Logger logger = Logger.getLogger(loggingClass);
+        logger.setLevel(logLevel);
+        logger.addAppender(_defaultAppender);
+        
+        return logger;
+    }
+
+    public static void main(String[] args) {
+        
+        Logger log = LoggerFactory.INSTANCE.getLogger(LoggerFactory.class);
+        if(log.isDebugEnabled()){
+            log.debug("something");
+        }
+
+    }
+}

Added: incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/util/LoggerLayout.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/util/LoggerLayout.java?view=auto&rev=443109
==============================================================================
--- incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/util/LoggerLayout.java
(added)
+++ incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/util/LoggerLayout.java
Wed Sep 13 13:21:31 2006
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.tuscany.das.rdb.util;
+
+/**
+ * Log4J layout helper for Tuscany DAS
+ * @author lresende
+ */
+public class LoggerLayout {
+    
+    public static String Layout(){
+        
+        /*
+         *  Substitute symbols
+         *  %c Logger, %c{2 } last 2 partial names
+         *  %C Class name (full agony), %C{2 } last 2 partial names
+         *  %d{dd MMM yyyy HH:MM:ss } Date, format see java.text.SimpleDateFormat
+         *  %F File name
+         *  %l Location (caution: compiler-option-dependently)
+         *  %L Line number
+         *  %m user-defined message
+         *  %M Method name
+         *  %p Level
+         *  %r Milliseconds since program start
+         *  %t Threadname
+         *  %x, %X see Doku
+         *  %% individual percentage sign
+         *  
+         *  Caution: %C, %F, %l, %L, %M slow down program run!
+         *  Note, %n is newline
+         */
+        
+        return "[DAS RDB] - %c{1}.%M (%L) : %m %n";
+    }
+
+}

Modified: incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/TestDataWithExplicitColumns.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/TestDataWithExplicitColumns.java?view=diff&rev=443109&r1=443108&r2=443109
==============================================================================
--- incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/TestDataWithExplicitColumns.java
(original)
+++ incubator/tuscany/java/das/rdb/src/test/java/org/apache/tuscany/das/rdb/test/framework/TestDataWithExplicitColumns.java
Wed Sep 13 13:21:31 2006
@@ -6,15 +6,15 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *   http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
- * under the License.    
+ * under the License.
  */
 package org.apache.tuscany.das.rdb.test.framework;
 
@@ -22,18 +22,19 @@
 import java.sql.PreparedStatement;
 import java.sql.SQLException;
 
-import org.apache.tuscany.das.rdb.util.DebugUtil;
+import org.apache.log4j.Logger;
+import org.apache.tuscany.das.rdb.util.LoggerFactory;
 
 
 public abstract class TestDataWithExplicitColumns extends TestData {
 
+    private final Logger logger = LoggerFactory.INSTANCE.getLogger(TestDataWithExplicitColumns.class);
+
 	protected String[] columns;
-	protected int[] sqlTypes;
-	
-	private static boolean debug = false;
 
-	public TestDataWithExplicitColumns(Connection c, Object[][] data,
-			String[] columns, int[] sqlTypes) {
+    protected int[] sqlTypes;
+
+	public TestDataWithExplicitColumns(Connection c, Object[][] data, String[] columns, int[]
sqlTypes) {
 		super(c, data);
 		this.columns = columns;
 		this.sqlTypes = sqlTypes;
@@ -42,7 +43,7 @@
 	private String getColumn(int i) {
 		return columns[i - 1];
 	}
-	
+
 	private int getSqlType(int i) {
 		return (sqlTypes[i - 1]);
 	}
@@ -58,7 +59,7 @@
 		sql.append(" (");
 		for (int i = 1; i <= size(); i++) {
 			sql.append(getColumn(i));
-			if ( i < size() ) 
+			if ( i < size() )
 				sql.append(',');
 		}
 		sql.append(" )");
@@ -68,8 +69,10 @@
 			sql.append("?,");
 		}
 		sql.append("?)");
-		
-		DebugUtil.debugln(getClass(), debug, sql.toString());
+
+        if(this.logger.isDebugEnabled())
+            this.logger.debug(sql.toString());
+
 		PreparedStatement ps = connection.prepareStatement(sql.toString());
 
 		while (next()) {



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org


Mime
View raw message