/*
 * $Log: JdbcQueryListener.java,v $
 * Revision 1.1  2008-02-28 16:22:45  europe\L190409
 * first version
 *
 */
package nl.nn.adapterframework.jdbc;

import org.apache.commons.lang.StringUtils;

import nl.nn.adapterframework.configuration.ConfigurationException;

/**

/**
 * Database Listener that operates on a table having at least a key and a status field.
 *
 * <p><b>Configuration:</b>
 * <table border="1">
 * <tr><th>attributes</th><th>description</th><th>default</th></tr>
 * <tr><td>classname</td><td>nl.nn.adapterframework.jdbc.JdbcQueryListener</td><td>&nbsp;</td></tr>
 * <tr><td>{@link #setName(String) name}</td>  <td>name of the listener</td><td>&nbsp;</td></tr>
 * <tr><td>{@link #setKeyField(String) keyField}</td>  <td>primary key field of the table, used to identify messages</td><td>&nbsp;</td></tr>
 * <tr><td>{@link #setMessageField(String) messageField}</td>  <td>(optional) field containing the message data</td><td><i>same as keyField</i></td></tr>

 * <tr><td>{@link #setSelectQuery(String) selectQuery}</td> <td>query that returns a row to be processed. Must contain a key field and optionally a message field</td><td>&nbsp;</td></tr>
 * <tr><td>{@link #setUpdateStatusToProcessedQuery(String) updateStatusToProcessedQuery}</td> <td>SQL Statement to the status of a row to 'processed'. Must contain one parameter, that is set to the value of the key</td><td>&nbsp;</td></tr>
 * <tr><td>{@link #setUpdateStatusToErrorQuery(String) updateStatusToErrorQuery}</td> <td>SQL Statement to the status of a row to 'error'. Must contain one parameter, that is set to the value of the key</td><td>same as <code>updateStatusToProcessedQuery</code></td></tr>

 * <tr><td>{@link #setDatasourceName(String) datasourceName}</td><td>can be configured from JmsRealm, too</td><td>&nbsp;</td></tr>
 * <tr><td>{@link #setUsername(String) username}</td><td>username used to connect to datasource</td><td>&nbsp;</td></tr>
 * <tr><td>{@link #setPassword(String) password}</td><td>password used to connect to datasource</td><td>&nbsp;</td></tr>
 * <tr><td>{@link #setConnectionsArePooled(boolean) connectionsArePooled}</td><td>when true, it is assumed that an connectionpooling mechanism is present. Before a message is sent, a new connection is obtained, that is closed after the message is sent. When transacted is true, connectionsArePooled is true, too</td><td>true</td></tr>
 * <tr><td>{@link #setJmsRealm(String) jmsRealm}</td><td>&nbsp;</td><td>&nbsp;</td></tr>
 * </table>
 * @author  Gerrit van Brakel
 * @since   4.7
 * @version Id
 */
public class JdbcQueryListener extends JdbcListener {

	public void configure() throws ConfigurationException {
		super.configure();
		if (StringUtils.isEmpty(getSelectQuery())) {
			throw new ConfigurationException("selectQuery must be specified");
		}
		if (StringUtils.isEmpty(getUpdateStatusToProcessedQuery())) {
			throw new ConfigurationException("updateStatusToProcessedQuery must be specified");
		}
		if (StringUtils.isEmpty(getKeyField())) {
			throw new ConfigurationException("keyField must be specified");
		}
	}
	

	public void setKeyField(String fieldname) {
		super.setKeyField(fieldname);
	}

	public void setMessageField(String fieldname) {
		super.setMessageField(fieldname);
	}

	public void setSelectQuery(String string) {
		super.setSelectQuery(string);
	}

	public void setUpdateStatusToErrorQuery(String string) {
		super.setUpdateStatusToErrorQuery(string);
	}

	public void setUpdateStatusToInProcessQuery(String string) {
		super.setUpdateStatusToInProcessQuery(string);
	}

	public void setUpdateStatusToProcessedQuery(String string) {
		super.setUpdateStatusToProcessedQuery(string);
	}


}

@@ -50,17 +50,17 @@
 n 1.
-1
+2
   2008-0
 2-28
@@ -59,20 +59,20 @@
 08-0
-2-28 16:22:4
+6-19 08:10:5
 5  e
@@ -85,16 +85,178 @@
 L190409%0A
+ * set default updateStatusToError-query to updateStatusToProcessed%0A *%0A * Revision 1.1  2008/02/28 16:22:45  Gerrit van Brakel %3Cgerrit.van.brakel@ibissource.org%3E%0A
  * first
@@ -3232,16 +3232,267 @@
 %22);%0A%09%09%7D%0A
+%09%09if (StringUtils.isEmpty(getUpdateStatusToErrorQuery())) %7B%0A%09%09%09log.warn(getLogPrefix()+%22has no updateStatusToErrorQuery specified, will use updateStatusToProcessedQuery instead%22);%0A%09%09%09setUpdateStatusToErrorQuery(getUpdateStatusToProcessedQuery());%0A%09%09%7D%0A
 %09%7D%0A%09%0A%0A%09p

set default updateStatusToError-query to updateStatusToProcessed