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