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