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