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