001// -------------------------------------------------------------------------------- 002// Copyright 2002-2024 Echo Three, LLC 003// 004// Licensed under the Apache License, Version 2.0 (the "License"); 005// you may not use this file except in compliance with the License. 006// You may obtain a copy of the License at 007// 008// http://www.apache.org/licenses/LICENSE-2.0 009// 010// Unless required by applicable law or agreed to in writing, software 011// distributed under the License is distributed on an "AS IS" BASIS, 012// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013// See the License for the specific language governing permissions and 014// limitations under the License. 015// -------------------------------------------------------------------------------- 016// Generated File -- DO NOT EDIT BY HAND 017// -------------------------------------------------------------------------------- 018 019/** 020 * LetterSourceDetailFactory.java 021 */ 022 023package com.echothree.model.data.letter.server.factory; 024 025import com.echothree.model.data.letter.common.pk.LetterSourcePK; 026import com.echothree.model.data.party.common.pk.PartyPK; 027import com.echothree.model.data.contact.common.pk.PartyContactMechanismPK; 028 029import com.echothree.model.data.letter.server.entity.LetterSource; 030import com.echothree.model.data.party.server.entity.Party; 031import com.echothree.model.data.contact.server.entity.PartyContactMechanism; 032 033import com.echothree.model.data.letter.common.LetterSourceDetailConstants; 034import com.echothree.model.data.letter.common.pk.LetterSourceDetailPK; 035import com.echothree.model.data.letter.server.value.LetterSourceDetailValue; 036import com.echothree.model.data.letter.server.entity.LetterSourceDetail; 037import com.echothree.util.common.exception.PersistenceDatabaseException; 038import com.echothree.util.common.exception.PersistenceDatabaseUpdateException; 039import com.echothree.util.common.exception.PersistenceNotNullException; 040import com.echothree.util.server.persistence.BaseFactory; 041import com.echothree.util.server.persistence.EntityIdGenerator; 042import com.echothree.util.server.persistence.EntityPermission; 043import com.echothree.util.server.persistence.PersistenceDebugFlags; 044import com.echothree.util.server.persistence.Session; 045import com.echothree.util.server.persistence.ThreadSession; 046import java.sql.PreparedStatement; 047import java.sql.ResultSet; 048import java.sql.SQLException; 049import java.sql.Types; 050import java.io.ByteArrayInputStream; 051import java.io.StringReader; 052import java.util.ArrayList; 053import java.util.Collection; 054import java.util.HashSet; 055import java.util.List; 056import java.util.Map; 057import java.util.Set; 058import org.apache.commons.logging.Log; 059import org.apache.commons.logging.LogFactory; 060 061public class LetterSourceDetailFactory 062 implements BaseFactory<LetterSourceDetailPK, LetterSourceDetail> { 063 064 //final private static Log log = LogFactory.getLog(LetterSourceDetailFactory.class); 065 066 final private static String SQL_SELECT_READ_ONLY = "SELECT lttrsrcdt_lettersourcedetailid, lttrsrcdt_lttrsrc_lettersourceid, lttrsrcdt_lettersourcename, lttrsrcdt_companypartyid, lttrsrcdt_emailaddresspartycontactmechanismid, lttrsrcdt_postaladdresspartycontactmechanismid, lttrsrcdt_lettersourcepartycontactmechanismid, lttrsrcdt_isdefault, lttrsrcdt_sortorder, lttrsrcdt_fromtime, lttrsrcdt_thrutime FROM lettersourcedetails WHERE lttrsrcdt_lettersourcedetailid = ?"; 067 final private static String SQL_SELECT_READ_WRITE = "SELECT lttrsrcdt_lettersourcedetailid, lttrsrcdt_lttrsrc_lettersourceid, lttrsrcdt_lettersourcename, lttrsrcdt_companypartyid, lttrsrcdt_emailaddresspartycontactmechanismid, lttrsrcdt_postaladdresspartycontactmechanismid, lttrsrcdt_lettersourcepartycontactmechanismid, lttrsrcdt_isdefault, lttrsrcdt_sortorder, lttrsrcdt_fromtime, lttrsrcdt_thrutime FROM lettersourcedetails WHERE lttrsrcdt_lettersourcedetailid = ? FOR UPDATE"; 068 final private static String SQL_INSERT = "INSERT INTO lettersourcedetails (lttrsrcdt_lettersourcedetailid, lttrsrcdt_lttrsrc_lettersourceid, lttrsrcdt_lettersourcename, lttrsrcdt_companypartyid, lttrsrcdt_emailaddresspartycontactmechanismid, lttrsrcdt_postaladdresspartycontactmechanismid, lttrsrcdt_lettersourcepartycontactmechanismid, lttrsrcdt_isdefault, lttrsrcdt_sortorder, lttrsrcdt_fromtime, lttrsrcdt_thrutime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; 069 final private static String SQL_UPDATE = "UPDATE lettersourcedetails SET lttrsrcdt_lttrsrc_lettersourceid = ?, lttrsrcdt_lettersourcename = ?, lttrsrcdt_companypartyid = ?, lttrsrcdt_emailaddresspartycontactmechanismid = ?, lttrsrcdt_postaladdresspartycontactmechanismid = ?, lttrsrcdt_lettersourcepartycontactmechanismid = ?, lttrsrcdt_isdefault = ?, lttrsrcdt_sortorder = ?, lttrsrcdt_fromtime = ?, lttrsrcdt_thrutime = ? WHERE lttrsrcdt_lettersourcedetailid = ?"; 070 final private static String SQL_DELETE = "DELETE FROM lettersourcedetails WHERE lttrsrcdt_lettersourcedetailid = ?"; 071 final private static String SQL_VALID = "SELECT COUNT(*) FROM lettersourcedetails WHERE lttrsrcdt_lettersourcedetailid = ?"; 072 073 final private static String PK_COLUMN = "lttrsrcdt_lettersourcedetailid"; 074 final private static String ALL_COLUMNS = "lttrsrcdt_lettersourcedetailid, lttrsrcdt_lttrsrc_lettersourceid, lttrsrcdt_lettersourcename, lttrsrcdt_companypartyid, lttrsrcdt_emailaddresspartycontactmechanismid, lttrsrcdt_postaladdresspartycontactmechanismid, lttrsrcdt_lettersourcepartycontactmechanismid, lttrsrcdt_isdefault, lttrsrcdt_sortorder, lttrsrcdt_fromtime, lttrsrcdt_thrutime"; 075 final public static String TABLE_NAME = "lettersourcedetails"; 076 077 final public static String LTTRSRCDT_LETTERSOURCEDETAILID = "lttrsrcdt_lettersourcedetailid"; 078 final public static String LTTRSRCDT_LTTRSRC_LETTERSOURCEID = "lttrsrcdt_lttrsrc_lettersourceid"; 079 final public static String LTTRSRCDT_LETTERSOURCENAME = "lttrsrcdt_lettersourcename"; 080 final public static String LTTRSRCDT_COMPANYPARTYID = "lttrsrcdt_companypartyid"; 081 final public static String LTTRSRCDT_EMAILADDRESSPARTYCONTACTMECHANISMID = "lttrsrcdt_emailaddresspartycontactmechanismid"; 082 final public static String LTTRSRCDT_POSTALADDRESSPARTYCONTACTMECHANISMID = "lttrsrcdt_postaladdresspartycontactmechanismid"; 083 final public static String LTTRSRCDT_LETTERSOURCEPARTYCONTACTMECHANISMID = "lttrsrcdt_lettersourcepartycontactmechanismid"; 084 final public static String LTTRSRCDT_ISDEFAULT = "lttrsrcdt_isdefault"; 085 final public static String LTTRSRCDT_SORTORDER = "lttrsrcdt_sortorder"; 086 final public static String LTTRSRCDT_FROMTIME = "lttrsrcdt_fromtime"; 087 final public static String LTTRSRCDT_THRUTIME = "lttrsrcdt_thrutime"; 088 089 final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(LetterSourceDetailConstants.COMPONENT_VENDOR_NAME, LetterSourceDetailConstants.ENTITY_TYPE_NAME); 090 091 /** Creates a new instance of LetterSourceDetailFactory */ 092 private LetterSourceDetailFactory() { 093 super(); 094 } 095 096 private static class LetterSourceDetailFactoryHolder { 097 static LetterSourceDetailFactory instance = new LetterSourceDetailFactory(); 098 } 099 100 public static LetterSourceDetailFactory getInstance() { 101 return LetterSourceDetailFactoryHolder.instance; 102 } 103 104 @Override 105 public String getPKColumn() { 106 return PK_COLUMN; 107 } 108 109 @Override 110 public String getAllColumns() { 111 return ALL_COLUMNS; 112 } 113 114 @Override 115 public String getTableName() { 116 return TABLE_NAME; 117 } 118 119 @Override 120 public String getComponentVendorName() { 121 return LetterSourceDetailConstants.COMPONENT_VENDOR_NAME; 122 } 123 124 @Override 125 public String getEntityTypeName() { 126 return LetterSourceDetailConstants.ENTITY_TYPE_NAME; 127 } 128 129 public PreparedStatement prepareStatement(String query) { 130 return ThreadSession.currentSession().prepareStatement(LetterSourceDetailFactory.class, query); 131 } 132 133 public LetterSourceDetailPK getNextPK() { 134 return new LetterSourceDetailPK(entityIdGenerator.getNextEntityId()); 135 } 136 137 public Set<LetterSourceDetailPK> getPKsFromResultSetAsSet(ResultSet rs) 138 throws PersistenceDatabaseException { 139 Set<LetterSourceDetailPK> _result = new HashSet<>(); 140 141 try { 142 while(rs.next()) { 143 _result.add(getPKFromResultSet(rs)); 144 } 145 } catch (SQLException se) { 146 throw new PersistenceDatabaseException(se); 147 } 148 149 return _result; 150 } 151 152 public java.util.List<LetterSourceDetailPK> getPKsFromResultSetAsList(ResultSet rs) 153 throws PersistenceDatabaseException { 154 java.util.List<LetterSourceDetailPK> _result = new ArrayList<>(); 155 156 try { 157 while(rs.next()) { 158 _result.add(getPKFromResultSet(rs)); 159 } 160 } catch (SQLException se) { 161 throw new PersistenceDatabaseException(se); 162 } 163 164 return _result; 165 } 166 167 public LetterSourceDetailPK getPKFromResultSet(ResultSet rs) 168 throws PersistenceDatabaseException { 169 LetterSourceDetailPK _result; 170 171 try { 172 long lttrsrcdt_lettersourcedetailid = rs.getLong(LTTRSRCDT_LETTERSOURCEDETAILID); 173 Long _entityId = rs.wasNull() ? null : lttrsrcdt_lettersourcedetailid; 174 175 _result = new LetterSourceDetailPK(_entityId); 176 } catch (SQLException se) { 177 throw new PersistenceDatabaseException(se); 178 } 179 180 return _result; 181 } 182 183 public java.util.List<LetterSourceDetailValue> getValuesFromPKs(Session session, Collection<LetterSourceDetailPK> pks) 184 throws PersistenceDatabaseException { 185 java.util.List<LetterSourceDetailValue> _values = new ArrayList<>(pks.size()); 186 187 for(LetterSourceDetailPK _pk: pks) { 188 _values.add(getValueFromPK(session, _pk)); 189 } 190 191 return _values; 192 } 193 194 public LetterSourceDetailValue getValueFromPK(Session session, LetterSourceDetailPK pk) 195 throws PersistenceDatabaseException { 196 LetterSourceDetailValue _value; 197 198 // See if we already have the entity in the session cache 199 LetterSourceDetail _entity = (LetterSourceDetail)session.getEntity(pk); 200 if(_entity == null) 201 _value = getEntityFromPK(session, EntityPermission.READ_ONLY, pk).getLetterSourceDetailValue(); 202 else 203 _value = _entity.getLetterSourceDetailValue(); 204 205 return _value; 206 } 207 208 public java.util.List<LetterSourceDetailValue> getValuesFromResultSet(Session session, ResultSet rs) 209 throws PersistenceDatabaseException { 210 java.util.List<LetterSourceDetailValue> _result = new ArrayList<>(); 211 212 try { 213 while(rs.next()) { 214 _result.add(getValueFromResultSet(session, rs)); 215 } 216 } catch (SQLException se) { 217 throw new PersistenceDatabaseException(se); 218 } 219 220 return _result; 221 } 222 223 public LetterSourceDetailValue getValueFromResultSet(Session session, ResultSet rs) 224 throws PersistenceDatabaseException { 225 LetterSourceDetailValue _value; 226 227 try { 228 Long lttrsrcdt_lettersourcedetailid = rs.getLong(LTTRSRCDT_LETTERSOURCEDETAILID); 229 LetterSourceDetailPK _pk = new LetterSourceDetailPK(lttrsrcdt_lettersourcedetailid); 230 231 // See if we already have the entity in the session cache 232 LetterSourceDetail _entity = (LetterSourceDetail)session.getEntity(_pk); 233 234 if(_entity == null) { 235 Long lttrsrcdt_lttrsrc_lettersourceid = rs.getLong(LTTRSRCDT_LTTRSRC_LETTERSOURCEID); 236 if(rs.wasNull()) 237 lttrsrcdt_lttrsrc_lettersourceid = null; 238 239 String lttrsrcdt_lettersourcename = rs.getString(LTTRSRCDT_LETTERSOURCENAME); 240 if(rs.wasNull()) 241 lttrsrcdt_lettersourcename = null; 242 243 Long lttrsrcdt_companypartyid = rs.getLong(LTTRSRCDT_COMPANYPARTYID); 244 if(rs.wasNull()) 245 lttrsrcdt_companypartyid = null; 246 247 Long lttrsrcdt_emailaddresspartycontactmechanismid = rs.getLong(LTTRSRCDT_EMAILADDRESSPARTYCONTACTMECHANISMID); 248 if(rs.wasNull()) 249 lttrsrcdt_emailaddresspartycontactmechanismid = null; 250 251 Long lttrsrcdt_postaladdresspartycontactmechanismid = rs.getLong(LTTRSRCDT_POSTALADDRESSPARTYCONTACTMECHANISMID); 252 if(rs.wasNull()) 253 lttrsrcdt_postaladdresspartycontactmechanismid = null; 254 255 Long lttrsrcdt_lettersourcepartycontactmechanismid = rs.getLong(LTTRSRCDT_LETTERSOURCEPARTYCONTACTMECHANISMID); 256 if(rs.wasNull()) 257 lttrsrcdt_lettersourcepartycontactmechanismid = null; 258 259 Boolean lttrsrcdt_isdefault = rs.getInt(LTTRSRCDT_ISDEFAULT) == 1; 260 if(rs.wasNull()) 261 lttrsrcdt_isdefault = null; 262 263 Integer lttrsrcdt_sortorder = rs.getInt(LTTRSRCDT_SORTORDER); 264 if(rs.wasNull()) 265 lttrsrcdt_sortorder = null; 266 267 Long lttrsrcdt_fromtime = rs.getLong(LTTRSRCDT_FROMTIME); 268 if(rs.wasNull()) 269 lttrsrcdt_fromtime = null; 270 271 Long lttrsrcdt_thrutime = rs.getLong(LTTRSRCDT_THRUTIME); 272 if(rs.wasNull()) 273 lttrsrcdt_thrutime = null; 274 275 _value = new LetterSourceDetailValue(_pk, new LetterSourcePK(lttrsrcdt_lttrsrc_lettersourceid), lttrsrcdt_lettersourcename, new PartyPK(lttrsrcdt_companypartyid), new PartyContactMechanismPK(lttrsrcdt_emailaddresspartycontactmechanismid), new PartyContactMechanismPK(lttrsrcdt_postaladdresspartycontactmechanismid), new PartyContactMechanismPK(lttrsrcdt_lettersourcepartycontactmechanismid), lttrsrcdt_isdefault, lttrsrcdt_sortorder, lttrsrcdt_fromtime, lttrsrcdt_thrutime); 276 } else 277 _value = _entity.getLetterSourceDetailValue(); 278 } catch (SQLException se) { 279 throw new PersistenceDatabaseException(se); 280 } 281 282 return _value; 283 } 284 285 public java.util.List<LetterSourceDetail> getEntitiesFromPKs(EntityPermission entityPermission, Collection<LetterSourceDetailPK> pks) 286 throws PersistenceDatabaseException { 287 return getEntitiesFromPKs(ThreadSession.currentSession(), entityPermission, pks); 288 } 289 290 public java.util.List<LetterSourceDetail> getEntitiesFromPKs(Session session, EntityPermission entityPermission, Collection<LetterSourceDetailPK> pks) 291 throws PersistenceDatabaseException { 292 java.util.List<LetterSourceDetail> _entities = new ArrayList<>(pks.size()); 293 294 for(LetterSourceDetailPK _pk: pks) { 295 _entities.add(getEntityFromPK(session, entityPermission, _pk)); 296 } 297 298 return _entities; 299 } 300 301 public LetterSourceDetail getEntityFromValue(EntityPermission entityPermission, LetterSourceDetailValue value) { 302 return getEntityFromPK(ThreadSession.currentSession(), entityPermission, value.getPrimaryKey()); 303 } 304 305 public LetterSourceDetail getEntityFromValue(Session session, EntityPermission entityPermission, LetterSourceDetailValue value) { 306 return getEntityFromPK(session, entityPermission, value.getPrimaryKey()); 307 } 308 309 public LetterSourceDetail getEntityFromPK(EntityPermission entityPermission, LetterSourceDetailPK pk) 310 throws PersistenceDatabaseException { 311 return getEntityFromPK(ThreadSession.currentSession(), entityPermission, pk); 312 } 313 314 public LetterSourceDetail getEntityFromCache(Session session, LetterSourceDetailPK pk) { 315 LetterSourceDetailValue _value = (LetterSourceDetailValue)session.getValueCache().get(pk); 316 317 return _value == null ? null : new LetterSourceDetail(_value, EntityPermission.READ_ONLY); 318 } 319 320 public LetterSourceDetail getEntityFromPK(Session session, EntityPermission entityPermission, LetterSourceDetailPK pk) 321 throws PersistenceDatabaseException { 322 LetterSourceDetail _entity; 323 324 // See if we already have the entity in the session cache 325 _entity = (LetterSourceDetail)session.getEntity(pk); 326 if(_entity != null) { 327 // If the requested permission is READ_WRITE, and the cached permission is 328 // READ_ONLY, then pretend that the cached object wasn't found, and create 329 // a new entity that is READ_WRITE. 330 if(entityPermission.equals(EntityPermission.READ_WRITE)) { 331 if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY)) 332 _entity = null; 333 } 334 } 335 336 if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) { 337 _entity = getEntityFromCache(session, pk); 338 } 339 340 if(_entity == null) { 341 PreparedStatement _ps = session.prepareStatement(entityPermission.equals(EntityPermission.READ_ONLY)? SQL_SELECT_READ_ONLY: SQL_SELECT_READ_WRITE); 342 long _entityId = pk.getEntityId(); 343 ResultSet _rs = null; 344 345 try { 346 _ps.setLong(1, _entityId); 347 _rs = _ps.executeQuery(); 348 if(_rs.next()) { 349 _entity = getEntityFromResultSet(session, entityPermission, _rs); 350 } 351 } catch (SQLException se) { 352 throw new PersistenceDatabaseException(se); 353 } finally { 354 if(_rs != null) { 355 try { 356 _rs.close(); 357 } catch (SQLException se) { 358 // do nothing 359 } 360 } 361 } 362 } 363 364 return _entity; 365 } 366 367 public Set<LetterSourceDetailPK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params) 368 throws PersistenceDatabaseException { 369 Set<LetterSourceDetailPK> _pks; 370 ResultSet _rs = null; 371 372 try { 373 if(params.length != 0) { 374 Session.setQueryParams(ps, params); 375 } 376 377 _rs = ps.executeQuery(); 378 _pks = getPKsFromResultSetAsSet(_rs); 379 _rs.close(); 380 } catch (SQLException se) { 381 throw new PersistenceDatabaseException(se); 382 } finally { 383 if(_rs != null) { 384 try { 385 _rs.close(); 386 } catch (SQLException se) { 387 // do nothing 388 } 389 } 390 } 391 392 return _pks; 393 } 394 395 public java.util.List<LetterSourceDetailPK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params) 396 throws PersistenceDatabaseException { 397 java.util.List<LetterSourceDetailPK> _pks; 398 ResultSet _rs = null; 399 400 try { 401 if(params.length != 0) { 402 Session.setQueryParams(ps, params); 403 } 404 405 _rs = ps.executeQuery(); 406 _pks = getPKsFromResultSetAsList(_rs); 407 _rs.close(); 408 } catch (SQLException se) { 409 throw new PersistenceDatabaseException(se); 410 } finally { 411 if(_rs != null) { 412 try { 413 _rs.close(); 414 } catch (SQLException se) { 415 // do nothing 416 } 417 } 418 } 419 420 return _pks; 421 } 422 423 public LetterSourceDetailPK getPKFromQuery(PreparedStatement ps, final Object... params) 424 throws PersistenceDatabaseException { 425 LetterSourceDetailPK _pk = null; 426 ResultSet _rs = null; 427 428 try { 429 if(params.length != 0) { 430 Session.setQueryParams(ps, params); 431 } 432 433 _rs = ps.executeQuery(); 434 if(_rs.next()) { 435 _pk = getPKFromResultSet(_rs); 436 } 437 _rs.close(); 438 } catch (SQLException se) { 439 throw new PersistenceDatabaseException(se); 440 } finally { 441 if(_rs != null) { 442 try { 443 _rs.close(); 444 } catch (SQLException se) { 445 // do nothing 446 } 447 } 448 } 449 450 return _pk; 451 } 452 453 public java.util.List<LetterSourceDetail> getEntitiesFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 454 throws PersistenceDatabaseException { 455 PreparedStatement ps = session.prepareStatement(LetterSourceDetailFactory.class, queryMap.get(entityPermission)); 456 457 return getEntitiesFromQuery(session, entityPermission, ps, params); 458 } 459 460 public java.util.List<LetterSourceDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 461 throws PersistenceDatabaseException { 462 Session session = ThreadSession.currentSession(); 463 PreparedStatement ps = session.prepareStatement(LetterSourceDetailFactory.class, queryMap.get(entityPermission)); 464 465 return getEntitiesFromQuery(session, entityPermission, ps, params); 466 } 467 468 public java.util.List<LetterSourceDetail> getEntitiesFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 469 throws PersistenceDatabaseException { 470 PreparedStatement ps = session.prepareStatement(LetterSourceDetailFactory.class, queryMap.get(entityPermission)); 471 472 return getEntitiesFromQuery(session, entityPermission, ps); 473 } 474 475 public java.util.List<LetterSourceDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 476 throws PersistenceDatabaseException { 477 Session session = ThreadSession.currentSession(); 478 PreparedStatement ps = session.prepareStatement(LetterSourceDetailFactory.class, queryMap.get(entityPermission)); 479 480 return getEntitiesFromQuery(session, entityPermission, ps); 481 } 482 483 public java.util.List<LetterSourceDetail> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps) 484 throws PersistenceDatabaseException { 485 return getEntitiesFromQuery(ThreadSession.currentSession(), entityPermission, ps); 486 } 487 488 public java.util.List<LetterSourceDetail> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 489 throws PersistenceDatabaseException { 490 return getEntitiesFromQuery(ThreadSession.currentSession(), entityPermission, ps, params); 491 } 492 493 public java.util.List<LetterSourceDetail> getEntitiesFromQuery(Session session, EntityPermission entityPermission, PreparedStatement ps, final Object... params) 494 throws PersistenceDatabaseException { 495 java.util.List<LetterSourceDetail> _entities; 496 ResultSet _rs = null; 497 498 try { 499 if(params.length != 0) { 500 Session.setQueryParams(ps, params); 501 } 502 503 _rs = ps.executeQuery(); 504 _entities = getEntitiesFromResultSet(session, entityPermission, _rs); 505 _rs.close(); 506 } catch (SQLException se) { 507 throw new PersistenceDatabaseException(se); 508 } finally { 509 if(_rs != null) { 510 try { 511 _rs.close(); 512 } catch (SQLException se) { 513 // do nothing 514 } 515 } 516 } 517 518 return _entities; 519 } 520 521 public LetterSourceDetail getEntityFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 522 throws PersistenceDatabaseException { 523 PreparedStatement ps = session.prepareStatement(LetterSourceDetailFactory.class, queryMap.get(entityPermission)); 524 525 return getEntityFromQuery(session, entityPermission, ps, params); 526 } 527 528 public LetterSourceDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 529 throws PersistenceDatabaseException { 530 Session session = ThreadSession.currentSession(); 531 PreparedStatement ps = session.prepareStatement(LetterSourceDetailFactory.class, queryMap.get(entityPermission)); 532 533 return getEntityFromQuery(session, entityPermission, ps, params); 534 } 535 536 public LetterSourceDetail getEntityFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 537 throws PersistenceDatabaseException { 538 PreparedStatement ps = session.prepareStatement(LetterSourceDetailFactory.class, queryMap.get(entityPermission)); 539 540 return getEntityFromQuery(session, entityPermission, ps); 541 } 542 543 public LetterSourceDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 544 throws PersistenceDatabaseException { 545 Session session = ThreadSession.currentSession(); 546 PreparedStatement ps = session.prepareStatement(LetterSourceDetailFactory.class, queryMap.get(entityPermission)); 547 548 return getEntityFromQuery(session, entityPermission, ps); 549 } 550 551 public LetterSourceDetail getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps) 552 throws PersistenceDatabaseException { 553 return getEntityFromQuery(ThreadSession.currentSession(), entityPermission, ps); 554 } 555 556 public LetterSourceDetail getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 557 throws PersistenceDatabaseException { 558 return getEntityFromQuery(ThreadSession.currentSession(), entityPermission, ps, params); 559 } 560 561 public LetterSourceDetail getEntityFromQuery(Session session, EntityPermission entityPermission, PreparedStatement ps, final Object... params) 562 throws PersistenceDatabaseException { 563 LetterSourceDetail _entity = null; 564 ResultSet _rs = null; 565 566 try { 567 if(params.length != 0) { 568 Session.setQueryParams(ps, params); 569 } 570 571 _rs = ps.executeQuery(); 572 if(_rs.next()) { 573 _entity = getEntityFromResultSet(session, entityPermission, _rs); 574 } 575 _rs.close(); 576 } catch (SQLException se) { 577 throw new PersistenceDatabaseException(se); 578 } finally { 579 if(_rs != null) { 580 try { 581 _rs.close(); 582 } catch (SQLException se) { 583 // do nothing 584 } 585 } 586 } 587 588 return _entity; 589 } 590 591 public java.util.List<LetterSourceDetail> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs) 592 throws PersistenceDatabaseException { 593 return getEntitiesFromResultSet(ThreadSession.currentSession(), entityPermission, rs); 594 } 595 596 public java.util.List<LetterSourceDetail> getEntitiesFromResultSet(Session session, EntityPermission entityPermission, ResultSet rs) 597 throws PersistenceDatabaseException { 598 java.util.List<LetterSourceDetail> _result = new ArrayList<>(); 599 600 try { 601 while(rs.next()) { 602 _result.add(getEntityFromResultSet(session, entityPermission, rs)); 603 } 604 } catch (SQLException se) { 605 throw new PersistenceDatabaseException(se); 606 } 607 608 return _result; 609 } 610 611 public LetterSourceDetail getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs) 612 throws PersistenceDatabaseException { 613 return getEntityFromResultSet(ThreadSession.currentSession(), entityPermission, rs); 614 } 615 616 public LetterSourceDetail getEntityFromResultSet(Session session, EntityPermission entityPermission, ResultSet rs) 617 throws PersistenceDatabaseException { 618 LetterSourceDetail _entity; 619 620 try { 621 Long lttrsrcdt_lettersourcedetailid = rs.getLong(LTTRSRCDT_LETTERSOURCEDETAILID); 622 LetterSourceDetailPK _pk = new LetterSourceDetailPK(lttrsrcdt_lettersourcedetailid); 623 624 // See if we already have the entity in the session cache 625 _entity = (LetterSourceDetail)session.getEntity(_pk); 626 if(_entity != null) { 627 // If the requested permission is READ_WRITE, and the cached permission is 628 // READ_ONLY, then pretend that the cached object wasn't found, and create 629 // a new entity that is READ_WRITE. 630 if(entityPermission.equals(EntityPermission.READ_WRITE)) { 631 if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY)) 632 _entity = null; 633 } 634 } 635 boolean foundInSessionCache = _entity != null; 636 637 if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) { 638 _entity = getEntityFromCache(session, _pk); 639 } 640 641 if(_entity == null) { 642 Long lttrsrcdt_lttrsrc_lettersourceid = rs.getLong(LTTRSRCDT_LTTRSRC_LETTERSOURCEID); 643 if(rs.wasNull()) 644 lttrsrcdt_lttrsrc_lettersourceid = null; 645 646 String lttrsrcdt_lettersourcename = rs.getString(LTTRSRCDT_LETTERSOURCENAME); 647 if(rs.wasNull()) 648 lttrsrcdt_lettersourcename = null; 649 650 Long lttrsrcdt_companypartyid = rs.getLong(LTTRSRCDT_COMPANYPARTYID); 651 if(rs.wasNull()) 652 lttrsrcdt_companypartyid = null; 653 654 Long lttrsrcdt_emailaddresspartycontactmechanismid = rs.getLong(LTTRSRCDT_EMAILADDRESSPARTYCONTACTMECHANISMID); 655 if(rs.wasNull()) 656 lttrsrcdt_emailaddresspartycontactmechanismid = null; 657 658 Long lttrsrcdt_postaladdresspartycontactmechanismid = rs.getLong(LTTRSRCDT_POSTALADDRESSPARTYCONTACTMECHANISMID); 659 if(rs.wasNull()) 660 lttrsrcdt_postaladdresspartycontactmechanismid = null; 661 662 Long lttrsrcdt_lettersourcepartycontactmechanismid = rs.getLong(LTTRSRCDT_LETTERSOURCEPARTYCONTACTMECHANISMID); 663 if(rs.wasNull()) 664 lttrsrcdt_lettersourcepartycontactmechanismid = null; 665 666 Boolean lttrsrcdt_isdefault = rs.getInt(LTTRSRCDT_ISDEFAULT) == 1; 667 if(rs.wasNull()) 668 lttrsrcdt_isdefault = null; 669 670 Integer lttrsrcdt_sortorder = rs.getInt(LTTRSRCDT_SORTORDER); 671 if(rs.wasNull()) 672 lttrsrcdt_sortorder = null; 673 674 Long lttrsrcdt_fromtime = rs.getLong(LTTRSRCDT_FROMTIME); 675 if(rs.wasNull()) 676 lttrsrcdt_fromtime = null; 677 678 Long lttrsrcdt_thrutime = rs.getLong(LTTRSRCDT_THRUTIME); 679 if(rs.wasNull()) 680 lttrsrcdt_thrutime = null; 681 682 LetterSourceDetailValue _value = new LetterSourceDetailValue(_pk, lttrsrcdt_lttrsrc_lettersourceid == null? null: new LetterSourcePK(lttrsrcdt_lttrsrc_lettersourceid), lttrsrcdt_lettersourcename, lttrsrcdt_companypartyid == null? null: new PartyPK(lttrsrcdt_companypartyid), lttrsrcdt_emailaddresspartycontactmechanismid == null? null: new PartyContactMechanismPK(lttrsrcdt_emailaddresspartycontactmechanismid), lttrsrcdt_postaladdresspartycontactmechanismid == null? null: new PartyContactMechanismPK(lttrsrcdt_postaladdresspartycontactmechanismid), lttrsrcdt_lettersourcepartycontactmechanismid == null? null: new PartyContactMechanismPK(lttrsrcdt_lettersourcepartycontactmechanismid), lttrsrcdt_isdefault, lttrsrcdt_sortorder, lttrsrcdt_fromtime, lttrsrcdt_thrutime); 683 _entity = new LetterSourceDetail(_value, entityPermission); 684 } 685 686 if(!foundInSessionCache) { 687 if(entityPermission.equals(EntityPermission.READ_ONLY)) { 688 session.putReadOnlyEntity(_pk, _entity); 689 session.getValueCache().put(_entity.getLetterSourceDetailValue()); 690 } else { 691 session.putReadWriteEntity(_pk, _entity); 692 } 693 } 694 } catch (SQLException se) { 695 throw new PersistenceDatabaseException(se); 696 } 697 698 return _entity; 699 } 700 701 public LetterSourceDetail create(Session session, LetterSource letterSource, String letterSourceName, Party companyParty, PartyContactMechanism emailAddressPartyContactMechanism, PartyContactMechanism postalAddressPartyContactMechanism, PartyContactMechanism letterSourcePartyContactMechanism, Boolean isDefault, Integer sortOrder, Long fromTime, Long thruTime) 702 throws PersistenceDatabaseException, PersistenceNotNullException { 703 return create(session, letterSource == null ? null : letterSource.getPrimaryKey(), letterSourceName, companyParty == null ? null : companyParty.getPrimaryKey(), emailAddressPartyContactMechanism == null ? null : emailAddressPartyContactMechanism.getPrimaryKey(), postalAddressPartyContactMechanism == null ? null : postalAddressPartyContactMechanism.getPrimaryKey(), letterSourcePartyContactMechanism == null ? null : letterSourcePartyContactMechanism.getPrimaryKey(), isDefault, sortOrder, fromTime, thruTime); 704 } 705 706 public LetterSourceDetail create(LetterSource letterSource, String letterSourceName, Party companyParty, PartyContactMechanism emailAddressPartyContactMechanism, PartyContactMechanism postalAddressPartyContactMechanism, PartyContactMechanism letterSourcePartyContactMechanism, Boolean isDefault, Integer sortOrder, Long fromTime, Long thruTime) 707 throws PersistenceDatabaseException, PersistenceNotNullException { 708 return create(ThreadSession.currentSession(), letterSource == null ? null : letterSource.getPrimaryKey(), letterSourceName, companyParty == null ? null : companyParty.getPrimaryKey(), emailAddressPartyContactMechanism == null ? null : emailAddressPartyContactMechanism.getPrimaryKey(), postalAddressPartyContactMechanism == null ? null : postalAddressPartyContactMechanism.getPrimaryKey(), letterSourcePartyContactMechanism == null ? null : letterSourcePartyContactMechanism.getPrimaryKey(), isDefault, sortOrder, fromTime, thruTime); 709 } 710 711 private void bindForCreate(PreparedStatement _ps, LetterSourceDetailValue _value) 712 throws SQLException { 713 _ps.setLong(1, _value.getEntityId()); 714 715 LetterSourcePK lttrsrcdt_lttrsrc_lettersourceid = _value.getLetterSourcePK(); 716 if(lttrsrcdt_lttrsrc_lettersourceid == null) 717 _ps.setNull(2, Types.BIGINT); 718 else 719 _ps.setLong(2, lttrsrcdt_lttrsrc_lettersourceid.getEntityId()); 720 721 String lttrsrcdt_lettersourcename = _value.getLetterSourceName(); 722 if(lttrsrcdt_lettersourcename == null) 723 _ps.setNull(3, Types.VARCHAR); 724 else 725 _ps.setString(3, lttrsrcdt_lettersourcename); 726 727 PartyPK lttrsrcdt_companypartyid = _value.getCompanyPartyPK(); 728 if(lttrsrcdt_companypartyid == null) 729 _ps.setNull(4, Types.BIGINT); 730 else 731 _ps.setLong(4, lttrsrcdt_companypartyid.getEntityId()); 732 733 PartyContactMechanismPK lttrsrcdt_emailaddresspartycontactmechanismid = _value.getEmailAddressPartyContactMechanismPK(); 734 if(lttrsrcdt_emailaddresspartycontactmechanismid == null) 735 _ps.setNull(5, Types.BIGINT); 736 else 737 _ps.setLong(5, lttrsrcdt_emailaddresspartycontactmechanismid.getEntityId()); 738 739 PartyContactMechanismPK lttrsrcdt_postaladdresspartycontactmechanismid = _value.getPostalAddressPartyContactMechanismPK(); 740 if(lttrsrcdt_postaladdresspartycontactmechanismid == null) 741 _ps.setNull(6, Types.BIGINT); 742 else 743 _ps.setLong(6, lttrsrcdt_postaladdresspartycontactmechanismid.getEntityId()); 744 745 PartyContactMechanismPK lttrsrcdt_lettersourcepartycontactmechanismid = _value.getLetterSourcePartyContactMechanismPK(); 746 if(lttrsrcdt_lettersourcepartycontactmechanismid == null) 747 _ps.setNull(7, Types.BIGINT); 748 else 749 _ps.setLong(7, lttrsrcdt_lettersourcepartycontactmechanismid.getEntityId()); 750 751 Boolean lttrsrcdt_isdefault = _value.getIsDefault(); 752 if(lttrsrcdt_isdefault == null) 753 _ps.setNull(8, Types.BIT); 754 else 755 _ps.setInt(8, lttrsrcdt_isdefault? 1: 0); 756 757 Integer lttrsrcdt_sortorder = _value.getSortOrder(); 758 if(lttrsrcdt_sortorder == null) 759 _ps.setNull(9, Types.INTEGER); 760 else 761 _ps.setInt(9, lttrsrcdt_sortorder); 762 763 Long lttrsrcdt_fromtime = _value.getFromTime(); 764 if(lttrsrcdt_fromtime == null) 765 _ps.setNull(10, Types.BIGINT); 766 else 767 _ps.setLong(10, lttrsrcdt_fromtime); 768 769 Long lttrsrcdt_thrutime = _value.getThruTime(); 770 if(lttrsrcdt_thrutime == null) 771 _ps.setNull(11, Types.BIGINT); 772 else 773 _ps.setLong(11, lttrsrcdt_thrutime); 774 775 } 776 777 public LetterSourceDetail create(Session session, LetterSourcePK letterSourcePK, String letterSourceName, PartyPK companyPartyPK, PartyContactMechanismPK emailAddressPartyContactMechanismPK, PartyContactMechanismPK postalAddressPartyContactMechanismPK, PartyContactMechanismPK letterSourcePartyContactMechanismPK, Boolean isDefault, Integer sortOrder, Long fromTime, Long thruTime) 778 throws PersistenceDatabaseException, PersistenceNotNullException { 779 LetterSourceDetailPK _pk = getNextPK(); 780 LetterSourceDetailValue _value = new LetterSourceDetailValue(_pk, letterSourcePK, letterSourceName, companyPartyPK, emailAddressPartyContactMechanismPK, postalAddressPartyContactMechanismPK, letterSourcePartyContactMechanismPK, isDefault, sortOrder, fromTime, thruTime); 781 782 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 783 784 try { 785 bindForCreate(_ps, _value); 786 787 if(PersistenceDebugFlags.CheckEntityInsertRowCount) { 788 int _count = _ps.executeUpdate(); 789 790 if(_count != 1) { 791 throw new PersistenceDatabaseUpdateException("insert failed, _count = " + _count); 792 } 793 } else { 794 _ps.executeUpdate(); 795 } 796 797 session.getValueCache().put(_value); 798 } catch (SQLException se) { 799 throw new PersistenceDatabaseException(se); 800 } 801 802 LetterSourceDetail _entity = new LetterSourceDetail(_value, EntityPermission.READ_ONLY); 803 session.putReadOnlyEntity(_pk, _entity); 804 805 return _entity; 806 } 807 808 public LetterSourceDetail create(LetterSourcePK letterSourcePK, String letterSourceName, PartyPK companyPartyPK, PartyContactMechanismPK emailAddressPartyContactMechanismPK, PartyContactMechanismPK postalAddressPartyContactMechanismPK, PartyContactMechanismPK letterSourcePartyContactMechanismPK, Boolean isDefault, Integer sortOrder, Long fromTime, Long thruTime) 809 throws PersistenceDatabaseException, PersistenceNotNullException { 810 return create(ThreadSession.currentSession(), letterSourcePK, letterSourceName, companyPartyPK, emailAddressPartyContactMechanismPK, postalAddressPartyContactMechanismPK, letterSourcePartyContactMechanismPK, isDefault, sortOrder, fromTime, thruTime); 811 } 812 813 public void create(Session session, Collection<LetterSourceDetailValue> _values) 814 throws PersistenceDatabaseException, PersistenceNotNullException { 815 int _size = _values.size(); 816 817 if(_size > 0) { 818 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 819 List<LetterSourceDetailValue> _cacheValues = new ArrayList<>(_size); 820 821 try { 822 for(LetterSourceDetailValue _value : _values) { 823 _value.setEntityId(entityIdGenerator.getNextEntityId()); 824 bindForCreate(_ps, _value); 825 826 _ps.addBatch(); 827 828 _cacheValues.add(_value); 829 } 830 831 if(PersistenceDebugFlags.CheckEntityInsertRowCount) { 832 int[] _counts = _ps.executeBatch(); 833 834 for(int _countOffset = 0 ; _countOffset < _size ; _countOffset++) { 835 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 836 throw new PersistenceDatabaseUpdateException("batch insert failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 837 } 838 } 839 } else { 840 _ps.executeBatch(); 841 } 842 843 _ps.clearBatch(); 844 } catch (SQLException se) { 845 throw new PersistenceDatabaseException(se); 846 } 847 848 _cacheValues.forEach((_cacheValue) -> { 849 LetterSourceDetail _cacheEntity = new LetterSourceDetail(_cacheValue, EntityPermission.READ_ONLY); 850 851 session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity); 852 }); 853 } 854 } 855 856 public void create(Collection<LetterSourceDetailValue> _values) 857 throws PersistenceDatabaseException, PersistenceNotNullException { 858 create(ThreadSession.currentSession(), _values); 859 } 860 861 private boolean bindForStore(PreparedStatement _ps, LetterSourceDetailValue _value) 862 throws SQLException { 863 boolean _hasBeenModified = _value.hasBeenModified(); 864 865 if(_hasBeenModified) { 866 LetterSourcePK lttrsrcdt_lttrsrc_lettersourceid = _value.getLetterSourcePK(); 867 if(lttrsrcdt_lttrsrc_lettersourceid == null) 868 _ps.setNull(1, Types.BIGINT); 869 else 870 _ps.setLong(1, lttrsrcdt_lttrsrc_lettersourceid.getEntityId()); 871 872 String lttrsrcdt_lettersourcename = _value.getLetterSourceName(); 873 if(lttrsrcdt_lettersourcename == null) 874 _ps.setNull(2, Types.VARCHAR); 875 else 876 _ps.setString(2, lttrsrcdt_lettersourcename); 877 878 PartyPK lttrsrcdt_companypartyid = _value.getCompanyPartyPK(); 879 if(lttrsrcdt_companypartyid == null) 880 _ps.setNull(3, Types.BIGINT); 881 else 882 _ps.setLong(3, lttrsrcdt_companypartyid.getEntityId()); 883 884 PartyContactMechanismPK lttrsrcdt_emailaddresspartycontactmechanismid = _value.getEmailAddressPartyContactMechanismPK(); 885 if(lttrsrcdt_emailaddresspartycontactmechanismid == null) 886 _ps.setNull(4, Types.BIGINT); 887 else 888 _ps.setLong(4, lttrsrcdt_emailaddresspartycontactmechanismid.getEntityId()); 889 890 PartyContactMechanismPK lttrsrcdt_postaladdresspartycontactmechanismid = _value.getPostalAddressPartyContactMechanismPK(); 891 if(lttrsrcdt_postaladdresspartycontactmechanismid == null) 892 _ps.setNull(5, Types.BIGINT); 893 else 894 _ps.setLong(5, lttrsrcdt_postaladdresspartycontactmechanismid.getEntityId()); 895 896 PartyContactMechanismPK lttrsrcdt_lettersourcepartycontactmechanismid = _value.getLetterSourcePartyContactMechanismPK(); 897 if(lttrsrcdt_lettersourcepartycontactmechanismid == null) 898 _ps.setNull(6, Types.BIGINT); 899 else 900 _ps.setLong(6, lttrsrcdt_lettersourcepartycontactmechanismid.getEntityId()); 901 902 Boolean lttrsrcdt_isdefault = _value.getIsDefault(); 903 if(lttrsrcdt_isdefault == null) 904 _ps.setNull(7, Types.BIT); 905 else 906 _ps.setInt(7, lttrsrcdt_isdefault? 1: 0); 907 908 Integer lttrsrcdt_sortorder = _value.getSortOrder(); 909 if(lttrsrcdt_sortorder == null) 910 _ps.setNull(8, Types.INTEGER); 911 else 912 _ps.setInt(8, lttrsrcdt_sortorder); 913 914 Long lttrsrcdt_fromtime = _value.getFromTime(); 915 if(lttrsrcdt_fromtime == null) 916 _ps.setNull(9, Types.BIGINT); 917 else 918 _ps.setLong(9, lttrsrcdt_fromtime); 919 920 Long lttrsrcdt_thrutime = _value.getThruTime(); 921 if(lttrsrcdt_thrutime == null) 922 _ps.setNull(10, Types.BIGINT); 923 else 924 _ps.setLong(10, lttrsrcdt_thrutime); 925 926 _ps.setLong(11, _value.getPrimaryKey().getEntityId()); 927 928 _value.clearHasBeenModified(); 929 } 930 931 return _hasBeenModified; 932 } 933 934 @Override 935 public void store(Session session, LetterSourceDetail entity) 936 throws PersistenceDatabaseException { 937 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 938 939 try { 940 LetterSourceDetailValue _value = entity.getLetterSourceDetailValue(); 941 942 if(bindForStore(_ps, _value)) { 943 if(PersistenceDebugFlags.CheckEntityUpdateRowCount) { 944 int _count = _ps.executeUpdate(); 945 946 if(_count != 1) { 947 throw new PersistenceDatabaseUpdateException("update failed, _count = " + _count); 948 } 949 } else { 950 _ps.executeUpdate(); 951 } 952 953 session.getValueCache().put(_value); 954 } 955 } catch (SQLException se) { 956 throw new PersistenceDatabaseException(se); 957 } 958 } 959 960 @Override 961 public void store(Session session, Collection<LetterSourceDetail> entities) 962 throws PersistenceDatabaseException { 963 if(entities.size() > 0) { 964 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 965 int _modifiedEntities = 0; 966 967 try { 968 for(LetterSourceDetail entity : entities) { 969 if(bindForStore(_ps, entity.getLetterSourceDetailValue())) { 970 _ps.addBatch(); 971 _modifiedEntities++; 972 } 973 } 974 975 if(_modifiedEntities != 0) { 976 if(PersistenceDebugFlags.CheckEntityUpdateRowCount) { 977 int[] _counts = _ps.executeBatch(); 978 979 for(int _countOffset = 0 ; _countOffset < _modifiedEntities ; _countOffset++) { 980 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 981 throw new PersistenceDatabaseUpdateException("batch update failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 982 } 983 } 984 } else { 985 _ps.executeBatch(); 986 } 987 988 _ps.clearBatch(); 989 990 entities.forEach((entity) -> { 991 session.getValueCache().put(entity.getLetterSourceDetailValue()); 992 }); 993 } 994 } catch (SQLException se) { 995 throw new PersistenceDatabaseException(se); 996 } 997 } 998 } 999 1000 @Override 1001 public void store(Collection<LetterSourceDetail> entities) 1002 throws PersistenceDatabaseException { 1003 store(ThreadSession.currentSession(), entities); 1004 } 1005 1006 @Override 1007 public void remove(Session session, LetterSourceDetail entity) 1008 throws PersistenceDatabaseException { 1009 remove(session, entity.getPrimaryKey()); 1010 } 1011 1012 @Override 1013 public void remove(Session session, LetterSourceDetailPK pk) 1014 throws PersistenceDatabaseException { 1015 PreparedStatement _ps = session.prepareStatement(SQL_DELETE); 1016 long _entityId = pk.getEntityId(); 1017 1018 try { 1019 _ps.setLong(1, _entityId); 1020 1021 if(PersistenceDebugFlags.CheckEntityDeleteRowCount) { 1022 int _count = _ps.executeUpdate(); 1023 1024 if(_count != 1) { 1025 throw new PersistenceDatabaseUpdateException("remove failed, _count = " + _count); 1026 } 1027 } else { 1028 _ps.executeUpdate(); 1029 } 1030 1031 session.getValueCache().remove(pk); 1032 } catch (SQLException se) { 1033 throw new PersistenceDatabaseException(se); 1034 } 1035 1036 session.removed(pk, false); 1037 } 1038 1039 @Override 1040 public void remove(Session session, Collection<LetterSourceDetailPK> pks) 1041 throws PersistenceDatabaseException { 1042 if(pks.size() > 0) { 1043 PreparedStatement _ps = session.prepareStatement(SQL_DELETE); 1044 int _modifiedEntities = 0; 1045 1046 try { 1047 for(LetterSourceDetailPK pk : pks) { 1048 long _entityId = pk.getEntityId(); 1049 1050 _ps.setLong(1, _entityId); 1051 1052 _ps.addBatch(); 1053 _modifiedEntities++; 1054 } 1055 1056 if(_modifiedEntities != 0) { 1057 if(PersistenceDebugFlags.CheckEntityDeleteRowCount) { 1058 int[] _counts = _ps.executeBatch(); 1059 1060 for(int _countOffset = 0 ; _countOffset < _modifiedEntities ; _countOffset++) { 1061 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 1062 throw new PersistenceDatabaseUpdateException("batch remove failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 1063 } 1064 } 1065 } else { 1066 _ps.executeBatch(); 1067 } 1068 1069 _ps.clearBatch(); 1070 1071 pks.forEach((pk) -> { 1072 session.getValueCache().remove(pk); 1073 }); 1074 } 1075 } catch (SQLException se) { 1076 throw new PersistenceDatabaseException(se); 1077 } 1078 1079 pks.forEach((pk) -> { 1080 session.removed(pk, true); 1081 }); 1082 } 1083 } 1084 1085 @Override 1086 public void remove(Collection<LetterSourceDetailPK> pks) 1087 throws PersistenceDatabaseException { 1088 remove(ThreadSession.currentSession(), pks); 1089 } 1090 1091 @Override 1092 public boolean validPK(Session session, LetterSourceDetailPK pk) 1093 throws PersistenceDatabaseException { 1094 boolean valid = false; 1095 PreparedStatement _ps = session.prepareStatement(SQL_VALID); 1096 ResultSet _rs = null; 1097 1098 try { 1099 _ps.setLong(1, pk.getEntityId()); 1100 1101 _rs = _ps.executeQuery(); 1102 if(_rs.next()) { 1103 long _count = _rs.getLong(1); 1104 if(_rs.wasNull()) 1105 _count = 0; 1106 1107 if(_count == 1) 1108 valid = true; 1109 } 1110 } catch (SQLException se) { 1111 throw new PersistenceDatabaseException(se); 1112 } finally { 1113 if(_rs != null) { 1114 try { 1115 _rs.close(); 1116 } catch (SQLException se) { 1117 // do nothing 1118 } 1119 } 1120 } 1121 1122 return valid; 1123 } 1124 1125}