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