Exemplo n.º 1
0
        internal long GetLongId(string extendedSeriesId) {
            var sid = new SeriesId(extendedSeriesId);
            var seriesId = sid.TextId;
            var keyType = sid.KeyType;
            var valueType = sid.ValueType;

            var seriesIdRow = _connection.Query<SeriesId>("SELECT Id, TextId, UUID, KeyType, ValueType, Version from " + IdTableName + "" + " WHERE TextId = @TextId", new { TextId = seriesId }, buffered: false).SingleOrDefault();
            if (seriesIdRow != null) {
                if (seriesIdRow.KeyType != keyType || seriesIdRow.ValueType != valueType) {
                    throw new ArgumentException(
                        $"Wrong types for {seriesId}: expexting <{seriesIdRow.KeyType},{seriesIdRow.ValueType}> but requested <{keyType},{valueType}>");
                }
                return seriesIdRow.Id;
            }

            var setSql = @"INSERT INTO " + IdTableName + " (TextId, UUID, KeyType, ValueType, Version) VALUES ( @TextId, @UUID, @KeyType, @ValueType, @Version ); " + "SELECT Id from " + IdTableName + " WHERE TextId = @TextId;";
            var id = _connection.ExecuteScalar<long>(setSql, new {
                TextId = seriesId,
                UUID = seriesId.MD5Bytes(),
                KeyType = keyType,
                ValueType = valueType,
                Version = 0L
            });
            return id;
        }
Exemplo n.º 2
0
        internal long GetLastVersion(string extendedSeriesId) {
            var sid = new SeriesId(extendedSeriesId);
            var seriesId = sid.TextId;
            var keyType = sid.KeyType;
            var valueType = sid.ValueType;

            var seriesIdRow = _connection.Query<SeriesId>("SELECT Id, TextId, UUID, KeyType, ValueType, Version from " + IdTableName + "" + " WHERE TextId = @TextId", new { TextId = seriesId }, buffered: false).SingleOrDefault();
            if (seriesIdRow != null) {
                if (seriesIdRow.KeyType != keyType || seriesIdRow.ValueType != valueType)
                {
                    var message =
                        $"Wrong types for {seriesId}: expexting <{seriesIdRow.KeyType},{seriesIdRow.ValueType}> but requested <{keyType},{valueType}>";
                    Trace.TraceError(message);
                    throw new ArgumentException(message);
                }
                return seriesIdRow.Version;
            }
            return -1L;
        }