Permalink
Browse files

Minor logging tweaks and tests of named queries

  • Loading branch information...
daitangio committed Jul 1, 2017
1 parent e497607 commit 356accd093b20b2fd6de233e1ae29c8d58f092ae
View
@@ -11,9 +11,8 @@ Improvements over original release (svn revision 72)
+ Added HSQL compile dependency because used for caches and testing.
+ TODO
Consider incorporating fixes from https://github.com/AugeoSoftware/VJDBC
Instructions
------------
@@ -60,3 +59,14 @@ aren't listed on the Sourceforge-Page but the payments definitively arrived.
It's really exciting to see that VJDBC is used in production environments but to get paid for
it makes me really proud.
TODO
---------------
+ Consider incorporating fixes from https://github.com/AugeoSoftware/VJDBC
+ Consider replacing
de.simplicit.vjdbc.server.concurrent
with the jdk concurrent package (probably more secure).
+ Code base is old but seems well written, even with a statistical log upone disconnect.
There was some minor bad code eclipse catches (null pointer access, but only few).
@@ -79,6 +79,7 @@ private CommandProcessor() {
private static void installShutdownHook() {
// Install the shutdown hook
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
getInstance().destroy();
}
@@ -181,8 +182,8 @@ public Object process(Long connuid, Long uid, Command cmd, CallingContext ctx) t
}else {
cmdLimited=cmdStr;
}
_logger.debug("[ "+connuid+", "+uid
+ " ] Processing" + cmdLimited);
_logger.debug("[ C:"+connuid+", UID:"+uid
+ " ] Processing:" + cmdLimited);
}
if(connuid != null) {
@@ -253,7 +254,7 @@ public Object process(Long connuid, Long uid, Command cmd, CallingContext ctx) t
@Override
public void run() {
try {
_logger.debug("Checking for orphaned connections ..."+_connectionEntries.keySet().size());
_logger.trace("Checking for orphaned connections ..."+_connectionEntries.keySet().size());
long millis = System.currentTimeMillis();
@@ -84,6 +84,7 @@ void close() {
}
}
@Override
public void closeAllRelatedJdbcObjects() throws SQLException {
Set<Long> keys = null;
synchronized(_jdbcObjects) {
@@ -122,6 +123,7 @@ public long getNumberOfProcessedCommands() {
return _numberOfProcessedCommands;
}
@Override
public Object getJDBCObject(Long key) {
JdbcObjectHolder jdbcObjectHolder = _jdbcObjects.get(key);
if(jdbcObjectHolder != null) {
@@ -131,11 +133,13 @@ public Object getJDBCObject(Long key) {
}
}
@Override
public void addJDBCObject(Long key, Object partner) {
int _jdbcInterfaceType = getJdbcInterfaceTypeFromObject(partner);
_jdbcObjects.put(key, new JdbcObjectHolder(partner, null, _jdbcInterfaceType));
}
@Override
public Object removeJDBCObject(Long key) {
JdbcObjectHolder jdbcObjectHolder = _jdbcObjects.remove(key);
if(jdbcObjectHolder != null) {
@@ -145,25 +149,31 @@ public Object removeJDBCObject(Long key) {
}
}
@Override
public int getCompressionMode() {
return _connectionConfiguration.getCompressionModeAsInt();
}
@Override
public long getCompressionThreshold() {
return _connectionConfiguration.getCompressionThreshold();
}
@Override
public int getRowPacketSize() {
return _connectionConfiguration.getRowPacketSize();
}
@Override
public String getCharset() {
return _connectionConfiguration.getCharset();
}
@Override
public String resolveOrCheckQuery(String sql) throws SQLException
{
if (sql.startsWith("$")) {
_logger.debug("Named Query requested:"+sql);
return getNamedQuery(sql.substring(1));
}
else {
@@ -305,6 +315,7 @@ public void traceConnectionStatistics() {
ArrayList entries = new ArrayList(_commandCountMap.entrySet());
Collections.sort(entries, new Comparator() {
@Override
public int compare(Object o1, Object o2) {
Map.Entry e1 = (Map.Entry) o1;
Map.Entry e2 = (Map.Entry) o2;
@@ -7,21 +7,24 @@
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import de.simplicit.vjdbc.serial.StreamSerializer;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import java.math.BigDecimal;
import java.sql.*;
import java.text.DateFormat;
import java.util.Arrays;
import java.util.Calendar;
public class SuperSimpleHSqlTest{
public class SuperSimpleHSqlTest extends TestSuite {
protected Logger logger=Logger.getLogger(getClass());
private static final int NUMBER_OF_ADDRESSES = 1234;
private static final int NUMBER_OF_ADDRESSES = 64;
protected DateFormat _dateTimeFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
@BeforeClass
@@ -45,14 +48,26 @@ public void tearDown() throws Exception {
connVJdbc.close();
}
@Test
public void test1_SimpleCreate() throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
logger.info("Connecting to test db....and creating some tables");
connVJdbc.setAutoCommit(false);
createTestData(connVJdbc);
connVJdbc.commit();
}
@Test
public void test2_ConfiguredStatement() throws SQLException {
Statement stmt1 = connVJdbc.createStatement();
// Also test prepared statement
stmt1.addBatch("$updateAllAddresses");
stmt1.executeBatch();
stmt1.close();
}

0 comments on commit 356accd

Please sign in to comment.