Closes a {@link MappedEntity}, logging a warning if an {@link Exception} is thrown.
<p>
It flushes before closing the {@link MappedEntity}.

@param mappedEntity The mapped entity to close.
@since 2.1.13
427505
private void closeMappedEntity(final MappedEntity mappedEntity) {

        try {
            // Flush first
            final PreparedStatement insert = mappedEntity.getInsert();
            final PreparedStatement insertReturning = mappedEntity.getInsertReturning();
            final PreparedStatement insertWithAutoInc = mappedEntity.getInsertWithAutoInc();

            insert.executeBatch();

            if (insertReturning != null) {
                insertReturning.executeBatch();
            }

            if (insertWithAutoInc != null) {
                insertWithAutoInc.executeBatch();
            }

        } catch (final SQLException e) {
            logger.debug(String.format("Failed to flush before closing mapped entity '%s'",
                    mappedEntity.getEntity().getName()), e);

        } finally {
            try {
                mappedEntity.close();
            } catch (final Exception e) {
                logger.warn("Could not close insert statements from mapped entity.", e);
            }
        }

    }
1233781
public synchronized void close() throws IOException {
        if(getStatus().equals(ConnectionStatus.CLOSED)){
            return ;
        }
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Closing client for session: 0x"
                      + getSessionId());
        }
        connectRun.set(false);

        try{
            clientSocket.cleanup();
        }catch(Exception e){
            LOGGER.warn("Close the WSDirectorySocket get error.", e);
        }

        try {
            setStatus(ConnectionStatus.CLOSED);
            sendCloseSession();
            closeSession();
            eventThread.queueEventOfDeath();
        } catch (ServiceException e) {
            LOGGER.warn("Execute the CloseSession Protocol failed when close", e);
        }
    }
275452
@Override
    public void delete(Object entity, Object pKey)
    {
        s = getStatelessSession();
        Transaction tx = null;
        tx = onBegin();
        s.delete(entity);
        onCommit(tx);

        EntityMetadata metadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, entity.getClass());
        MetamodelImpl metamodel = (MetamodelImpl) KunderaMetadataManager.getMetamodel(kunderaMetadata,
                metadata.getPersistenceUnit());
        if (!MetadataUtils.useSecondryIndex(getClientMetadata()))
        {
            getIndexManager().remove(metadata, entity, pKey);
        }
    }
1176379
@Override
  public void close() throws Exception {

    if (this.lookupClient != null) {
      this.lookupClient.close();
    }

    if (this.registryClient != null) {
      this.registryClient.close();
    }

    if (this.transport != null) {
      this.transport.close();
    }
  }
314358
@Override
    void closeNoTxEntityManager(JPANoTxEmInvocation noTxInvocation)
    {
        EntityManager em = noTxInvocation.ivEm;
        if (em != null && em.isOpen())
        {
            // Pooling of this entity manager will only be allowed if the getDelegate()
            // method has not been invoked on the entity manager.  If it has then we will
            // need to close it instead.
            if (noTxInvocation.ivAllowPooling) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                    Tr.debug(tc, "closeNoTxEntityManager is pooling noTx em: " + em);

                ivEntityManagerPool.putEntityManager(em);
            } else {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                    Tr.debug(tc, "closeNoTxEntityManager is closing noTx em: " + em);

                em.close();
            }
        }
    }
731638
@SuppressWarnings("unchecked")
	@Override
	public <E> int delete(final Class<? extends E> entityType, final Object... keys) {
		@SuppressWarnings("rawtypes")
		EntityHandler handler = this.getEntityHandler();
		if (!handler.getEntityType().isAssignableFrom(entityType)) {
			throw new IllegalArgumentException("Entity type not supported");
		}

		try {
			TableMetadata metadata = handler.getMetadata(this.transactionManager, entityType);
			TableMetadata.Column keyColumn = null;
			List<? extends TableMetadata.Column> keyColumns = metadata.getKeyColumns();
			if (keyColumns.size() == 1) {
				keyColumn = keyColumns.get(0);
			} else if (keyColumns.isEmpty()) {
				keyColumn = metadata.getColumns().get(0);
			} else {
				throw new IllegalArgumentException("Entity has multiple keys");
			}
			return delete(entityType).in(keyColumn.getCamelColumnName(), keys).count();
		} catch (SQLException e) {
			throw new EntitySqlRuntimeException(SqlKind.DELETE, e);
		}
	}
1346392
@Transactional
    public void delete(E entity) {
        if (entityManager.contains(entity)) {
            entityManager.remove(entity);
        } else {
            // could be a delete on a transient instance
            E entityRef = entityManager.getReference(type, entity.getId());

            if (entityRef != null) {
                entityManager.remove(entityRef);
            } else {
                log.warning("Attempt to delete an instance that is not present in the database: " + entity);
            }
        }
    }
815487
@Override @DefinedBy(Api.COMPILER)
    public void close() throws IOException {
        if (deferredCloseTimeout > 0) {
            deferredClose();
            return;
        }

        locations.close();
        for (Container container: containers.values()) {
            container.close();
        }
        containers.clear();
        contentCache.clear();
    }
907373
@Override
  public void close() throws IOException {
    try {
      try {
        if (this.failed && this.conn != null) {
          this.conn.rollback();
        }
      } finally {
        if (this.conn != null) {
          this.conn.close();
        }
      }
    } catch (SQLException e) {
      throw new RuntimeException(e);
    }
  }
126198
@Override
  public void close() throws SQLException {
    if (last != null) {
      last.close();
      if (!con.isClosed()) {
        if (!con.getAutoCommit()) {
          try {
            con.rollback();
          } catch (SQLException ignored) {
          }
        }
      }
    }
    try {
      con.close();
    } finally {
      con = null;
    }
  }
864247
@Override
	public void close() throws IOException {

		// enforce sequential close() calls
		synchronized (CLOSE_MUTEX) {
			this.recordWriter.close(new HadoopDummyReporter());

			if (this.outputCommitter.needsTaskCommit(this.context)) {
				this.outputCommitter.commitTask(this.context);
			}
		}
	}
15364
private void evictBiDiReferencedEntities(Entity entity) {
    Stream<EntityKey> backreffingEntities =
        getEntityType()
            .getMappedByAttributes()
            .flatMap(mappedByAttr -> Streams.stream(entity.getEntities(mappedByAttr.getName())))
            .map(EntityKey::create);
    Stream<EntityKey> manyToOneEntities =
        getEntityType()
            .getInversedByAttributes()
            .map(inversedByAttr -> entity.getEntity(inversedByAttr.getName()))
            .filter(Objects::nonNull)
            .map(EntityKey::create);

    l1Cache.evict(Stream.concat(backreffingEntities, manyToOneEntities));
  }
559263
@SuppressWarnings("unchecked")
	@Override
	public int delete(final Object entity) {
		@SuppressWarnings("rawtypes")
		EntityHandler handler = this.getEntityHandler();
		if (!handler.getEntityType().isInstance(entity)) {
			throw new IllegalArgumentException("Entity type not supported");
		}

		try {
			Class<?> type = entity.getClass();
			TableMetadata metadata = handler.getMetadata(this.transactionManager, type);
			SqlContext context = handler.createDeleteContext(this, metadata, type, true);
			context.setSqlKind(SqlKind.DELETE);
			handler.setDeleteParams(context, entity);
			return handler.doDelete(this, context, entity);
		} catch (SQLException e) {
			throw new EntitySqlRuntimeException(SqlKind.DELETE, e);
		}
	}
276319
public <T> void evict(T entity) {
        DocumentInfo documentInfo = documentsByEntity.get(entity);
        if (documentInfo != null) {
            documentsByEntity.remove(entity);
            documentsById.remove(documentInfo.getId());
        }

        deletedEntities.remove(entity);
        if (_countersByDocId != null) {
            _countersByDocId.remove(documentInfo.getId());
        }
    }
13886
@Override
  public void close() {
    if ( content != null ) {
      try {
        content.close();
      } catch (IOException e) {
        logger.error("Failed to close underlying InputStream",e);
        throw new MarkLogicIOException(e);
      }
    }
  }
702008
@SuppressWarnings("unchecked")
    public void close() {
        synchronized (documentStores) {
            DocumentStore ds = documentStores.remove(location);
            if (ds != null) {
                database.close();
                ((QueryImpl)query).close();
            }
            else {
                throw new IllegalStateException("DocumentStore "+location+" already closed");
            }
        }
        eventBus.post(new DocumentStoreClosed(databaseName));
    }
748688
@Override
    public synchronized void dropEntity(String entity) throws DatabaseEngineException {
        if (!containsEntity(entity)) {
            return;
        }

        dropEntity(entities.get(entity).getEntity());
    }