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