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