aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJames Moger <james.moger@gmail.com>2011-08-17 13:30:40 -0400
committerJames Moger <james.moger@gmail.com>2011-08-17 13:30:40 -0400
commit05429c2cdf393730f17fb8fa51ee4b9e58e0a88f (patch)
tree1c6e98a2913b4f0912318e49f72f930b985eb345 /src
parent1734dc44d70391aeef26cacdf4d9f07c289e476e (diff)
downloadiciql-05429c2cdf393730f17fb8fa51ee4b9e58e0a88f.tar.gz
iciql-05429c2cdf393730f17fb8fa51ee4b9e58e0a88f.zip
Renamed logger. Improved test suite. Added Apache Commons and DBCP.v0.7.0
Diffstat (limited to 'src')
-rw-r--r--src/com/iciql/Constants.java6
-rw-r--r--src/com/iciql/Db.java4
-rw-r--r--src/com/iciql/IciqlException.java3
-rw-r--r--src/com/iciql/Query.java8
-rw-r--r--src/com/iciql/SQLDialectDefault.java3
-rw-r--r--src/com/iciql/TableDefinition.java14
-rw-r--r--src/com/iciql/build/Build.java18
-rw-r--r--src/com/iciql/util/IciqlLogger.java (renamed from src/com/iciql/util/StatementLogger.java)41
-rw-r--r--src/com/iciql/util/Slf4jIciqlListener.java (renamed from src/com/iciql/util/Slf4jStatementListener.java)16
9 files changed, 71 insertions, 42 deletions
diff --git a/src/com/iciql/Constants.java b/src/com/iciql/Constants.java
index bf6a5d0..b8d38dd 100644
--- a/src/com/iciql/Constants.java
+++ b/src/com/iciql/Constants.java
@@ -25,14 +25,14 @@ public class Constants {
// The build script extracts this exact line so be careful editing it
// and only use A-Z a-z 0-9 .-_ in the string.
- public static final String VERSION = "0.6.6";
+ public static final String VERSION = "0.7.0";
// The build script extracts this exact line so be careful editing it
// and only use A-Z a-z 0-9 .-_ in the string.
- public static final String VERSION_DATE = "2011-08-15";
+ public static final String VERSION_DATE = "2011-08-17";
// The build script extracts this exact line so be careful editing it
// and only use A-Z a-z 0-9 .-_ in the string.
- public static final String API_CURRENT = "5";
+ public static final String API_CURRENT = "6";
}
diff --git a/src/com/iciql/Db.java b/src/com/iciql/Db.java
index da0a7ac..af3c139 100644
--- a/src/com/iciql/Db.java
+++ b/src/com/iciql/Db.java
@@ -38,7 +38,7 @@ import com.iciql.DbUpgrader.DefaultDbUpgrader;
import com.iciql.Iciql.IQTable;
import com.iciql.Iciql.IQVersion;
import com.iciql.util.JdbcUtils;
-import com.iciql.util.StatementLogger;
+import com.iciql.util.IciqlLogger;
import com.iciql.util.StringUtils;
import com.iciql.util.Utils;
import com.iciql.util.WeakIdentityHashMap;
@@ -245,7 +245,7 @@ public class Db {
TableDefinition<T> def = (TableDefinition<T>) define(modelClass);
SQLStatement stat = new SQLStatement(this);
getDialect().prepareDropTable(stat, def);
- StatementLogger.drop(stat.getSQL());
+ IciqlLogger.drop(stat.getSQL());
int rc = 0;
try {
rc = stat.executeUpdate();
diff --git a/src/com/iciql/IciqlException.java b/src/com/iciql/IciqlException.java
index 4670418..7e7021e 100644
--- a/src/com/iciql/IciqlException.java
+++ b/src/com/iciql/IciqlException.java
@@ -109,6 +109,9 @@ public class IciqlException extends RuntimeException {
} else if ("42X05".equals(state)) {
// Derby table not found
iciqlCode = CODE_OBJECT_NOT_FOUND;
+ } else if ("42Y55".equals(state)) {
+ // Derby table not found
+ iciqlCode = CODE_OBJECT_NOT_FOUND;
} else if ("42S02".equals(state)) {
// H2 table not found
iciqlCode = CODE_OBJECT_NOT_FOUND;
diff --git a/src/com/iciql/Query.java b/src/com/iciql/Query.java
index 8f34761..b2d397a 100644
--- a/src/com/iciql/Query.java
+++ b/src/com/iciql/Query.java
@@ -31,7 +31,7 @@ import java.util.List;
import com.iciql.Iciql.EnumType;
import com.iciql.bytecode.ClassReader;
import com.iciql.util.JdbcUtils;
-import com.iciql.util.StatementLogger;
+import com.iciql.util.IciqlLogger;
import com.iciql.util.Utils;
/**
@@ -141,7 +141,7 @@ public class Query<T> {
stat.appendSQL("DELETE FROM ");
from.appendSQL(stat);
appendWhere(stat);
- StatementLogger.delete(stat.getSQL());
+ IciqlLogger.delete(stat.getSQL());
return stat.executeUpdate();
}
@@ -239,7 +239,7 @@ public class Query<T> {
declaration.appendSQL(stat);
}
appendWhere(stat);
- StatementLogger.update(stat.getSQL());
+ IciqlLogger.update(stat.getSQL());
return stat.executeUpdate();
}
@@ -713,7 +713,7 @@ public class Query<T> {
}
}
db.getDialect().appendLimitOffset(stat, limit, offset);
- StatementLogger.select(stat.getSQL());
+ IciqlLogger.select(stat.getSQL());
}
/**
diff --git a/src/com/iciql/SQLDialectDefault.java b/src/com/iciql/SQLDialectDefault.java
index 7ef507a..4814fdd 100644
--- a/src/com/iciql/SQLDialectDefault.java
+++ b/src/com/iciql/SQLDialectDefault.java
@@ -23,6 +23,7 @@ import java.text.MessageFormat;
import com.iciql.TableDefinition.FieldDefinition;
import com.iciql.TableDefinition.IndexDefinition;
+import com.iciql.util.IciqlLogger;
import com.iciql.util.StatementBuilder;
import com.iciql.util.StringUtils;
@@ -217,6 +218,8 @@ public class SQLDialectDefault implements SQLDialect {
case UNIQUE_HASH:
buff.append("UNIQUE ");
break;
+ default:
+ IciqlLogger.warn("{0} does not support hash indexes", getClass().getSimpleName());
}
buff.append("INDEX ");
buff.append(index.indexName);
diff --git a/src/com/iciql/TableDefinition.java b/src/com/iciql/TableDefinition.java
index 6f201ad..9b3666c 100644
--- a/src/com/iciql/TableDefinition.java
+++ b/src/com/iciql/TableDefinition.java
@@ -38,7 +38,7 @@ import com.iciql.Iciql.IQTable;
import com.iciql.Iciql.IQVersion;
import com.iciql.Iciql.IndexType;
import com.iciql.util.StatementBuilder;
-import com.iciql.util.StatementLogger;
+import com.iciql.util.IciqlLogger;
import com.iciql.util.StringUtils;
import com.iciql.util.Utils;
@@ -431,7 +431,7 @@ public class TableDefinition<T> {
}
buff.append(')');
stat.setSQL(buff.toString());
- StatementLogger.insert(stat.getSQL());
+ IciqlLogger.insert(stat.getSQL());
if (returnKey) {
return stat.executeInsert();
}
@@ -461,7 +461,7 @@ public class TableDefinition<T> {
}
SQLStatement stat = new SQLStatement(db);
db.getDialect().prepareMerge(stat, schemaName, tableName, this, obj);
- StatementLogger.merge(stat.getSQL());
+ IciqlLogger.merge(stat.getSQL());
return stat.executeUpdate();
}
@@ -503,7 +503,7 @@ public class TableDefinition<T> {
}
stat.setSQL(buff.toString());
query.appendWhere(stat);
- StatementLogger.update(stat.getSQL());
+ IciqlLogger.update(stat.getSQL());
return stat.executeUpdate();
}
@@ -535,7 +535,7 @@ public class TableDefinition<T> {
}
stat.setSQL(buff.toString());
query.appendWhere(stat);
- StatementLogger.delete(stat.getSQL());
+ IciqlLogger.delete(stat.getSQL());
return stat.executeUpdate();
}
@@ -548,7 +548,7 @@ public class TableDefinition<T> {
}
SQLStatement stat = new SQLStatement(db);
db.getDialect().prepareCreateTable(stat, this);
- StatementLogger.create(stat.getSQL());
+ IciqlLogger.create(stat.getSQL());
try {
stat.executeUpdate();
} catch (IciqlException e) {
@@ -561,7 +561,7 @@ public class TableDefinition<T> {
for (IndexDefinition index : indexes) {
stat = new SQLStatement(db);
db.getDialect().prepareCreateIndex(stat, schemaName, tableName, index);
- StatementLogger.create(stat.getSQL());
+ IciqlLogger.create(stat.getSQL());
try {
stat.executeUpdate();
} catch (IciqlException e) {
diff --git a/src/com/iciql/build/Build.java b/src/com/iciql/build/Build.java
index 75f6483..e8b9385 100644
--- a/src/com/iciql/build/Build.java
+++ b/src/com/iciql/build/Build.java
@@ -69,6 +69,10 @@ public class Build {
downloadFromApache(MavenObject.DOCLAVA, BuildType.COMPILETIME);
downloadFromApache(MavenObject.SLF4JAPI, BuildType.RUNTIME);
downloadFromApache(MavenObject.SLF4JAPI, BuildType.COMPILETIME);
+ downloadFromApache(MavenObject.COMMONSPOOL, BuildType.RUNTIME);
+ downloadFromApache(MavenObject.COMMONSPOOL, BuildType.COMPILETIME);
+ downloadFromApache(MavenObject.COMMONSDBCP, BuildType.RUNTIME);
+ downloadFromApache(MavenObject.COMMONSDBCP, BuildType.COMPILETIME);
// needed for site publishing
downloadFromApache(MavenObject.COMMONSNET, BuildType.RUNTIME);
@@ -172,9 +176,9 @@ public class Build {
"219a3540f3b27d7cc3b1d91d6ea046cd8723290e", "0bb50eec177acf0e94d58e0cf07262fe5164331d",
"c7adc475ca40c288c93054e0f4fe58f3a98c0cb5");
- public static final MavenObject H2 = new MavenObject("com/h2database", "h2", "1.3.158",
- "4bac13427caeb32ef6e93b70101e61f370c7b5e2", "6bb165156a0831879fa7797df6e18bdcd4421f2d",
- "446d3f58c44992534cb54f67134532d95961904a");
+ public static final MavenObject H2 = new MavenObject("com/h2database", "h2", "1.3.159",
+ "dd89f939661eb5593909584e1c243db0c25de130", "4d953bf765e8a13c7e06ca51165438338966c698",
+ "4c79ed03f994820a1a873150c8a9f13c667784d3");
public static final MavenObject HSQLDB = new MavenObject("org/hsqldb", "hsqldb", "2.2.4",
"6a6e040b07f5ee409fc825f1c5e5b574b1fa1428", "", "");
@@ -206,6 +210,14 @@ public class Build {
"6f3b8a24bf970f17289b234284c94f43eb42f0e4", "46a386136c901748e6a3af67ebde6c22bc6b4524",
"e223571d77769cdafde59040da235842f3326453");
+ public static final MavenObject COMMONSPOOL = new MavenObject("commons-pool", "commons-pool", "1.5.6",
+ "16390e2d74df4ab08c06a85d42a74a951dc93ad7", "bbfb73ed3c341d9738c64da8157910b967f878d6",
+ "d72204023b30cd9fecb64829586472f3c6806005");
+
+ public static final MavenObject COMMONSDBCP = new MavenObject("commons-dbcp", "commons-dbcp", "1.4",
+ "30be73c965cc990b153a100aaaaafcf239f82d39", "9b076ff231434d5403be6599a1347019b12c0def",
+ "098bf7c8d5b026f6e3969259a36e813ac37432b3");
+
public final String group;
public final String artifact;
public final String version;
diff --git a/src/com/iciql/util/StatementLogger.java b/src/com/iciql/util/IciqlLogger.java
index b11a5f9..d8005bb 100644
--- a/src/com/iciql/util/StatementLogger.java
+++ b/src/com/iciql/util/IciqlLogger.java
@@ -17,6 +17,7 @@
package com.iciql.util;
import java.text.DecimalFormat;
+import java.text.MessageFormat;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -25,34 +26,34 @@ import java.util.concurrent.atomic.AtomicLong;
import com.iciql.IciqlException;
/**
- * Utility class to optionally log generated statements to StatementListeners.<br>
+ * Utility class to optionally log generated statements to IciqlListeners.<br>
* Statement logging is disabled by default.
* <p>
* This class also tracks the counts for generated statements by major type.
*
*/
-public class StatementLogger {
+public class IciqlLogger {
/**
* Enumeration of the different statement types that are logged.
*/
public enum StatementType {
- STAT, TOTAL, CREATE, INSERT, UPDATE, MERGE, DELETE, SELECT, DROP;
+ STAT, TOTAL, CREATE, INSERT, UPDATE, MERGE, DELETE, SELECT, DROP, WARN;
}
/**
- * Interface that defines a statement listener.
+ * Interface that defines an iciql listener.
*/
- public interface StatementListener {
- void logStatement(StatementType type, String statement);
+ public interface IciqlListener {
+ void logIciql(StatementType type, String statement);
}
private static final ExecutorService EXEC = Executors.newSingleThreadExecutor();
- private static final Set<StatementListener> LISTENERS = Utils.newHashSet();
- private static final StatementListener CONSOLE = new StatementListener() {
+ private static final Set<IciqlListener> LISTENERS = Utils.newHashSet();
+ private static final IciqlListener CONSOLE = new IciqlListener() {
@Override
- public void logStatement(StatementType type, String message) {
+ public void logIciql(StatementType type, String message) {
System.out.println(message);
}
};
@@ -64,6 +65,7 @@ public class StatementLogger {
private static final AtomicLong MERGE_COUNT = new AtomicLong();
private static final AtomicLong DELETE_COUNT = new AtomicLong();
private static final AtomicLong DROP_COUNT = new AtomicLong();
+ private static final AtomicLong WARN_COUNT = new AtomicLong();
/**
* Activates the Console Logger.
@@ -84,7 +86,7 @@ public class StatementLogger {
*
* @param listener
*/
- public static void registerListener(StatementListener listener) {
+ public static void registerListener(IciqlListener listener) {
LISTENERS.add(listener);
}
@@ -93,9 +95,9 @@ public class StatementLogger {
*
* @param listener
*/
- public static void unregisterListener(StatementListener listener) {
+ public static void unregisterListener(IciqlListener listener) {
if (!LISTENERS.remove(listener)) {
- throw new IciqlException("Failed to remove statement listener {0}", listener);
+ throw new IciqlException("Failed to remove iciql listener {0}", listener);
}
}
@@ -134,11 +136,16 @@ public class StatementLogger {
logStatement(StatementType.DROP, statement);
}
+ public static void warn(String message, Object... args) {
+ WARN_COUNT.incrementAndGet();
+ logStatement(StatementType.WARN, args.length > 0 ? MessageFormat.format(message, args) : message);
+ }
+
private static void logStatement(final StatementType type, final String statement) {
- for (final StatementListener listener : LISTENERS) {
+ for (final IciqlListener listener : LISTENERS) {
EXEC.execute(new Runnable() {
public void run() {
- listener.logStatement(type, statement);
+ listener.logIciql(type, statement);
}
});
}
@@ -172,6 +179,10 @@ public class StatementLogger {
return DROP_COUNT.longValue();
}
+ public static long getWarnCount() {
+ return WARN_COUNT.longValue();
+ }
+
public static long getTotalCount() {
return getCreateCount() + getInsertCount() + getUpdateCount() + getDeleteCount() + getMergeCount()
+ getSelectCount() + getDropCount();
@@ -180,6 +191,8 @@ public class StatementLogger {
public static void logStats() {
logStatement(StatementType.STAT, "iciql Runtime Statistics");
logStatement(StatementType.STAT, "========================");
+ logStat(StatementType.WARN, getWarnCount());
+ logStatement(StatementType.STAT, "========================");
logStat(StatementType.CREATE, getCreateCount());
logStat(StatementType.INSERT, getInsertCount());
logStat(StatementType.UPDATE, getUpdateCount());
diff --git a/src/com/iciql/util/Slf4jStatementListener.java b/src/com/iciql/util/Slf4jIciqlListener.java
index f46099c..ded393f 100644
--- a/src/com/iciql/util/Slf4jStatementListener.java
+++ b/src/com/iciql/util/Slf4jIciqlListener.java
@@ -23,15 +23,13 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.iciql.Iciql;
-import com.iciql.util.StatementLogger.StatementListener;
-import com.iciql.util.StatementLogger.StatementType;
+import com.iciql.util.IciqlLogger.IciqlListener;
+import com.iciql.util.IciqlLogger.StatementType;
/**
- * Slf4jStatementListener interfaces the iciql statement logger to the SLF4J
- * logging architecture.
- *
+ * Slf4jIciqlListener interfaces the IciqlLogger to the SLF4J logging framework.
*/
-public class Slf4jStatementListener implements StatementListener {
+public class Slf4jIciqlListener implements IciqlListener {
private Logger logger = LoggerFactory.getLogger(Iciql.class);
@@ -46,11 +44,11 @@ public class Slf4jStatementListener implements StatementListener {
private final Map<StatementType, Level> levels;
- public Slf4jStatementListener() {
+ public Slf4jIciqlListener() {
this(Level.TRACE);
}
- public Slf4jStatementListener(Level defaultLevel) {
+ public Slf4jIciqlListener(Level defaultLevel) {
this.defaultLevel = defaultLevel;
levels = new HashMap<StatementType, Level>();
for (StatementType type : StatementType.values()) {
@@ -69,7 +67,7 @@ public class Slf4jStatementListener implements StatementListener {
}
@Override
- public void logStatement(StatementType type, String statement) {
+ public void logIciql(StatementType type, String statement) {
Level level = levels.get(type);
switch (level) {
case ERROR: