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