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