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