View Javadoc
1 /* 2 * ==================================================================== 3 * 4 * This code is subject to the freebxml License, Version 1.1 5 * 6 * Copyright (c) 2001 - 2003 freebxml.org. All rights reserved. 7 * 8 * ==================================================================== 9 */ 10 11 package com.sun.ebxml.registry.persistence.rdb; 12 13 import java.sql.ResultSet; 14 import java.sql.SQLException; 15 import java.sql.Statement; 16 import java.util.ArrayList; 17 import java.util.Iterator; 18 19 import org.oasis.ebxml.registry.bindings.query.ResponseOption; 20 import org.oasis.ebxml.registry.bindings.rim.AuditableEvent; 21 import org.oasis.ebxml.registry.bindings.rim.ObjectRef; 22 import org.oasis.ebxml.registry.bindings.rim.User; 23 import org.oasis.ebxml.registry.bindings.rim.types.EventTypeType; 24 25 import com.sun.ebxml.registry.RegistryException; 26 27 28 public class AuditableEventDAO extends RegistryObjectDAO { 29 protected AuditableEventDAO(){} 30 31 public static String getTableNameStatic() { 32 return "AuditableEvent"; 33 } 34 35 public String getTableName() { 36 return getTableNameStatic(); 37 } 38 39 /*** 40 @deprecated 41 */ 42 public void insert(java.sql.Statement stmt 43 , ArrayList auditableEvents) throws RegistryException { 44 try { 45 //Statement stmt = connection.createStatement(); 46 Iterator iter = auditableEvents.iterator(); 47 while (iter.hasNext()) { 48 AuditableEvent auditableEvent = (AuditableEvent) iter.next(); 49 50 java.sql.Timestamp timestamp = new java.sql.Timestamp(auditableEvent.getTimestamp().getTime()); 51 //??The timestamp is being truncated to work around a bug in PostgreSQL 7.2.2 JDBC driver 52 String timestampStr = timestamp.toString().substring(0,19); 53 // System.err.println("*********************************************timestamp = " + timestampStr); 54 55 //System.err.println("ae id: " + auditableEvent.getId()); 56 String sql = "insert into " + getTableName() + " values (" 57 + "null" // accessControlPolicy 58 + ",'"+ auditableEvent.getId() +"'" // id 59 + ",'"+ auditableEvent.getObjectType() +"'" // objectType 60 + ",'"+ auditableEvent.getEventType() +"'" // eventType 61 + ",'"+ auditableEvent.getRegistryObject() +"'" // registryObject 62 + ",'"+ timestampStr +"'" // timeStamp_ 63 + ",'"+ ((User)auditableEvent.getUser()).getId() +"'" // user_ 64 + ")"; 65 //Log.print(Log.TRACE, 5, "Inserting AuditableEvent..."); 66 //Log.print(Log.TRACE, 5, sql); 67 stmt.addBatch(sql); 68 } 69 if (auditableEvents.size() > 0) { 70 stmt.executeBatch(); 71 } 72 } 73 catch (SQLException e) { 74 e.printStackTrace(); 75 RegistryException exception = new RegistryException(e); 76 throw exception; 77 } 78 } 79 80 public void insert(java.sql.Connection conn 81 , ArrayList auditableEvents) throws RegistryException { 82 String auditableEventId = null; 83 Statement stmt = null; 84 if (auditableEvents.size()==0) { 85 return; 86 } 87 try { 88 stmt = conn.createStatement(); 89 Iterator iter = auditableEvents.iterator(); 90 while (iter.hasNext()) { 91 AuditableEvent auditableEvent = (AuditableEvent) iter.next(); 92 auditableEventId = auditableEvent.getId(); 93 94 java.sql.Timestamp timestamp = new java.sql.Timestamp(auditableEvent.getTimestamp().getTime()); 95 //??The timestamp is being truncated to work around a bug in PostgreSQL 7.2.2 JDBC driver 96 String timestampStr = timestamp.toString().substring(0,19); 97 //System.err.println("*********************************************timestamp = " + timestampStr); 98 99 //System.err.println("ae id: " + auditableEvent.getId()); 100 String sql = "insert into " + getTableName() + " values (" 101 + "null" // accessControlPolicy 102 + ",'"+ auditableEvent.getId() +"'" // id 103 + ",'"+ auditableEvent.getObjectType() +"'" // objectType 104 + ",'"+ auditableEvent.getEventType() +"'" // eventType 105 + ",'"+ auditableEvent.getRegistryObject() +"'" // registryObject 106 + ",'"+ timestampStr +"'" // timeStamp_ 107 + ",'"+ ((User)auditableEvent.getUser()).getId() +"'" // user_ 108 + ")"; 109 //Log.print(Log.TRACE, 5, "Inserting AuditableEvent..."); 110 //Log.print(Log.TRACE, 5, sql); 111 stmt.addBatch(sql); 112 } 113 if (auditableEvents.size() > 0) { 114 stmt.executeBatch(); 115 //stmt.close(); 116 } 117 } 118 catch (SQLException e) { 119 e.printStackTrace(); 120 /* It is trying to find out whether the SQLException is because 121 the AuditableEvent already exist. This error is because the registry 122 generate a AuditableEvent with a Id owned by another AuditableEvent. 123 It is very rare. It happens when UUIDFactory can't generate a unique 124 id 125 */ 126 if (auditableEventId != null && registryObjectExist(conn, auditableEventId)) { 127 throw new RegistryException("Internal error: The registry " + 128 "cannot generate AuditableEvent with unique id"); 129 } 130 RegistryException exception = new RegistryException(e); 131 throw exception; 132 } finally { 133 try { 134 if (stmt != null) 135 stmt.close(); 136 } catch (SQLException sqle) { 137 sqle.printStackTrace(); 138 } 139 } 140 } 141 142 public void update(java.sql.Connection conn, ArrayList auditableEvents) { 143 144 } 145 146 public void loadObjectFromResultSet(java.sql.Connection conn, Object obj, ResultSet rs, ResponseOption responseOption, ArrayList objectRefs) throws RegistryException { 147 try { 148 if (!(obj instanceof org.oasis.ebxml.registry.bindings.rim.AuditableEvent)) { 149 throw new RegistryException("Unexpected object " + obj + ". Was expecting org.oasis.ebxml.registry.bindings.rim.AuditableEvent."); 150 } 151 152 AuditableEvent ae = (AuditableEvent)obj; 153 super.loadObjectFromResultSet(conn, obj, rs, responseOption, objectRefs); 154 155 String eventType = rs.getString("eventType"); 156 EventTypeType ett = EventTypeType.valueOf(eventType); 157 ae.setEventType(ett); 158 159 String registryObjectId = rs.getString("registryObject"); 160 ObjectRef ro = new ObjectRef(); 161 objectRefs.add(ro); 162 ro.setId(registryObjectId); 163 ae.setRegistryObject(ro); 164 165 //Workaround for bug in PostgreSQL 7.2.2 JDBC driver 166 //java.sql.Timestamp timeStamp = rs.getTimestamp("timeStamp_"); 167 String timestampStr = rs.getString("timeStamp_").substring(0,19); 168 java.sql.Timestamp timeStamp = java.sql.Timestamp.valueOf(timestampStr); 169 ae.setTimestamp(timeStamp); 170 171 String userId = rs.getString("user_"); 172 ro = new ObjectRef(); 173 objectRefs.add(ro); 174 ro.setId(userId); 175 ae.setUser(ro); 176 177 178 179 } 180 catch (SQLException e) { 181 e.printStackTrace(); 182 throw new RegistryException(e); 183 } 184 } 185 186 public ArrayList getLeafObjectList(java.sql.Connection conn, ResultSet rs, ResponseOption responseOption, ArrayList objectRefs) throws RegistryException { 187 ArrayList res = new ArrayList(); 188 189 try { 190 while(rs.next()) { 191 AuditableEvent obj = new AuditableEvent(); 192 loadObjectFromResultSet(conn, obj, rs, responseOption, objectRefs); 193 194 res.add(obj); 195 } 196 } 197 catch (SQLException e) { 198 e.printStackTrace(); 199 throw new RegistryException(e); 200 } 201 202 203 return res; 204 } 205 206 public static AuditableEventDAO getInstance(){ 207 if (instance == null) { 208 synchronized(AuditableEventDAO.class) { 209 if (instance == null) { 210 instance = new AuditableEventDAO(); 211 } 212 } 213 } 214 return instance; 215 } 216 217 /*** 218 * @link 219 * @shapeType PatternLink 220 * @pattern Singleton 221 * @supplierRole Singleton factory 222 */ 223 /*# private AuditableEventDAO _auditableEventDAO; */ 224 private static AuditableEventDAO instance = null; 225 }

This page was automatically generated by Maven