running sql from a groovy event handler in agile plm
DESCRIPTION
Have you ever run into a situation where you needed to run SQL from an event handler or PX but wasn't quite sure how to do it? This presentation will show you how to get a connection to the Agile PLM database and execute SQL without worrying about the connection details.TRANSCRIPT
Running SQL from a Agile PLM Groovy Event Handler
Introduction
Will show how to execute SQL from a Groovy handler using the SQL connection already established by the container
Should work fine in a PX – add agileclasses.jar to the IDE classpath for the build but cannot run in the debugger since the PX is not in Agile’s class loader
Sample Scriptimport com.agile.agileDSL.ScriptObj.*;import com.agile.api.*;import com.agile.util.sql.*;import java.sql.*;
void invokeScript(IBaseObjectScriptObj object) {
Connection connection = null;PreparedStatement statement = null;ResultSet rows = null;
try {connection = ConnectionFactory.getFactory().getConnection();statement = connection.prepareStatement("select ifs_url from vault");rows = statement.executeQuery();
while(rows.next()) {
// log the SQL responseobject.logMonitor( "SQL Response: " + rows.getString("ifs_url") );
}
} catch (Exception e) { object.logMonitor( e.getMessage() );
}}
Setting Up Agile for the Test
Setting up the event for our demo
Setting Up Agile for the Test (cont)
Defining the event handler
Setting Up Agile for the Test (cont)
The event subscriber
The Results
I set up my script to execute on the title block update event for items, so simply modifying an attribute on a part and saving the changes will trigger it. If we inspect the event monitor the following entry is found.
About Us
PLM Mechanic specializes in the technical aspects of Oracle’s Agile PLM solution
We offer the following service:– Agile PLM installations and upgrades– Agile PLM maintenance and help desk functions– Agile PLM hosting– Customization
PLM Mechanic also has several product offerings
Contact Us Web: http://www.plmmechanic.com Blog: http://www.plmmechanic.com/blog Facebook: http://facebook.com/PLMMechanic LinkedIn: http://www.linkedin.com/company/plm-mechanic Twitter: @PLMMechanic Email: [email protected] Phone: 512-827-2262 Fax: 512-582-2932