org.springframework.data.redis.connection.stream.ObjectRecord Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of org.apache.servicemix.bundles.spring-data-redis
Show all versions of org.apache.servicemix.bundles.spring-data-redis
This OSGi bundle wraps ${pkgArtifactId} ${pkgVersion} jar files.
/*
* Copyright 2018-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.stream;
import org.springframework.data.redis.connection.stream.StreamRecords.ObjectBackedRecord;
import org.springframework.data.redis.hash.HashMapper;
import org.springframework.util.Assert;
/**
* A {@link Record} within the stream mapped to a single object. This may be a simple type, such as {@link String} or a
* complex one.
*
* @param the type of the backing Object.
* @author Christoph Strobl
* @author Mark Paluch
* @see 2.2
*/
public interface ObjectRecord extends Record {
/**
* Creates a new {@link ObjectRecord} associated with the {@code stream} key and {@code value}.
*
* @param stream the stream key.
* @param value the value.
* @return the {@link ObjectRecord} holding the {@code stream} key and {@code value}.
*/
static ObjectRecord create(S stream, V value) {
Assert.notNull(stream, "Stream must not be null");
Assert.notNull(value, "Value must not be null");
return new ObjectBackedRecord<>(stream, RecordId.autoGenerate(), value);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStreamCommands.Record#withId(org.springframework.data.redis.connection.RedisStreamCommands.RecordId)
*/
@Override
ObjectRecord withId(RecordId id);
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStreamCommands.Record#withStreamKey(java.lang.Object)
*/
ObjectRecord withStreamKey(SK key);
/**
* Apply the given {@link HashMapper} to the backing value to create a new {@link MapRecord}. An already assigned
* {@link RecordId id} is carried over to the new instance.
*
* @param mapper must not be {@literal null}.
* @param the key type of the resulting {@link MapRecord}.
* @param the value type of the resulting {@link MapRecord}.
* @return new instance of {@link MapRecord}.
*/
default MapRecord toMapRecord(HashMapper mapper) {
return Record. of(mapper.toHash(getValue())).withId(getId()).withStreamKey(getStream());
}
}