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