1 24 25 package com.mckoi.database; 26 27 32 33 public class TableModificationEvent { 34 35 37 40 public static final int BEFORE = 0x010; 41 42 45 public static final int AFTER = 0x020; 46 47 49 52 public static final int INSERT = 0x001; 53 54 57 public static final int UPDATE = 0x002; 58 59 62 public static final int DELETE = 0x004; 63 64 66 69 public static final int BEFORE_INSERT = BEFORE | INSERT; 70 71 74 public static final int AFTER_INSERT = AFTER | INSERT; 75 76 79 public static final int BEFORE_UPDATE = BEFORE | UPDATE; 80 81 84 public static final int AFTER_UPDATE = AFTER | UPDATE; 85 86 89 public static final int BEFORE_DELETE = BEFORE | DELETE; 90 91 94 public static final int AFTER_DELETE = AFTER | DELETE; 95 96 97 99 102 private DatabaseConnection connection; 103 104 107 private TableName table_name; 108 109 112 private int event_type; 113 114 120 private RowData row_data; 121 122 127 private int row_index = -1; 128 129 132 private TableModificationEvent(DatabaseConnection connection, 133 TableName table_name, int row_index, RowData row_data, 134 int type, boolean before) { 135 this.connection = connection; 136 this.table_name = table_name; 137 this.row_index = row_index; 138 this.row_data = row_data; 139 this.event_type = type | (before ? BEFORE : AFTER); 140 } 141 142 145 TableModificationEvent(DatabaseConnection connection, TableName table_name, 146 RowData row_data, boolean before) { 147 this(connection, table_name, -1, row_data, INSERT, before); 148 } 149 150 153 TableModificationEvent(DatabaseConnection connection, TableName table_name, 154 int row_index, RowData row_data, boolean before) { 155 this(connection, table_name, row_index, row_data, UPDATE, before); 156 } 157 158 161 TableModificationEvent(DatabaseConnection connection, TableName table_name, 162 int row_index, boolean before) { 163 this(connection, table_name, row_index, null, DELETE, before); 164 } 165 166 169 public DatabaseConnection getDatabaseConnection() { 170 return connection; 171 } 172 173 176 public int getType() { 177 return event_type; 178 } 179 180 183 public boolean isBefore() { 184 return (event_type & BEFORE) != 0; 185 } 186 187 190 public boolean isAfter() { 191 return (event_type & AFTER) != 0; 192 } 193 194 197 public boolean isInsert() { 198 return (event_type & INSERT) != 0; 199 } 200 201 204 public boolean isUpdate() { 205 return (event_type & UPDATE) != 0; 206 } 207 208 211 public boolean isDelete() { 212 return (event_type & DELETE) != 0; 213 } 214 215 218 public TableName getTableName() { 219 return table_name; 220 } 221 222 226 public int getRowIndex() { 227 return row_index; 228 } 229 230 235 public RowData getRowData() { 236 return row_data; 237 } 238 239 245 public boolean listenedBy(int listen_t) { 246 boolean ba_match = 249 ( (event_type & BEFORE) != 0 && (listen_t & BEFORE) != 0 ) || 250 ( (event_type & AFTER) != 0 && (listen_t & AFTER) != 0 ); 251 boolean trig_match = 254 ( (event_type & INSERT) != 0 && (listen_t & INSERT) != 0 ) || 255 ( (event_type & DELETE) != 0 && (listen_t & DELETE) != 0 ) || 256 ( (event_type & UPDATE) != 0 && (listen_t & UPDATE) != 0 ); 257 return (ba_match && trig_match); 259 } 260 261 } 262 263 | Popular Tags |