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