Java Doc for TriggerSample.java in  » Database-DBMS » hsql » org » hsqldb » sample » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database DBMS » hsql » org.hsqldb.sample 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.hsqldb.sample.TriggerSample

TriggerSample
public class TriggerSample implements Trigger(Code)

Sample code for use of triggers in hsqldb. SQL to invoke is:

CREATE TRIGGER triggerSample BEFORE|AFTER INSERT|UPDATE|DELETE ON myTable [FOR EACH ROW] [QUEUE n] [NOWAIT] CALL "myPackage.trigClass"
This will create a thread that will wait for its firing event to occur; when this happens, the trigger's thread runs the 'trigClass.fire' Note that this is still in the same Java Virtual Machine as the database, so make sure the fired method does not hang.

There is a queue of events waiting to be run by each trigger thread. This is particularly useful for 'FOR EACH ROW' triggers, when a large number of trigger events occur in rapid succession, without the trigger thread getting a chance to run. If the queue becomes full, subsequent additions to it cause the database engine to suspend awaiting space in the queue. Take great care to avoid this situation if the trigger action involves accessing the database, as deadlock will occur. This can be avoided either by ensuring the QUEUE parameter makes a large enough queue, or by using the NOWAIT parameter, which causes a new trigger event to overwrite the most recent event in the queue. The default queue size is 1024.

Ensure that "myPackage.trigClass" is present in the classpath which you use to start hsql.

If the method wants to access the database, it must establish a JDBC connection.

When the 'fire' method is called, it is passed the following arguments:

fire (int type, String trigName, String tabName, Object oldRow[], Object[] newRow)

where 'type' is one of the values enumerated in the Trigger interface and the 'oldRow'/'newRow' pair represents the rows acted on. The first length - 1 array slots contain column values and the final slot contains either null or the value of the internally assigned row identity, if the concerned table has no primary key. The final slot must _never_ be modified.

The mapping of row classes to database types is specified in /doc/hsqlSyntax.html#Datatypes.

To be done:

  1. Implement the "jdbc:default:connection: URL to provide transparent and portable access to internal connections for use in triggers and stored procedures.

  2. Implement declaritive column to trigger method argument mapping, conditional execution (WHEN clause), etc.

  3. Investigate and refine synchronous and asynchronous trigger models.

    Because certain combinations of trigger create parameters cause the individual triggered actions of a multirow update to run in different threads, it is possible for an 'after' trigger to run before its corresponding 'before' trigger; the acceptability and implications of this needs to be investigated, documented and the behaviour of the engine fully specified.

  4. Investigate and implement the SQL 200n specified execution stack under arbitrary triggered action and SQL-invoked routine call graphs.

author:
   Peter Hudson
author:
   boucherb@users
version:
   1.7.2
since:
   1.7.0


Field Summary
final static  Stringaudit_insert_stmt
    
final static  Stringcreate_audit_table_stmt
    
final static  Stringcreate_test_table_stmt
    
final static  Stringdrop_audit_table_stmt
    
final static  Stringdrop_test_table_stmt
    
final static  Stringdrv
    
final static  Stringimpl
    
final static  PrintWriterout
    
final static  Stringpwd
    
final static  Stringtn
    
final static  Stringurl
    
final static  Stringusr
    


Method Summary
public  voidfire(int typ, String trn, String tn, Object[] or, Object[] nr)
     A sample HSQLDB Trigger interface implementation.
public static  StringgetForEachSpec(int type)
    
public static  StringgetOperationSpec(int type)
    
public static  StringgetQueueSpec(int qs)
    
public static  StringgetTriggerDDL(String trn, int typ, String tab, int qs, String impl)
    
public static  StringgetTriggerDescriptor(String trn, int typ, String tab)
    
public static  StringgetWhenSpec(int type)
    
public static  voidmain(String[] args)
    

Field Detail
audit_insert_stmt
final static String audit_insert_stmt(Code)



create_audit_table_stmt
final static String create_audit_table_stmt(Code)



create_test_table_stmt
final static String create_test_table_stmt(Code)



drop_audit_table_stmt
final static String drop_audit_table_stmt(Code)



drop_test_table_stmt
final static String drop_test_table_stmt(Code)



drv
final static String drv(Code)



impl
final static String impl(Code)



out
final static PrintWriter out(Code)



pwd
final static String pwd(Code)



tn
final static String tn(Code)



url
final static String url(Code)



usr
final static String usr(Code)





Method Detail
fire
public void fire(int typ, String trn, String tn, Object[] or, Object[] nr)(Code)
A sample HSQLDB Trigger interface implementation.

This sample prints information about the firing trigger and records actions in an audit table.

The techniques used here are simplified dramatically for demonstration purposes and are in no way recommended as a model upon which to build actual installations involving triggered actions.
Parameters:
  typ - trigger type
Parameters:
  trn - trigger name
Parameters:
  tn - table name
Parameters:
  or - old row
Parameters:
  nr - new row




getForEachSpec
public static String getForEachSpec(int type)(Code)



getOperationSpec
public static String getOperationSpec(int type)(Code)



getQueueSpec
public static String getQueueSpec(int qs)(Code)



getTriggerDDL
public static String getTriggerDDL(String trn, int typ, String tab, int qs, String impl) throws SQLException(Code)



getTriggerDescriptor
public static String getTriggerDescriptor(String trn, int typ, String tab)(Code)



getWhenSpec
public static String getWhenSpec(int type)(Code)



main
public static void main(String[] args) throws SQLException(Code)



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.