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