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