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