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