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