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