cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject [05/30] cayenne git commit: CAY-2377. Changes in JDBCEventLogger and impl
Date Thu, 07 Dec 2017 10:09:34 GMT
CAY-2377. Changes in JDBCEventLogger and impl


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/cb1ed5d6
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/cb1ed5d6
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/cb1ed5d6

Branch: refs/heads/master
Commit: cb1ed5d65de53f4b311d8786b9ad9ee06a37b97a
Parents: 13056c1
Author: Arseni Bulatski <ancarseni@gmail.com>
Authored: Wed Oct 25 11:18:06 2017 +0300
Committer: Arseni Bulatski <ancarseni@gmail.com>
Committed: Wed Nov 15 10:27:46 2017 +0300

----------------------------------------------------------------------
 .../log/FormattedSlf4jJdbcEventLogger.java      |  12 --
 .../org/apache/cayenne/log/JdbcEventLogger.java |  18 --
 .../apache/cayenne/log/NoopJdbcEventLogger.java |  15 --
 .../cayenne/log/Slf4jJdbcEventLogger.java       | 177 -------------------
 .../cayenne/log/Slf4jJdbcEventLoggerTest.java   |  10 --
 docs/doc/src/main/resources/UPGRADE.txt         |  18 +-
 6 files changed, 17 insertions(+), 233 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/cb1ed5d6/cayenne-server/src/main/java/org/apache/cayenne/log/FormattedSlf4jJdbcEventLogger.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/log/FormattedSlf4jJdbcEventLogger.java
b/cayenne-server/src/main/java/org/apache/cayenne/log/FormattedSlf4jJdbcEventLogger.java
index 7994f58..b38c90e 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/log/FormattedSlf4jJdbcEventLogger.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/log/FormattedSlf4jJdbcEventLogger.java
@@ -120,16 +120,4 @@ public class FormattedSlf4jJdbcEventLogger extends Slf4jJdbcEventLogger
{
         return result;
     }
 
-    @Override
-    @Deprecated
-    public void logQuery(
-            String queryStr,
-            List<DbAttribute> attrs,
-            List<?> params,
-            long time) {
-        if (isLoggable()) {
-            super.logQuery(formatQuery(queryStr), attrs, params, time);
-        }
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/cb1ed5d6/cayenne-server/src/main/java/org/apache/cayenne/log/JdbcEventLogger.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/log/JdbcEventLogger.java b/cayenne-server/src/main/java/org/apache/cayenne/log/JdbcEventLogger.java
index 124e6ba..28fd49e 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/log/JdbcEventLogger.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/log/JdbcEventLogger.java
@@ -39,18 +39,6 @@ public interface JdbcEventLogger {
 	void logGeneratedKey(DbAttribute attribute, Object value);
 
 	/**
-	 * @deprecated since 4.0 use {@link #logQuery(String, ParameterBinding[])}.
-	 */
-	@Deprecated
-	void logQuery(String sql, List<?> params);
-
-	/**
-	 * @deprecated since 4.0 use {@link #logQuery(String, ParameterBinding[])}.
-	 */
-	@Deprecated
-	void logQuery(String sql, List<DbAttribute> attrs, List<?> params, long time);
-
-	/**
 	 * @since 4.0
 	 */
 	void logQuery(String sql, ParameterBinding[] bindings);
@@ -60,12 +48,6 @@ public interface JdbcEventLogger {
 	 */
 	void logQueryParameters(String label, ParameterBinding[] bindings);
 
-	/**
-	 * @deprecated since 4.0 use {@link #logQueryParameters(String, ParameterBinding[])}
-	 */
-	@Deprecated
-	void logQueryParameters(String label, List<DbAttribute> attrs, List<Object>
parameters, boolean isInserting);
-
 	void logSelectCount(int count, long time);
 
 	/**

http://git-wip-us.apache.org/repos/asf/cayenne/blob/cb1ed5d6/cayenne-server/src/main/java/org/apache/cayenne/log/NoopJdbcEventLogger.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/log/NoopJdbcEventLogger.java
b/cayenne-server/src/main/java/org/apache/cayenne/log/NoopJdbcEventLogger.java
index 75f6f58..abe6adf 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/log/NoopJdbcEventLogger.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/log/NoopJdbcEventLogger.java
@@ -46,27 +46,12 @@ public class NoopJdbcEventLogger implements JdbcEventLogger {
 	@Override
 	public void logGeneratedKey(DbAttribute attribute, Object value) {
 	}
-
-	@Deprecated
-	@Override
-	public void logQuery(String sql, List<?> params) {
-	}
-
-	@Deprecated
-	@Override
-	public void logQuery(String sql, List<DbAttribute> attrs, List<?> params, long
time) {
-	}
 	
 	@Override
 	public void logQuery(String sql, ParameterBinding[] bindings) {
 	}
 
 	@Override
-	@Deprecated
-	public void logQueryParameters(String label, List<DbAttribute> attrs, List<Object>
parameters, boolean isInserting) {
-	}
-
-	@Override
 	public void logQueryParameters(String label, ParameterBinding[] bindings) {
 	}
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/cb1ed5d6/cayenne-server/src/main/java/org/apache/cayenne/log/Slf4jJdbcEventLogger.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/log/Slf4jJdbcEventLogger.java
b/cayenne-server/src/main/java/org/apache/cayenne/log/Slf4jJdbcEventLogger.java
index a18e5e1..d29b585 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/log/Slf4jJdbcEventLogger.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/log/Slf4jJdbcEventLogger.java
@@ -59,96 +59,6 @@ public class Slf4jJdbcEventLogger implements JdbcEventLogger {
 				Constants.QUERY_EXECUTION_TIME_LOGGING_THRESHOLD_PROPERTY, 0);
 	}
 
-	// this should go away once we can remove 4.0 deprecated API. The actual logic for printing
a value is now
-    // spread around the ExtendedTypes
-	@Deprecated
-	void sqlLiteralForObject(StringBuilder buffer, Object object) {
-		if (object == null) {
-			buffer.append("NULL");
-		} else if (object instanceof String) {
-			buffer.append('\'');
-			// lets escape quotes
-			String literal = (String) object;
-			if (literal.length() > TRIM_VALUES_THRESHOLD) {
-				literal = literal.substring(0, TRIM_VALUES_THRESHOLD) + "...";
-			}
-
-			int curPos = 0;
-			int endPos = 0;
-
-			while ((endPos = literal.indexOf('\'', curPos)) >= 0) {
-				buffer.append(literal.substring(curPos, endPos + 1)).append('\'');
-				curPos = endPos + 1;
-			}
-
-			if (curPos < literal.length())
-				buffer.append(literal.substring(curPos));
-
-			buffer.append('\'');
-		}
-		// handle byte pretty formatting
-		else if (object instanceof Byte) {
-			IDUtil.appendFormattedByte(buffer, (Byte) object);
-		} else if (object instanceof Number) {
-			// process numeric value (do something smart in the future)
-			buffer.append(object);
-		} else if (object instanceof java.sql.Date) {
-			buffer.append('\'').append(object).append('\'');
-		} else if (object instanceof java.sql.Time) {
-			buffer.append('\'').append(object).append('\'');
-		} else if (object instanceof java.util.Date) {
-			long time = ((java.util.Date) object).getTime();
-			buffer.append('\'').append(new java.sql.Timestamp(time)).append('\'');
-		} else if (object instanceof java.util.Calendar) {
-			long time = ((java.util.Calendar) object).getTimeInMillis();
-			buffer.append(object.getClass().getName()).append('(').append(new java.sql.Timestamp(time)).append(')');
-		} else if (object instanceof Character) {
-			buffer.append(((Character) object).charValue());
-		} else if (object instanceof Boolean) {
-			buffer.append('\'').append(object).append('\'');
-		} else if (object instanceof Enum<?>) {
-			// buffer.append(object.getClass().getName()).append(".");
-			buffer.append(((Enum<?>) object).name()).append("=");
-			if (object instanceof ExtendedEnumeration) {
-				Object value = ((ExtendedEnumeration) object).getDatabaseValue();
-				if (value instanceof String)
-					buffer.append("'");
-				buffer.append(value);
-				if (value instanceof String)
-					buffer.append("'");
-			} else {
-				buffer.append(((Enum<?>) object).ordinal());
-				// FIXME -- this isn't quite right
-			}
-		} else if (object instanceof ParameterBinding) {
-			sqlLiteralForObject(buffer, ((ParameterBinding) object).getValue());
-		} else if (object.getClass().isArray()) {
-			buffer.append("< ");
-
-			int len = Array.getLength(object);
-			boolean trimming = false;
-			if (len > TRIM_VALUES_THRESHOLD) {
-				len = TRIM_VALUES_THRESHOLD;
-				trimming = true;
-			}
-
-			for (int i = 0; i < len; i++) {
-				if (i > 0) {
-					buffer.append(",");
-				}
-				sqlLiteralForObject(buffer, Array.get(object, i));
-			}
-
-			if (trimming) {
-				buffer.append("...");
-			}
-
-			buffer.append('>');
-		} else {
-			buffer.append(object.getClass().getName()).append("@").append(System.identityHashCode(object));
-		}
-	}
-
 	@Override
 	public void log(String message) {
 		if (message != null) {
@@ -164,63 +74,6 @@ public class Slf4jJdbcEventLogger implements JdbcEventLogger {
 		}
 	}
 
-	/**
-	 * @deprecated since 4.0 use
-	 *             {@link #logQuery(String, ParameterBinding[], long)}.
-	 */
-	@Deprecated
-	@Override
-	public void logQuery(String queryStr, List<?> params) {
-		logQuery(queryStr, null, params, -1);
-	}
-
-	/**
-	 * @deprecated since 4.0 uses old style of parameter logging.
-	 */
-	@Deprecated
-	private void buildLog(StringBuilder buffer, String prefix, String postfix, List<DbAttribute>
attributes,
-			List<?> parameters, boolean isInserting) {
-		if (parameters != null && parameters.size() > 0) {
-			Iterator<DbAttribute> attributeIterator = null;
-			int position = 0;
-
-			if (attributes != null)
-				attributeIterator = attributes.iterator();
-
-			for (Object parameter : parameters) {
-				// If at the beginning, output the prefix, otherwise a
-				// separator.
-				if (position++ == 0)
-					buffer.append(prefix);
-				else
-					buffer.append(", ");
-
-				// Find the next attribute and SKIP generated attributes. Only
-				// skip when logging inserts, though. Should show previously
-				// generated keys on DELETE, UPDATE, or SELECT.
-				DbAttribute attribute = null;
-				while (attributeIterator != null && attributeIterator.hasNext()) {
-					attribute = attributeIterator.next();
-
-					if (!isInserting || !attribute.isGenerated())
-						break;
-				}
-
-				buffer.append(position);
-
-				if (attribute != null) {
-					buffer.append("->");
-					buffer.append(attribute.getName());
-				}
-
-				buffer.append(":");
-				sqlLiteralForObject(buffer, parameter);
-			}
-
-			buffer.append(postfix);
-		}
-	}
-
 	private boolean isInserting(String query) {
 		if (query == null || query.length() == 0)
 			return false;
@@ -243,36 +96,6 @@ public class Slf4jJdbcEventLogger implements JdbcEventLogger {
 		}
 	}
 
-	@Deprecated
-	@Override
-	public void logQuery(String queryStr, List<DbAttribute> attrs, List<?> params,
long time) {
-		if (isLoggable()) {
-			StringBuilder buffer = new StringBuilder(queryStr);
-			buildLog(buffer, " [bind: ", "]", attrs, params, isInserting(queryStr));
-
-			// log preparation time only if it is something significant
-			if (time > 5) {
-				buffer.append(" - prepared in ").append(time).append(" ms.");
-			}
-
-			logger.info(buffer.toString());
-		}
-	}
-
-	/**
-	 * @deprecated since 4.0
-	 */
-	@Deprecated
-	@Override
-	public void logQueryParameters(String label, List<DbAttribute> attrs, List<Object>
parameters, boolean isInserting) {
-		String prefix = "[" + label + ": ";
-		if (isLoggable() && parameters.size() > 0) {
-			StringBuilder buffer = new StringBuilder();
-			buildLog(buffer, prefix, "]", attrs, parameters, isInserting);
-			logger.info(buffer.toString());
-		}
-	}
-
 	@Override
 	public void logQueryParameters(String label, ParameterBinding[] bindings) {
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/cb1ed5d6/cayenne-server/src/test/java/org/apache/cayenne/log/Slf4jJdbcEventLoggerTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/log/Slf4jJdbcEventLoggerTest.java
b/cayenne-server/src/test/java/org/apache/cayenne/log/Slf4jJdbcEventLoggerTest.java
index 5074ee4..a41861c 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/log/Slf4jJdbcEventLoggerTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/log/Slf4jJdbcEventLoggerTest.java
@@ -30,16 +30,6 @@ import static org.junit.Assert.assertTrue;
 public class Slf4jJdbcEventLoggerTest {
 
     @Test
-    public void testSqlLiteralForObject() throws Exception {
-        StringBuilder buf = new StringBuilder();
-
-        // test unsupported type
-        new Slf4jJdbcEventLogger(new DefaultRuntimeProperties(Collections.<String, String>emptyMap()))
-                .sqlLiteralForObject(buf, new Object());
-        assertTrue(buf.length() > 0);
-    }
-
-    @Test
     public void testAppendFormattedByte() throws Exception {
         assertFormatting((byte) 0, "00");
         assertFormatting((byte) 1, "01");

http://git-wip-us.apache.org/repos/asf/cayenne/blob/cb1ed5d6/docs/doc/src/main/resources/UPGRADE.txt
----------------------------------------------------------------------
diff --git a/docs/doc/src/main/resources/UPGRADE.txt b/docs/doc/src/main/resources/UPGRADE.txt
index a5635bf..30de007 100644
--- a/docs/doc/src/main/resources/UPGRADE.txt
+++ b/docs/doc/src/main/resources/UPGRADE.txt
@@ -110,7 +110,23 @@ UPGRADING TO 4.1.M2
       - removed Property(final String name) {use factory method Property.create("propertyName",
PropertyType.class)} in org.apache.cayenne.exp.Property;
       - removed void testDeprecatedConstruct(); in org.apache.cayenne.exp.PropertyTest;
       - removed void testDeprecatedConstruct(); in org.apache.cayenne.query.ColumnSelectIT;
-
+      - removed void logQueryParameters(String label, List<DbAttribute> attrs, List<Object>
parameters, boolean isInserting); {since 4.0 use
+      logQueryParameters(String, ParameterBinding[])} in org.apache.cayenne.log.JdbcEventLogger;
+      - removed void logQueryParameters(String label, List<DbAttribute> attrs, List<Object>
parameters, boolean isInserting) in org.apache.cayenne.log.Slf4jJdbcEventLogger;
+      - removed void logQueryParameters(String label, List<DbAttribute> attrs, List<Object>
parameters, boolean isInserting) in org.apache.cayenne.log.NoopJdbcEventLogger;
+      - removed void logQuery(String sql, List<?> params); {since 4.0 use logQuery(String,
ParameterBinding[])} in org.apache.cayenne.log.JdbcEventLogger;
+      - removed void logQuery(String queryStr, List<?> params) in org.apache.cayenne.log.Slf4jJdbcEventLogger;
+      - removed void logQuery(String sql, List<?> params) in org.apache.cayenne.log.NoopJdbcEventLogger;
+      - removed void logQuery(String sql, List<DbAttribute> attrs, List<?> params,
long time); {since 4.0 use logQuery(String, ParameterBinding[])}
+      in org.apache.cayenne.log.JdbcEventLogger;
+      - removed void logQuery(String queryStr, List<DbAttribute> attrs, List<?>
params, long time); in org.apache.cayenne.log.Slf4jJdbcEventLogger;
+      - removed void logQuery(String sql, List<DbAttribute> attrs, List<?> params,
long time); in org.apache.cayenne.log.NoopJdbcEventLogger;
+      - removed void logQuery(String queryStr, List<DbAttribute> attrs, List<?>
params, long time) in org.apache.cayenne.log.FormattedSlf4jJdbcEventLogger;
+      - removed void buildLog(StringBuilder buffer, String prefix, String postfix, List<DbAttribute>
attributes, List<?> parameters, boolean isInserting);
+      {since 4.0 uses old style of parameter logging} in org.apache.cayenne.log.Slf4jJdbcEventLogger;
+      - removed void sqlLiteralForObject(StringBuilder buffer, Object object); {his should
go away once we can remove 4.0 deprecated API. The actual logic for printing a value is now
+      spread around the ExtendedTypes} in org.apache.cayenne.log.Slf4jJdbcEventLogger;
+      - removed test void testSqlLiteralForObject() in org.apache.cayenne.log;
 
 UPGRADING TO 4.1.M1
 


Mime
View raw message