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