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