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