You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by "Menon, Manjush" <ma...@usswi.com> on 2005/01/14 08:31:50 UTC

Reg: Custom datasource resource loader

Hi All,

 

Is there any mechanism by which velocity will notify the Custom Data source
Resource Loader after a template is loaded from the db?

 

I checked the source code, but didn't find any implementation for
notification back to the resource loader so that it can clean up the
resources used.

 

 

The Requirement:  I want to cleanup statement object in the Custom Resource
Loader class, but only after the InputStream is completely read by Velocity.

 

Is there anyway to get notified on the status of template reading?

 

Please mail back

 

Thanks in advance

 

--Manjush

 


RE: Custom datasource resource loader

Posted by "Menon, Manjush" <ma...@usswi.com>.
Will,

I had tried that before with the following piece of code:

-------------------------------------------------
InputStream inputStream = null;
StringBuffer content = new StringBuffer();
String line = new String();				

InputStreamReader reader = 
	new InputStreamReader(clob.getAsciiStream(), "US-ASCII");

BufferedReader in = new BufferedReader(reader);
						
while (line != null) {					
	content.append(line);
	line = in.readLine();
}
inputStream = new ByteArrayInputStream(content.toString().getBytes());	
return inputStream;
-------------------------------------------------

This code didn't work though you won't find anything missing in first look.

Let me ask you one thing: is there anything specific with the encoding of
the stream that Velocity expects to read?

The output was same i.e., with empty output. But I can see that the
StringBuffer 'content' has the entire template loaded as String, but the
output is empty. (I didn't debug this scenario with Velocity source code in
place)

--Manjush

-----Original Message-----
From: Will Glass-Husain [mailto:wglass@forio.com] 
Sent: Tuesday, January 18, 2005 11:05 AM
To: manjush_menon@usswi.com; velocity-dev@jakarta.apache.org
Subject: Re: Custom datasource resource loader

Manjush,

Maybe it would be simpler to just dump the entire template into a String,
close the statement, and then return an InputStream based on the String?

The challenge with the notification method is that we can't implement it in
Velocity 1.x because a new interface would break all old resource loaders.
Unless we did a new (optional) interface specifically to add this method.

WILL

----- Original Message ----- 
From: "Menon, Manjush" <ma...@usswi.com>
To: "'Will Glass-Husain'" <wg...@forio.com>;
<ve...@jakarta.apache.org>
Sent: Monday, January 17, 2005 9:24 PM
Subject: RE: Custom datasource resource loader



The InputStream will not return the template data (it will be empty) from
the db if you do the statement.close() before (or even after returning the
Stream and before its read).

We are using Oracle CLOB objects to store templates with BEA Weblogic 8.1
(With SP2) and Connection Pooling enabled.

--Manjush

-----Original Message-----
From: Will Glass-Husain [mailto:wglass@forio.com]
Sent: Tuesday, January 18, 2005 10:41 AM
To: manjush_menon@usswi.com; velocity-dev@jakarta.apache.org
Subject: Re: Custom datasource resource loader

Why can't you close the statement object after the result set is generated
but before the stream is returned?

In other words, just after the statement is used?

WILL

----- Original Message ----- 
From: "Menon, Manjush" <ma...@usswi.com>
To: "'Will Glass-Husain'" <wg...@forio.com>; "'Velocity Developers List'"
<ve...@jakarta.apache.org>
Sent: Monday, January 17, 2005 8:42 PM
Subject: RE: Custom datasource resource loader


Will,

Thanks for the comments.

I too definitely think that the DatasourceResourceLoader should close the
statement object once it is done with.

I have modified the velocity source code to incorporate a notification
mechanism. This works fine for me, but I' m finding the statement objects as
"null" during notification.

I'm planning to modify the source in such a way that any of the resource
loaders can register itself to be notified at a later point of time.

Do add your valuable comments

Thanks

--Manjush

-----Original Message-----
From: Will Glass-Husain [mailto:wglass@forio.com]
Sent: Tuesday, January 18, 2005 12:30 AM
To: Velocity Developers List; manjush_menon@usswi.com
Subject: Re: Custom datasource resource loader

This is a little kludgy, but maybe you could subclass InputStream and
intercept the "close" method?

As an aside, it looks like the built in DatasourceResourceLoader never
closes the statement.   Maybe it should.

WILL

----- Original Message ----- 
From: "Menon, Manjush" <ma...@usswi.com>
To: <ve...@jakarta.apache.org>
Sent: Thursday, January 13, 2005 11:31 PM
Subject: Reg: Custom datasource resource loader


Hi All,



Is there any mechanism by which velocity will notify the Custom Data source
Resource Loader after a template is loaded from the db?



I checked the source code, but didn't find any implementation for
notification back to the resource loader so that it can clean up the
resources used.





The Requirement:  I want to cleanup statement object in the Custom Resource
Loader class, but only after the InputStream is completely read by Velocity.



Is there anyway to get notified on the status of template reading?



Please mail back



Thanks in advance



--Manjush





---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org


Re: Custom datasource resource loader

Posted by Will Glass-Husain <wg...@forio.com>.
Manjush,

Maybe it would be simpler to just dump the entire template into a String,
close the statement, and then return an InputStream based on the String?

The challenge with the notification method is that we can't implement it in
Velocity 1.x because a new interface would break all old resource loaders.
Unless we did a new (optional) interface specifically to add this method.

WILL

----- Original Message ----- 
From: "Menon, Manjush" <ma...@usswi.com>
To: "'Will Glass-Husain'" <wg...@forio.com>;
<ve...@jakarta.apache.org>
Sent: Monday, January 17, 2005 9:24 PM
Subject: RE: Custom datasource resource loader



The InputStream will not return the template data (it will be empty) from
the db if you do the statement.close() before (or even after returning the
Stream and before its read).

We are using Oracle CLOB objects to store templates with BEA Weblogic 8.1
(With SP2) and Connection Pooling enabled.

--Manjush

-----Original Message-----
From: Will Glass-Husain [mailto:wglass@forio.com]
Sent: Tuesday, January 18, 2005 10:41 AM
To: manjush_menon@usswi.com; velocity-dev@jakarta.apache.org
Subject: Re: Custom datasource resource loader

Why can't you close the statement object after the result set is generated
but before the stream is returned?

In other words, just after the statement is used?

WILL

----- Original Message ----- 
From: "Menon, Manjush" <ma...@usswi.com>
To: "'Will Glass-Husain'" <wg...@forio.com>; "'Velocity Developers List'"
<ve...@jakarta.apache.org>
Sent: Monday, January 17, 2005 8:42 PM
Subject: RE: Custom datasource resource loader


Will,

Thanks for the comments.

I too definitely think that the DatasourceResourceLoader should close the
statement object once it is done with.

I have modified the velocity source code to incorporate a notification
mechanism. This works fine for me, but I' m finding the statement objects as
"null" during notification.

I'm planning to modify the source in such a way that any of the resource
loaders can register itself to be notified at a later point of time.

Do add your valuable comments

Thanks

--Manjush

-----Original Message-----
From: Will Glass-Husain [mailto:wglass@forio.com]
Sent: Tuesday, January 18, 2005 12:30 AM
To: Velocity Developers List; manjush_menon@usswi.com
Subject: Re: Custom datasource resource loader

This is a little kludgy, but maybe you could subclass InputStream and
intercept the "close" method?

As an aside, it looks like the built in DatasourceResourceLoader never
closes the statement.   Maybe it should.

WILL

----- Original Message ----- 
From: "Menon, Manjush" <ma...@usswi.com>
To: <ve...@jakarta.apache.org>
Sent: Thursday, January 13, 2005 11:31 PM
Subject: Reg: Custom datasource resource loader


Hi All,



Is there any mechanism by which velocity will notify the Custom Data source
Resource Loader after a template is loaded from the db?



I checked the source code, but didn't find any implementation for
notification back to the resource loader so that it can clean up the
resources used.





The Requirement:  I want to cleanup statement object in the Custom Resource
Loader class, but only after the InputStream is completely read by Velocity.



Is there anyway to get notified on the status of template reading?



Please mail back



Thanks in advance



--Manjush





---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org


RE: Custom datasource resource loader

Posted by "Menon, Manjush" <ma...@usswi.com>.
The InputStream will not return the template data (it will be empty) from
the db if you do the statement.close() before (or even after returning the
Stream and before its read).
 
We are using Oracle CLOB objects to store templates with BEA Weblogic 8.1
(With SP2) and Connection Pooling enabled.

--Manjush

-----Original Message-----
From: Will Glass-Husain [mailto:wglass@forio.com] 
Sent: Tuesday, January 18, 2005 10:41 AM
To: manjush_menon@usswi.com; velocity-dev@jakarta.apache.org
Subject: Re: Custom datasource resource loader

Why can't you close the statement object after the result set is generated 
but before the stream is returned?

In other words, just after the statement is used?

WILL

----- Original Message ----- 
From: "Menon, Manjush" <ma...@usswi.com>
To: "'Will Glass-Husain'" <wg...@forio.com>; "'Velocity Developers List'" 
<ve...@jakarta.apache.org>
Sent: Monday, January 17, 2005 8:42 PM
Subject: RE: Custom datasource resource loader


Will,

Thanks for the comments.

I too definitely think that the DatasourceResourceLoader should close the
statement object once it is done with.

I have modified the velocity source code to incorporate a notification
mechanism. This works fine for me, but I' m finding the statement objects as
"null" during notification.

I'm planning to modify the source in such a way that any of the resource
loaders can register itself to be notified at a later point of time.

Do add your valuable comments

Thanks

--Manjush

-----Original Message-----
From: Will Glass-Husain [mailto:wglass@forio.com]
Sent: Tuesday, January 18, 2005 12:30 AM
To: Velocity Developers List; manjush_menon@usswi.com
Subject: Re: Custom datasource resource loader

This is a little kludgy, but maybe you could subclass InputStream and
intercept the "close" method?

As an aside, it looks like the built in DatasourceResourceLoader never
closes the statement.   Maybe it should.

WILL

----- Original Message ----- 
From: "Menon, Manjush" <ma...@usswi.com>
To: <ve...@jakarta.apache.org>
Sent: Thursday, January 13, 2005 11:31 PM
Subject: Reg: Custom datasource resource loader


Hi All,



Is there any mechanism by which velocity will notify the Custom Data source
Resource Loader after a template is loaded from the db?



I checked the source code, but didn't find any implementation for
notification back to the resource loader so that it can clean up the
resources used.





The Requirement:  I want to cleanup statement object in the Custom Resource
Loader class, but only after the InputStream is completely read by Velocity.



Is there anyway to get notified on the status of template reading?



Please mail back



Thanks in advance



--Manjush





---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org


Re: Custom datasource resource loader

Posted by Will Glass-Husain <wg...@forio.com>.
Why can't you close the statement object after the result set is generated 
but before the stream is returned?

In other words, just after the statement is used?

WILL

----- Original Message ----- 
From: "Menon, Manjush" <ma...@usswi.com>
To: "'Will Glass-Husain'" <wg...@forio.com>; "'Velocity Developers List'" 
<ve...@jakarta.apache.org>
Sent: Monday, January 17, 2005 8:42 PM
Subject: RE: Custom datasource resource loader


Will,

Thanks for the comments.

I too definitely think that the DatasourceResourceLoader should close the
statement object once it is done with.

I have modified the velocity source code to incorporate a notification
mechanism. This works fine for me, but I' m finding the statement objects as
"null" during notification.

I'm planning to modify the source in such a way that any of the resource
loaders can register itself to be notified at a later point of time.

Do add your valuable comments

Thanks

--Manjush

-----Original Message-----
From: Will Glass-Husain [mailto:wglass@forio.com]
Sent: Tuesday, January 18, 2005 12:30 AM
To: Velocity Developers List; manjush_menon@usswi.com
Subject: Re: Custom datasource resource loader

This is a little kludgy, but maybe you could subclass InputStream and
intercept the "close" method?

As an aside, it looks like the built in DatasourceResourceLoader never
closes the statement.   Maybe it should.

WILL

----- Original Message ----- 
From: "Menon, Manjush" <ma...@usswi.com>
To: <ve...@jakarta.apache.org>
Sent: Thursday, January 13, 2005 11:31 PM
Subject: Reg: Custom datasource resource loader


Hi All,



Is there any mechanism by which velocity will notify the Custom Data source
Resource Loader after a template is loaded from the db?



I checked the source code, but didn't find any implementation for
notification back to the resource loader so that it can clean up the
resources used.





The Requirement:  I want to cleanup statement object in the Custom Resource
Loader class, but only after the InputStream is completely read by Velocity.



Is there anyway to get notified on the status of template reading?



Please mail back



Thanks in advance



--Manjush





---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org


RE: Custom datasource resource loader

Posted by "Menon, Manjush" <ma...@usswi.com>.
Will,

Thanks for the comments. 

I too definitely think that the DatasourceResourceLoader should close the
statement object once it is done with.

I have modified the velocity source code to incorporate a notification
mechanism. This works fine for me, but I' m finding the statement objects as
"null" during notification. 

I'm planning to modify the source in such a way that any of the resource
loaders can register itself to be notified at a later point of time.

Do add your valuable comments

Thanks

--Manjush

-----Original Message-----
From: Will Glass-Husain [mailto:wglass@forio.com] 
Sent: Tuesday, January 18, 2005 12:30 AM
To: Velocity Developers List; manjush_menon@usswi.com
Subject: Re: Custom datasource resource loader

This is a little kludgy, but maybe you could subclass InputStream and 
intercept the "close" method?

As an aside, it looks like the built in DatasourceResourceLoader never 
closes the statement.   Maybe it should.

WILL

----- Original Message ----- 
From: "Menon, Manjush" <ma...@usswi.com>
To: <ve...@jakarta.apache.org>
Sent: Thursday, January 13, 2005 11:31 PM
Subject: Reg: Custom datasource resource loader


Hi All,



Is there any mechanism by which velocity will notify the Custom Data source
Resource Loader after a template is loaded from the db?



I checked the source code, but didn't find any implementation for
notification back to the resource loader so that it can clean up the
resources used.





The Requirement:  I want to cleanup statement object in the Custom Resource
Loader class, but only after the InputStream is completely read by Velocity.



Is there anyway to get notified on the status of template reading?



Please mail back



Thanks in advance



--Manjush





---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org


Re: Custom datasource resource loader

Posted by Will Glass-Husain <wg...@forio.com>.
This is a little kludgy, but maybe you could subclass InputStream and 
intercept the "close" method?

As an aside, it looks like the built in DatasourceResourceLoader never 
closes the statement.   Maybe it should.

WILL

----- Original Message ----- 
From: "Menon, Manjush" <ma...@usswi.com>
To: <ve...@jakarta.apache.org>
Sent: Thursday, January 13, 2005 11:31 PM
Subject: Reg: Custom datasource resource loader


Hi All,



Is there any mechanism by which velocity will notify the Custom Data source
Resource Loader after a template is loaded from the db?



I checked the source code, but didn't find any implementation for
notification back to the resource loader so that it can clean up the
resources used.





The Requirement:  I want to cleanup statement object in the Custom Resource
Loader class, but only after the InputStream is completely read by Velocity.



Is there anyway to get notified on the status of template reading?



Please mail back



Thanks in advance



--Manjush





---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org