unico 2003/11/21 09:19:17
Modified:
src/blocks/repository/java/org/apache/cocoon/components/source/impl
SimpleJdbcSourceDescriptor.java
Log:
use a better event name for event caching
Revision Changes Path
1.5 +28 -12
cocoon-2.1/src/blocks/repository/java/org/apache/cocoon/components/source/impl/SimpleJdbcSourceDescriptor.java
Index: SimpleJdbcSourceDescriptor.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/repository/java/org/apache/cocoon/components/source/impl/SimpleJdbcSourceDescriptor.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SimpleJdbcSourceDescriptor.java 21 Nov 2003 11:39:18 -0000 1.4
+++ SimpleJdbcSourceDescriptor.java 21 Nov 2003 17:19:17 -0000 1.5
@@ -54,7 +54,6 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import org.apache.avalon.excalibur.datasource.DataSourceComponent;
@@ -105,8 +104,8 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Unico Hommes</a>
*/
public class SimpleJdbcSourceDescriptor
- extends AbstractConfigurableSourceDescriptor
- implements SourceDescriptor, Serviceable, Configurable, Initializable,
ThreadSafe {
+extends AbstractConfigurableSourceDescriptor
+implements SourceDescriptor, Serviceable, Configurable, Initializable,
ThreadSafe {
private static final String STMT_SELECT_SINGLE =
@@ -158,14 +157,6 @@
public void configure(final Configuration configuration) throws
ConfigurationException {
super.configure(configuration);
m_datasourceName =
configuration.getChild("datasource",true).getValue("cocoondb");
-
- if (m_cache != null) {
- m_eventName = "simple-jdbc:";
- Iterator types = getPropertyTypes().iterator();
- while (types.hasNext()) {
- m_eventName += "/" + types.next();
- }
- }
}
public void initialize() throws Exception {
@@ -332,9 +323,34 @@
public SourceValidity getValidity(Source source) {
if (m_cache != null) {
- return new EventValidity(new
NameValueEvent(m_eventName,source.getURI()));
+ return new EventValidity(new
NameValueEvent(getEventName(),source.getURI()));
}
return null;
}
+ private final String getEventName() {
+ if (m_eventName == null) {
+ Connection connection = null;
+ try {
+ connection = m_datasource.getConnection();
+ String catalogName = connection.getCatalog();
+ m_eventName = (catalogName != null)
+ ? catalogName + "/sourceprops"
+ : "sourceprops";
+ }
+ catch (SQLException e) {
+ getLogger().warn("Error getting catalog name from jdbc
connection.",e);
+ m_eventName = "sourceprops";
+ }
+ finally {
+ if (connection != null) {
+ try {
+ connection.close();
+ } catch (SQLException e) {
+ }
+ }
+ }
+ }
+ return m_eventName;
+ }
}