當前位置: 首頁>>代碼示例>>Java>>正文


Java StreamId.isProjection方法代碼示例

本文整理匯總了Java中org.fuin.esc.api.StreamId.isProjection方法的典型用法代碼示例。如果您正苦於以下問題:Java StreamId.isProjection方法的具體用法?Java StreamId.isProjection怎麽用?Java StreamId.isProjection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.fuin.esc.api.StreamId的用法示例。


在下文中一共展示了StreamId.isProjection方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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";
}
 
開發者ID:fuinorg,項目名稱:event-store-commons,代碼行數:24,代碼來源:JpaUtils.java

示例2: 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";
}
 
開發者ID:fuinorg,項目名稱:event-store-commons,代碼行數:23,代碼來源:JpaUtils.java

示例3: 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();
}
 
開發者ID:fuinorg,項目名稱:event-store-commons,代碼行數:31,代碼來源:AbstractJpaEventStore.java

示例4: deleteStream

import org.fuin.esc.api.StreamId; //導入方法依賴的package包/類
@Override
public final void deleteStream(final StreamId streamId, final int expected, final boolean hardDelete) {

    Contract.requireArgNotNull("streamId", streamId);
    Contract.requireArgMin("expected", expected, ExpectedVersion.ANY.getNo());
    ensureOpen();

    if (streamId.isProjection()) {
        throw new StreamReadOnlyException(streamId);
    }
    
    final JpaStream stream = findAndLockJpaStream(streamId);
    if (stream == null) {
        // Stream never existed
        if (expected == ExpectedVersion.ANY.getNo()
                || expected == ExpectedVersion.NO_OR_EMPTY_STREAM.getNo()) {
            if (hardDelete) {
                final JpaStream newStream = streamFactory.createStream(streamId);
                newStream.delete(true);
                getEm().persist(newStream);
            }
            // Ignore
            return;
        }
        throw new WrongExpectedVersionException(streamId, expected, null);
    }
    if (stream.getState() == StreamState.SOFT_DELETED) {
        // Ignore
        return;
    }
    if (stream.getState() == StreamState.HARD_DELETED) {
        throw new StreamDeletedException(streamId);
    }
    // StreamState.ACTIVE
    if (expected != ExpectedVersion.ANY.getNo() && expected != stream.getVersion()) {
        throw new WrongExpectedVersionException(streamId, expected, stream.getVersion());
    }
    stream.delete(hardDelete);

}
 
開發者ID:fuinorg,項目名稱:event-store-commons,代碼行數:41,代碼來源:JpaEventStore.java

示例5: appendToStream

import org.fuin.esc.api.StreamId; //導入方法依賴的package包/類
@Override
public final int appendToStream(final StreamId streamId, final int expectedVersion,
        final List<CommonEvent> toAppend) {

    Contract.requireArgNotNull("streamId", streamId);
    Contract.requireArgMin("expectedVersion", expectedVersion, ExpectedVersion.ANY.getNo());
    Contract.requireArgNotNull("toAppend", toAppend);
    ensureOpen();

    if (streamId.isProjection()) {
        throw new StreamReadOnlyException(streamId);
    }
    
    JpaStream stream = findAndLockJpaStream(streamId);
    if (stream == null) {
        LOG.debug("Stream '{}' not found, creating it", streamId);
        stream = streamFactory.createStream(streamId);
        getEm().persist(stream);
    } else {
        LOG.debug("Stream '{}' found, reading it", streamId);
        if (stream.isDeleted()) {
            throw new StreamDeletedException(streamId);
        }
        if ((expectedVersion != ANY.getNo()) && (stream.getVersion() != expectedVersion)) {
            // Test for idempotency
            final StreamEventsSlice slice = readEventsBackward(streamId, stream.getVersion(),
                    toAppend.size());
            final List<CommonEvent> events = slice.getEvents();
            if (EscSpiUtils.eventsEqual(events, toAppend)) {
                return stream.getVersion();
            }
            throw new WrongExpectedVersionException(streamId, expectedVersion, stream.getVersion());
        }
    }
    for (int i = 0; i < toAppend.size(); i++) {
        final JpaEvent eventEntry = asJpaEvent(toAppend.get(i));
        getEm().persist(eventEntry);
        final JpaStreamEvent streamEvent = stream.createEvent(streamId, eventEntry);
        getEm().persist(streamEvent);
    }
    return stream.getVersion();

}
 
開發者ID:fuinorg,項目名稱:event-store-commons,代碼行數:44,代碼來源:JpaEventStore.java

示例6: readEventsForward

import org.fuin.esc.api.StreamId; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public final StreamEventsSlice readEventsForward(final StreamId streamId, final int start,
        final int count) {

    Contract.requireArgNotNull("streamId", streamId);
    Contract.requireArgMin("start", start, 0);
    Contract.requireArgMin("count", count, 1);
    ensureOpen();
    verifyStreamEntityExists(streamId);

    if (streamId.isProjection()) {
        final JpaProjection projection = em.find(JpaProjection.class, streamEntityName(streamId));
        if (projection == null) {
            throw new StreamNotFoundException(streamId);
        }
        if (!projection.isEnabled()) {
            // The projection does exist, but is not ready yet
            return new StreamEventsSlice(start, new ArrayList<CommonEvent>(), start, true);
        }
    } else {
        final JpaStream stream = findStream(streamId);
        if (stream.getState() == StreamState.HARD_DELETED) {
            throw new StreamDeletedException(streamId);
        }
    }

    // Prepare SQL
    final NativeSqlCondition greaterOrEqualEventNumber = new NativeSqlCondition(JPA_STREAM_EVENT_PREFIX,
            JpaStreamEvent.COLUMN_EVENT_NUMBER, ">=", start);
    final List<NativeSqlCondition> conditions = createNativeSqlConditions(streamId,
            greaterOrEqualEventNumber);
    final String sql = createNativeSqlEventSelect(streamId, conditions) + createOrderBy(streamId, true);
    LOG.debug(sql);
    final Query query = em.createNativeQuery(sql, JpaEvent.class);
    setNativeSqlParameters(query, conditions);
    query.setMaxResults(count);
    final List<JpaEvent> resultList = query.getResultList();

    // Return result
    final List<CommonEvent> events = asCommonEvents(resultList);
    final int fromEventNumber = start;
    final int nextEventNumber = (start + events.size());
    final boolean endOfStream = (events.size() < count);

    return new StreamEventsSlice(fromEventNumber, events, nextEventNumber, endOfStream);

}
 
開發者ID:fuinorg,項目名稱:event-store-commons,代碼行數:49,代碼來源:AbstractJpaEventStore.java

示例7: readEventsBackward

import org.fuin.esc.api.StreamId; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public final StreamEventsSlice readEventsBackward(final StreamId streamId, final int start,
        final int count) {

    Contract.requireArgNotNull("streamId", streamId);
    Contract.requireArgMin("start", start, 0);
    Contract.requireArgMin("count", count, 1);
    ensureOpen();
    verifyStreamEntityExists(streamId);

    if (streamId.isProjection()) {
        final JpaProjection projection = em.find(JpaProjection.class, streamEntityName(streamId));
        if (projection == null) {
            throw new StreamNotFoundException(streamId);
        }
        if (!projection.isEnabled()) {
            // The projection does exist, but is not ready yet
            return new StreamEventsSlice(start, new ArrayList<CommonEvent>(), start, true);
        }
    } else {
        final JpaStream stream = findStream(streamId);
        if (stream.getState() == StreamState.HARD_DELETED) {
            throw new StreamDeletedException(streamId);
        }
    }

    // Prepare SQL
    final NativeSqlCondition greaterOrEqualEventNumber = new NativeSqlCondition(JPA_STREAM_EVENT_PREFIX,
            JpaStreamEvent.COLUMN_EVENT_NUMBER, "<=", start);
    final List<NativeSqlCondition> conditions = createNativeSqlConditions(streamId,
            greaterOrEqualEventNumber);
    final String sql = createNativeSqlEventSelect(streamId, conditions) + createOrderBy(streamId, false);
    LOG.debug(sql);
    final Query query = em.createNativeQuery(sql, JpaEvent.class);
    setNativeSqlParameters(query, conditions);
    query.setMaxResults(count);
    final List<JpaEvent> resultList = query.getResultList();

    // Return result
    final List<CommonEvent> events = asCommonEvents(resultList);
    final int fromEventNumber = start;
    int nextEventNumber = start - resultList.size();
    if (nextEventNumber < 0) {
        nextEventNumber = 0;
    }
    final boolean endOfStream = (start - count) < 0;

    return new StreamEventsSlice(fromEventNumber, events, nextEventNumber, endOfStream);

}
 
開發者ID:fuinorg,項目名稱:event-store-commons,代碼行數:52,代碼來源:AbstractJpaEventStore.java

示例8: deleteStream

import org.fuin.esc.api.StreamId; //導入方法依賴的package包/類
@Override
public final void deleteStream(final StreamId streamId, final int expected,
        final boolean hardDelete) {

    Contract.requireArgNotNull("streamId", streamId);
    ensureOpen();

    if (streamId.isProjection()) {
        throw new StreamReadOnlyException(streamId);
    }
    if (streamId == StreamId.ALL) {
        throw new IllegalArgumentException(
                "It's not possible to delete the 'all' stream");
    }

    final InternalStream stream = streams.get(streamId);
    if (stream == null) {
        // Stream never existed
        if (expected == ExpectedVersion.ANY.getNo()
                || expected == ExpectedVersion.NO_OR_EMPTY_STREAM.getNo()) {
            if (hardDelete) {
                final InternalStream hds = new InternalStream();
                hds.delete(hardDelete);
                streams.put(streamId, hds);
            }
            // Ignore
            return;
        }
        throw new WrongExpectedVersionException(streamId, expected, null);
    }
    if (stream.getState() == StreamState.SOFT_DELETED) {
        // Ignore
        return;
    }
    if (stream.getState() == StreamState.HARD_DELETED) {
        throw new StreamDeletedException(streamId);
    }
    // StreamState.ACTIVE
    if (expected != ExpectedVersion.ANY.getNo()
            && expected != stream.getVersion()) {
        throw new WrongExpectedVersionException(streamId, expected,
                stream.getVersion());
    }
    stream.delete(hardDelete);

}
 
開發者ID:fuinorg,項目名稱:event-store-commons,代碼行數:47,代碼來源:InMemoryEventStore.java

示例9: appendToStream

import org.fuin.esc.api.StreamId; //導入方法依賴的package包/類
@Override
public final int appendToStream(final StreamId streamId,
        final int expectedVersion, final List<CommonEvent> toAppend) {

    Contract.requireArgNotNull("streamId", streamId);
    Contract.requireArgNotNull("toAppend", toAppend);
    ensureOpen();

    if (streamId.isProjection()) {
        throw new StreamReadOnlyException(streamId);
    }

    InternalStream stream = streams.get(streamId);
    if (stream == null) {
        stream = new InternalStream();
        streams.put(streamId, stream);
    }
    if (stream.getState() == StreamState.HARD_DELETED) {
        throw new StreamDeletedException(streamId);
    }
    if (stream.getState() == StreamState.SOFT_DELETED) {
        stream.undelete();
    }
    if (expectedVersion != ExpectedVersion.ANY.getNo()
            && expectedVersion != stream.getVersion()) {
        // Test for idempotency
        final StreamEventsSlice slice = readEventsBackward(streamId,
                stream.getVersion(), toAppend.size());
        final List<CommonEvent> events = slice.getEvents();
        if (EscSpiUtils.eventsEqual(events, toAppend)) {
            return stream.getVersion();
        }
        throw new WrongExpectedVersionException(streamId, expectedVersion,
                stream.getVersion());
    }

    all.addAll(toAppend);
    stream.addAll(toAppend);

    notifyListeners(streamId, toAppend, 0);

    return stream.getVersion();

}
 
開發者ID:fuinorg,項目名稱:event-store-commons,代碼行數:45,代碼來源:InMemoryEventStore.java

示例10: deleteStream

import org.fuin.esc.api.StreamId; //導入方法依賴的package包/類
@Override
public void deleteStream(final StreamId streamId, final int expectedVersion,
        final boolean hardDelete) throws StreamNotFoundException,
        StreamDeletedException, WrongExpectedVersionException {

    Contract.requireArgNotNull("streamId", streamId);
    Contract.requireArgMin("expectedVersion", expectedVersion,
            ExpectedVersion.ANY.getNo());
    ensureOpen();

    if (streamId.isProjection()) {
        throw new StreamReadOnlyException(streamId);
    }

    final String msg = "deleteStream(" + streamId + ", " + expectedVersion
            + ", " + hardDelete + ")";
    try {
        final URI uri = new URIBuilder(url.toURI())
                .setPath("/streams/" + streamId).build();
        final HttpDelete delete = new HttpDelete(uri);
        try {
            delete.setHeader("ES-HardDelete", "" + hardDelete);
            delete.setHeader("ES-ExpectedVersion", "" + expectedVersion);
            LOG.debug(msg + " DELETE: {}", delete);

            final Future<HttpResponse> future = httpclient.execute(delete,
                    null);
            final HttpResponse response = future.get();
            final StatusLine statusLine = response.getStatusLine();
            if (statusLine.getStatusCode() == 204) {
                // Stream deleted
                LOG.debug(msg + " RESPONSE: {}", response);
                return;
            }
            if (statusLine.getStatusCode() == 400) {
                // TODO Add expected version instead of any version if ES
                // returns this in header
                LOG.debug(msg + " RESPONSE: {}", response);
                throw new WrongExpectedVersionException(streamId,
                        expectedVersion, null);
            }
            if (statusLine.getStatusCode() == 410) {
                // 410 GONE - Stream was hard deleted
                LOG.debug(msg + " RESPONSE: {}", response);
                throw new StreamDeletedException(streamId);
            }

            LOG.debug(msg + " RESPONSE: {}", response);
            throw new RuntimeException(
                    msg + " [Status=" + statusLine + "]");

        } finally {
            delete.reset();
        }

    } catch (final URISyntaxException | ExecutionException
            | InterruptedException ex) {
        throw new RuntimeException(msg, ex);
    }

}
 
開發者ID:fuinorg,項目名稱:event-store-commons,代碼行數:62,代碼來源:ESHttpEventStore.java

示例11: requireProjection

import org.fuin.esc.api.StreamId; //導入方法依賴的package包/類
private static void requireProjection(final StreamId projectionId) {
    if (!projectionId.isProjection()) {
        throw new ConstraintViolationException(
                "The stream identifier is not a projection id");
    }
}
 
開發者ID:fuinorg,項目名稱:event-store-commons,代碼行數:7,代碼來源:ESHttpEventStore.java


注:本文中的org.fuin.esc.api.StreamId.isProjection方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。