running sql from a groovy event handler in agile plm

9
Running SQL from a Agile PLM Groovy Event Handler

Upload: plm-mechanic-

Post on 25-May-2015

782 views

Category:

Technology


0 download

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

Page 1: Running SQL from a Groovy Event Handler in Agile PLM

Running SQL from a Agile PLM Groovy Event Handler

Page 2: Running SQL from a Groovy Event Handler in Agile PLM

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

Page 3: Running SQL from a Groovy Event Handler in Agile PLM

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() );

}}

Page 4: Running SQL from a Groovy Event Handler in Agile PLM

Setting Up Agile for the Test

Setting up the event for our demo

Page 5: Running SQL from a Groovy Event Handler in Agile PLM

Setting Up Agile for the Test (cont)

Defining the event handler

Page 6: Running SQL from a Groovy Event Handler in Agile PLM

Setting Up Agile for the Test (cont)

The event subscriber

Page 7: Running SQL from a Groovy Event Handler in Agile PLM

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.

Page 8: Running SQL from a Groovy Event Handler in Agile PLM

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

Page 9: Running SQL from a Groovy Event Handler in Agile PLM

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