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