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