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