本文整理匯總了Java中org.fuin.esc.api.StreamId類的典型用法代碼示例。如果您正苦於以下問題:Java StreamId類的具體用法?Java StreamId怎麽用?Java StreamId使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
StreamId類屬於org.fuin.esc.api包,在下文中一共展示了StreamId類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: findAndLockJpaStream
import org.fuin.esc.api.StreamId; //導入依賴的package包/類
private JpaStream findAndLockJpaStream(final StreamId streamId) {
if (!streamEntityExists(streamId)) {
return null;
}
final String sql = createJpqlStreamSelect(streamId);
LOG.debug("{}", sql);
final TypedQuery<JpaStream> query = getEm().createQuery(sql, JpaStream.class);
setJpqlParameters(query, streamId);
query.setLockMode(LockModeType.PESSIMISTIC_WRITE);
final List<JpaStream> streams = query.getResultList();
if (streams.size() == 0) {
return null;
}
if (streams.size() == 1) {
return streams.get(0);
}
throw new IllegalStateException("Select returned more than one stream: " + streams.size() + " ["
+ sql + "]");
}
示例2: streamEntityName
import org.fuin.esc.api.StreamId; //導入依賴的package包/類
/**
* Returns the name of the stream entity for a given stream.
*
* @param streamId
* Identifier of the stream to return a stream entity name for.
*
* @return Name of the entity (simple class name).
*/
public static String streamEntityName(final StreamId streamId) {
// User defined ID
if (streamId instanceof JpaStreamId) {
final JpaStreamId jpaId = (JpaStreamId) streamId;
return jpaId.getEntityName();
}
// Default ID
if (streamId.isProjection()) {
return streamId.getName();
}
if (streamId.getParameters().size() == 0) {
return NoParamsStream.class.getSimpleName();
}
return streamId.getName() + "Stream";
}
示例3: nativeEventsTableName
import org.fuin.esc.api.StreamId; //導入依賴的package包/類
/**
* Returns a native database events table name.
*
* @param streamId Unique stream identifier.
*
* @return Name that is configured in the {@link javax.persistence.Table} JPA annotation.
*/
public static String nativeEventsTableName(final StreamId streamId) {
// User defined ID
if (streamId instanceof JpaStreamId) {
final JpaStreamId jpaId = (JpaStreamId) streamId;
return jpaId.getNativeTableName();
}
// Default ID
if (streamId.isProjection()) {
return camel2Underscore(streamId.getName());
}
if (streamId.getParameters().size() == 0) {
return NoParamsEvent.NO_PARAMS_EVENTS_TABLE;
}
return camel2Underscore(streamId.getName()) + "_events";
}
示例4: readEvent
import org.fuin.esc.api.StreamId; //導入依賴的package包/類
@Override
public final CommonEvent readEvent(final StreamId streamId, final int eventNumber) {
Contract.requireArgNotNull("streamId", streamId);
Contract.requireArgMin("eventNumber", eventNumber, 0);
ensureOpen();
verifyStreamEntityExists(streamId);
final NativeSqlCondition eventNo = new NativeSqlCondition(JpaStreamEvent.COLUMN_EVENT_NUMBER, "=",
eventNumber);
final List<NativeSqlCondition> conditions = createNativeSqlConditions(streamId, eventNo);
final String nativeSql = createNativeSqlEventSelect(streamId, conditions);
final Query query = em.createNativeQuery(nativeSql, JpaEvent.class);
setNativeSqlParameters(query, conditions);
try {
final JpaEvent result = (JpaEvent) query.getSingleResult();
return asCommonEvent(result);
} catch (final NoResultException ex) {
throw new EventNotFoundException(streamId, eventNumber);
}
}
示例5: streamExists
import org.fuin.esc.api.StreamId; //導入依賴的package包/類
@Override
public final boolean streamExists(final StreamId streamId) {
Contract.requireArgNotNull("streamId", streamId);
ensureOpen();
if (!streamEntityExists(streamId)) {
return false;
}
final String sql = createJpqlStreamSelect(streamId);
final TypedQuery<JpaStream> query = getEm().createQuery(sql, JpaStream.class);
setJpqlParameters(query, streamId);
final List<JpaStream> streams = query.getResultList();
if (streams.size() == 0) {
return false;
}
if (streams.size() == 1) {
final JpaStream stream = streams.get(0);
return (stream.getState() == StreamState.ACTIVE);
}
throw new IllegalStateException(
"Select returned more than one stream: " + streams.size() + " [" + sql + "]");
}
示例6: createJpqlStreamSelect
import org.fuin.esc.api.StreamId; //導入依賴的package包/類
/**
* Creates the JPQL to select the stream itself.
*
* @param streamId
* Unique stream identifier.
*
* @return JPQL that selects the stream with the given identifier.
*/
protected final String createJpqlStreamSelect(final StreamId streamId) {
if (streamId.isProjection()) {
throw new IllegalArgumentException("Projections do not have a stream table : " + streamId);
}
final List<KeyValue> params = new ArrayList<>(streamId.getParameters());
if (params.size() == 0) {
// NoParamsStream
params.add(new KeyValue("streamName", streamId.getName()));
}
final StringBuilder sb = new StringBuilder("SELECT t FROM " + streamEntityName(streamId) + " t");
sb.append(" WHERE ");
for (int i = 0; i < params.size(); i++) {
final KeyValue param = params.get(i);
if (i > 0) {
sb.append(" AND ");
}
sb.append("t." + param.getKey() + "=:" + param.getKey());
}
return sb.toString();
}
示例7: createNativeSqlConditions
import org.fuin.esc.api.StreamId; //導入依賴的package包/類
private List<NativeSqlCondition> createNativeSqlConditions(final StreamId streamId,
final NativeSqlCondition... additionalConditions) {
final List<NativeSqlCondition> conditions;
if (additionalConditions == null) {
conditions = new ArrayList<>();
} else {
conditions = new ArrayList<>(Arrays.asList(additionalConditions));
}
if (streamId.getParameters().size() == 0) {
conditions.add(new NativeSqlCondition(JPA_STREAM_EVENT_PREFIX, NoParamsEvent.COLUMN_STREAM_NAME,
"=", streamId.getName()));
} else {
for (final KeyValue kv : streamId.getParameters()) {
conditions.add(new NativeSqlCondition(camel2Underscore(kv.getKey()), "=", kv.getValue()));
}
}
return conditions;
}
示例8: testCreate
import org.fuin.esc.api.StreamId; //導入依賴的package包/類
@Test
public void testCreate() {
// PREPARE
final StreamId streamId = new SimpleStreamId("AnyName");
// TEST
final NoParamsStream testee = new NoParamsStream(streamId);
// VERIFY
assertThat(testee.toString()).isEqualTo(streamId.toString());
assertThat(testee.getState()).isEqualTo(StreamState.ACTIVE);
assertThat(testee.getVersion()).isEqualTo(-1);
assertThat(testee.isDeleted()).isFalse();
}
示例9: streamExists
import org.fuin.esc.api.StreamId; //導入依賴的package包/類
@Override
public final boolean streamExists(final StreamId streamId) {
Contract.requireArgNotNull("streamId", streamId);
ensureOpen();
try {
final com.github.msemys.esjc.StreamEventsSlice slice = es
.readStreamEventsForward(streamId.asString(), 0, 1, false)
.get();
if (SliceReadStatus.StreamDeleted == slice.status) {
return false;
}
if (SliceReadStatus.StreamNotFound == slice.status) {
return false;
}
return true;
} catch (InterruptedException | ExecutionException ex) {
throw new RuntimeException("Error waiting for read forward result",
ex);
}
}
示例10: testCreateEvent
import org.fuin.esc.api.StreamId; //導入依賴的package包/類
@Test
public void testCreateEvent() {
// PREPARE
final StreamId streamId = new SimpleStreamId("AnyName");
final NoParamsStream testee = new NoParamsStream(streamId);
final JpaEvent eventEntry = new JpaEvent();
final int version = testee.getVersion();
// TEST
final JpaStreamEvent result = testee.createEvent(streamId, eventEntry);
// VERIFY
assertThat(result).isNotNull();
assertThat(result.getEvent()).isSameAs(eventEntry);
assertThat(testee.getVersion()).isEqualTo(version + 1);
}
示例11: readEvent
import org.fuin.esc.api.StreamId; //導入依賴的package包/類
@Override
public final CommonEvent readEvent(final StreamId streamId,
final int eventNumber) {
Contract.requireArgNotNull("streamId", streamId);
Contract.requireArgMin("eventNumber", eventNumber, 0);
ensureOpen();
final List<CommonEvent> events = getStream(streamId,
ExpectedVersion.ANY.getNo()).getEvents();
if (events.size() - 1 < eventNumber) {
throw new EventNotFoundException(streamId, eventNumber);
}
return events.get(eventNumber);
}
示例12: getStream
import org.fuin.esc.api.StreamId; //導入依賴的package包/類
private InternalStream getStream(final StreamId streamId,
final int expected) {
final InternalStream stream = streams.get(streamId);
if (stream == null) {
throw new StreamNotFoundException(streamId);
}
if (stream.getState() == StreamState.SOFT_DELETED) {
throw new StreamNotFoundException(streamId);
}
if (stream.getState() == StreamState.HARD_DELETED) {
throw new StreamDeletedException(streamId);
}
if (expected != ExpectedVersion.ANY.getNo()
&& expected != stream.getVersion()) {
throw new WrongExpectedVersionException(streamId, expected,
stream.getVersion());
}
return stream;
}
示例13: testAppendToStreamArray
import org.fuin.esc.api.StreamId; //導入依賴的package包/類
@Test
public void testAppendToStreamArray() {
// PREPARE
final StreamId streamId = new SimpleStreamId("MyStream");
final CommonEvent eventOne = event("One");
final CommonEvent eventTwo = event("Two");
// TEST
testee.appendToStream(streamId, ExpectedVersion.NO_OR_EMPTY_STREAM.getNo(), eventOne, eventTwo);
// VERIFY
final StreamEventsSlice slice = testee.readEventsForward(StreamId.ALL, 0, 2);
assertThat(slice.getEvents()).contains(eventOne, eventTwo);
assertThat(slice.getFromEventNumber()).isEqualTo(0);
assertThat(slice.getNextEventNumber()).isEqualTo(2);
}
示例14: testSubscribeToStreamNewEvents
import org.fuin.esc.api.StreamId; //導入依賴的package包/類
@Test
public void testSubscribeToStreamNewEvents() {
// PREPARE
final StreamId streamId = new SimpleStreamId("MyStream");
final CommonEvent eventOne = event("One");
final CommonEvent eventTwo = event("Two");
final CommonEvent eventThree = event("Three");
testee.appendToStream(streamId, eventOne);
final List<CommonEvent> result = new CopyOnWriteArrayList<>();
// TEST
testee.subscribeToStream(streamId, EscApiUtils.SUBSCRIBE_TO_NEW_EVENTS, (subscription, event) -> {
result.add(event);
}, (subscription, exception) -> {
// Not used
});
testee.appendToStream(streamId, eventTwo, eventThree);
waitForResult(result, 1);
// VERIFY
assertThat(result).containsExactly(eventTwo, eventThree);
}
示例15: testSubscribeToStreamFromFirst
import org.fuin.esc.api.StreamId; //導入依賴的package包/類
@Test
public void testSubscribeToStreamFromFirst() {
// PREPARE
final StreamId streamId = new SimpleStreamId("MyStream");
final CommonEvent eventOne = event("Eins");
final CommonEvent eventTwo = event("Zwei");
final CommonEvent eventThree = event("Drei");
testee.appendToStream(streamId, eventOne, eventTwo, eventThree);
final List<CommonEvent> result = new CopyOnWriteArrayList<>();
// TEST
testee.subscribeToStream(streamId, 0, (subscription, event) -> {
result.add(event);
}, (subscription, exception) -> {
// Not used
});
waitForResult(result, 3);
// VERIFY
assertThat(result).containsExactly(eventOne, eventTwo, eventThree);
}