arkanovicz commented on code in PR #49:
URL: https://github.com/apache/velocity-engine/pull/49#discussion_r1734571571
##########
velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/DefaultDatabaseObjectsFactory.java:
##########
@@ -0,0 +1,53 @@
+package org.apache.velocity.runtime.resource.loader;
+
+import org.apache.velocity.util.ExtProperties;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+
+/**
+ * Database objects factory which will obtain a new connection from the data
source and prepare needed statements
+ * at each call
+ */
+
+public class DefaultDatabaseObjectsFactory implements DatabaseObjectsFactory {
+
+ private DataSource dataSource;
+
+ /**
+ * Initialize the factory with the DataSourceResourceLoader properties
+ * @param dataSource data source
+ */
+ @Override
+ public void init(DataSource dataSource, ExtProperties properties)
+ {
+ this.dataSource = dataSource;
+ }
+
+ /**
+ * Prepare a statement
+ * @param sql Statement SQL
+ * @return prepared statement
+ */
+ @Override
+ public PreparedStatement prepareStatement(String sql) throws SQLException
+ {
+ Connection connection = dataSource.getConnection();
+ return connection.prepareStatement(sql);
+ }
+
+ /**
+ * Releases a prepared statement
+ * @param sql original sql query
+ * @param stmt statement
+ */
+ @Override
+ public void releaseStatement(String sql, PreparedStatement stmt) throws
SQLException
+ {
+ Connection connection = stmt.getConnection();
Review Comment:
I guess so. The documentation states:
> Retrieves the Connection object that produced this Statement object.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]