return NULL;
}
-static struct ovsdb_error *
-ovsdb_atom_parse_uuid(struct uuid *uuid, const struct json *json,
- const struct ovsdb_symbol_table *symtab)
- WARN_UNUSED_RESULT;
-
-static struct ovsdb_error *
+static struct ovsdb_error * WARN_UNUSED_RESULT
ovsdb_atom_parse_uuid(struct uuid *uuid, const struct json *json,
- const struct ovsdb_symbol_table *symtab)
+ struct ovsdb_symbol_table *symtab)
{
struct ovsdb_error *error0;
const struct json *value;
error1 = unwrap_json(json, "named-uuid", JSON_STRING, &value);
if (!error1) {
const char *name = json_string(value);
- const struct ovsdb_symbol *symbol;
ovsdb_error_destroy(error0);
-
- symbol = ovsdb_symbol_table_get(symtab, name);
- if (symbol) {
- *uuid = symbol->uuid;
- return NULL;
- } else {
- return ovsdb_syntax_error(json, NULL,
- "unknown named-uuid \"%s\"", name);
- }
+ *uuid = ovsdb_symbol_table_insert(symtab, name)->uuid;
+ return NULL;
}
ovsdb_error_destroy(error1);
}
static struct ovsdb_error * WARN_UNUSED_RESULT
ovsdb_atom_from_json__(union ovsdb_atom *atom, enum ovsdb_atomic_type type,
const struct json *json,
- const struct ovsdb_symbol_table *symtab)
+ struct ovsdb_symbol_table *symtab)
{
switch (type) {
case OVSDB_TYPE_VOID:
ovsdb_atom_from_json(union ovsdb_atom *atom,
const struct ovsdb_base_type *base,
const struct json *json,
- const struct ovsdb_symbol_table *symtab)
+ struct ovsdb_symbol_table *symtab)
{
struct ovsdb_error *error;
ovsdb_datum_from_json(struct ovsdb_datum *datum,
const struct ovsdb_type *type,
const struct json *json,
- const struct ovsdb_symbol_table *symtab)
+ struct ovsdb_symbol_table *symtab)
{
struct ovsdb_error *error;
return shash_find_data(&symtab->sh, name);
}
-void
+struct ovsdb_symbol *
ovsdb_symbol_table_put(struct ovsdb_symbol_table *symtab, const char *name,
const struct uuid *uuid, bool used)
{
symbol->uuid = *uuid;
symbol->used = used;
shash_add(&symtab->sh, name, symbol);
+ return symbol;
+}
+
+struct ovsdb_symbol *
+ovsdb_symbol_table_insert(struct ovsdb_symbol_table *symtab,
+ const char *name)
+{
+ struct ovsdb_symbol *symbol;
+
+ symbol = ovsdb_symbol_table_get(symtab, name);
+ if (!symbol) {
+ struct uuid uuid;
+
+ uuid_generate(&uuid);
+ symbol = ovsdb_symbol_table_put(symtab, name, &uuid, false);
+ }
+ return symbol;
}
\f
/* Extracts a token from the beginning of 's' and returns a pointer just after
struct ovsdb_error *ovsdb_atom_from_json(union ovsdb_atom *,
const struct ovsdb_base_type *,
const struct json *,
- const struct ovsdb_symbol_table *)
+ struct ovsdb_symbol_table *)
WARN_UNUSED_RESULT;
struct json *ovsdb_atom_to_json(const union ovsdb_atom *,
enum ovsdb_atomic_type);
struct ovsdb_error *ovsdb_datum_from_json(struct ovsdb_datum *,
const struct ovsdb_type *,
const struct json *,
- const struct ovsdb_symbol_table *)
+ struct ovsdb_symbol_table *)
WARN_UNUSED_RESULT;
struct json *ovsdb_datum_to_json(const struct ovsdb_datum *,
const struct ovsdb_type *);
void ovsdb_symbol_table_destroy(struct ovsdb_symbol_table *);
struct ovsdb_symbol *ovsdb_symbol_table_get(const struct ovsdb_symbol_table *,
const char *name);
-void ovsdb_symbol_table_put(struct ovsdb_symbol_table *, const char *name,
- const struct uuid *, bool used);
+struct ovsdb_symbol *ovsdb_symbol_table_put(struct ovsdb_symbol_table *,
+ const char *name,
+ const struct uuid *, bool used);
+struct ovsdb_symbol *ovsdb_symbol_table_insert(struct ovsdb_symbol_table *,
+ const char *name);
\f
/* Tokenization
*
&column->type));
}
}
- if (row->new && !row->old) {
- struct json *op;
-
- op = json_object_create();
- json_array_add(operations, op);
- json_object_put_string(op, "op", "declare");
- json_object_put(op, "uuid-name",
- json_string_create_nocopy(
- uuid_name_from_uuid(&row->uuid)));
- }
}
/* Add updates. */
<named-uuid>
A 2-element JSON array that represents the UUID of a row inserted
- in a previous "insert" operation within the same transaction. The
- first element of the array must be the string "named-uuid" and the
- second element must be the string specified on this "insert"
- operation's "uuid-name" or on a preceding "insert" within the same
- transaction. For example, if this or a previous "insert"
- operation specified a "uuid-name" of "myrow", the following
- <named-uuid> represents the UUID created by that operation:
+ in an "insert" operation within the same transaction. The first
+ element of the array must be the string "named-uuid" and the
+ second element should be the string specified as the "uuid-name"
+ for an "insert" operation within the same transaction. For
+ example, if an "insert" operation within this transaction
+ specifies a "uuid-name" of "myrow", the following <named-uuid>
+ represents the UUID created by that operation:
["named-uuid", "myrow"]
- "uuid": 00000000-0000-0000-0000-000000000000
- If "uuid-name" is not supplied, the new row receives a new,
- randomly generated UUID.
+ The new row receives a new, randomly generated UUID.
- If "uuid-name" is supplied, then it is an error if <id> has
- previously appeared as the "uuid-name" in an "insert" operation.
-
- If "uuid-name" is supplied and its <id> previously appeared as the
- "uuid-name" in a "declare" operation, then the new row receives
- the UUID associated with that "uuid-name".
-
- If "uuid-name" is supplied and its <id> has not previously
- appeared as the "uuid-name" in a "declare" operation, then the new
- row also receives a new, randomly generated UUID. This UUID is
- also made available under that name to this operation and later
- operations within the same transaction.
+ If "uuid-name" is supplied, then it is an error if <id> is not
+ unique among the "uuid-name"s supplied on all the "insert"
+ operations within this transaction.
The UUID for the new row is returned as the "uuid" member of the
result.
"error": "duplicate uuid-name"
- The same "uuid-name" appeared on an earlier "insert" operation
+ The same "uuid-name" appears on another "insert" operation
within this transaction.
"error": "constraint violation"
This operation always fails with this error.
-declare
-.......
-
-Request object members:
-
- "op": "declare" required
- "uuid-name": <id> required
-
-Result object members:
-
- "uuid": <uuid>
-
-Semantics:
-
- Predeclares a UUID named <id> that may be referenced in later
- operations as ["named-uuid", <id>] or (at most once) in an
- "insert" operation as "uuid-name".
-
- It is an error if <id> has appeared as the "uuid-name" in a prior
- "insert" or "declare" operation within this transaction.
-
- The generated UUID is returned as the "uuid" member of the result.
-
-Errors:
-
- "error": "duplicate uuid-name"
-
- The same "uuid-name" appeared on an earlier "insert" or
- "declare" operation within this transaction.
-
comment
.......
static WARN_UNUSED_RESULT struct ovsdb_error *
ovsdb_clause_from_json(const struct ovsdb_table_schema *ts,
const struct json *json,
- const struct ovsdb_symbol_table *symtab,
+ struct ovsdb_symbol_table *symtab,
struct ovsdb_clause *clause)
{
const struct json_array *array;
struct ovsdb_error *
ovsdb_condition_from_json(const struct ovsdb_table_schema *ts,
const struct json *json,
- const struct ovsdb_symbol_table *symtab,
+ struct ovsdb_symbol_table *symtab,
struct ovsdb_condition *cnd)
{
const struct json_array *array = json_array(json);
-/* Copyright (c) 2009 Nicira Networks
+/* Copyright (c) 2009, 2010 Nicira Networks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
struct ovsdb_error *ovsdb_condition_from_json(
const struct ovsdb_table_schema *,
- const struct json *, const struct ovsdb_symbol_table *,
+ const struct json *, struct ovsdb_symbol_table *,
struct ovsdb_condition *) WARN_UNUSED_RESULT;
struct json *ovsdb_condition_to_json(const struct ovsdb_condition *);
void ovsdb_condition_destroy(struct ovsdb_condition *);
static ovsdb_operation_executor ovsdb_execute_wait;
static ovsdb_operation_executor ovsdb_execute_commit;
static ovsdb_operation_executor ovsdb_execute_abort;
-static ovsdb_operation_executor ovsdb_execute_declare;
static ovsdb_operation_executor ovsdb_execute_comment;
static ovsdb_operation_executor *
{ "wait", ovsdb_execute_wait },
{ "commit", ovsdb_execute_commit },
{ "abort", ovsdb_execute_abort },
- { "declare", ovsdb_execute_declare },
{ "comment", ovsdb_execute_comment },
};
static WARN_UNUSED_RESULT struct ovsdb_error *
parse_row(struct ovsdb_parser *parser, const char *member,
const struct ovsdb_table *table,
- const struct ovsdb_symbol_table *symtab,
+ struct ovsdb_symbol_table *symtab,
struct ovsdb_row **rowp, struct ovsdb_column_set *columns)
{
struct ovsdb_error *error;
if (uuid_name) {
struct ovsdb_symbol *symbol;
- symbol = ovsdb_symbol_table_get(x->symtab, json_string(uuid_name));
- if (symbol) {
- if (symbol->used) {
- return ovsdb_syntax_error(uuid_name, "duplicate uuid-name",
- "This \"uuid-name\" appeared on an "
- "earlier \"insert\" operation.");
- }
- row_uuid = symbol->uuid;
- symbol->used = true;
- } else {
- uuid_generate(&row_uuid);
- ovsdb_symbol_table_put(x->symtab, json_string(uuid_name),
- &row_uuid, true);
+ symbol = ovsdb_symbol_table_insert(x->symtab, json_string(uuid_name));
+ if (symbol->used) {
+ return ovsdb_syntax_error(uuid_name, "duplicate uuid-name",
+ "This \"uuid-name\" appeared on an "
+ "earlier \"insert\" operation.");
}
+ row_uuid = symbol->uuid;
+ symbol->used = true;
} else {
uuid_generate(&row_uuid);
}
return error;
}
-static struct ovsdb_error *
-ovsdb_execute_declare(struct ovsdb_execution *x, struct ovsdb_parser *parser,
- struct json *result)
-{
- const struct json *uuid_name;
- struct uuid uuid;
-
- uuid_name = ovsdb_parser_member(parser, "uuid-name", OP_ID);
- if (!uuid_name) {
- return NULL;
- }
-
- if (ovsdb_symbol_table_get(x->symtab, json_string(uuid_name))) {
- return ovsdb_syntax_error(uuid_name, "duplicate uuid-name",
- "This \"uuid-name\" appeared on an "
- "earlier \"declare\" or \"insert\" "
- "operation.");
- }
-
- uuid_generate(&uuid);
- ovsdb_symbol_table_put(x->symtab, json_string(uuid_name), &uuid, false);
- json_object_put(result, "uuid",
- json_array_create_2(
- json_string_create("uuid"),
- json_string_create_nocopy(
- xasprintf(UUID_FMT, UUID_ARGS(&uuid)))));
- return NULL;
-}
-
static struct ovsdb_error *
ovsdb_execute_comment(struct ovsdb_execution *x, struct ovsdb_parser *parser,
struct json *result UNUSED)
static WARN_UNUSED_RESULT struct ovsdb_error *
ovsdb_mutation_from_json(const struct ovsdb_table_schema *ts,
const struct json *json,
- const struct ovsdb_symbol_table *symtab,
+ struct ovsdb_symbol_table *symtab,
struct ovsdb_mutation *m)
{
const struct json_array *array;
struct ovsdb_error *
ovsdb_mutation_set_from_json(const struct ovsdb_table_schema *ts,
const struct json *json,
- const struct ovsdb_symbol_table *symtab,
+ struct ovsdb_symbol_table *symtab,
struct ovsdb_mutation_set *set)
{
const struct json_array *array = json_array(json);
-/* Copyright (c) 2009 Nicira Networks
+/* Copyright (c) 2009, 2010 Nicira Networks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
struct ovsdb_error *ovsdb_mutation_set_from_json(
const struct ovsdb_table_schema *,
- const struct json *, const struct ovsdb_symbol_table *,
+ const struct json *, struct ovsdb_symbol_table *,
struct ovsdb_mutation_set *) WARN_UNUSED_RESULT;
struct json *ovsdb_mutation_set_to_json(const struct ovsdb_mutation_set *);
void ovsdb_mutation_set_destroy(struct ovsdb_mutation_set *);
struct ovsdb_error *
ovsdb_row_from_json(struct ovsdb_row *row, const struct json *json,
- const struct ovsdb_symbol_table *symtab,
+ struct ovsdb_symbol_table *symtab,
struct ovsdb_column_set *included)
{
struct ovsdb_table_schema *schema = row->table->schema;
struct ovsdb_error *ovsdb_row_from_json(struct ovsdb_row *,
const struct json *,
- const struct ovsdb_symbol_table *,
+ struct ovsdb_symbol_table *,
struct ovsdb_column_set *included)
WARN_UNUSED_RESULT;
struct json *ovsdb_row_to_json(const struct ovsdb_row *,
OVSDB_CHECK_EXECUTION([referential integrity -- mutual references],
[CONSTRAINT_SCHEMA],
- [[[[{"op": "declare",
- "uuid-name": "row1"},
- {"op": "declare",
- "uuid-name": "row2"},
- {"op": "insert",
+ [[[[{"op": "insert",
"table": "a",
"row": {"a": 0,
"a2b": ["set", [["named-uuid", "row2"]]],
{"op": "delete",
"table": "b",
"where": [["b", "==", 1]]}]]]],
- [[[{"uuid":["uuid","<0>"]},{"uuid":["uuid","<1>"]},{"uuid":["uuid","<0>"]},{"uuid":["uuid","<1>"]}]
+ [[[{"uuid":["uuid","<0>"]},{"uuid":["uuid","<1>"]}]
[{"uuid":["uuid","<2>"]},{"details":"reference to nonexistent row <3>","error":"referential integrity violation"}]
[{"count":1},{"details":"cannot delete a row <0> because of 1 remaining reference(s)","error":"referential integrity violation"}]
[{"count":1},{"details":"cannot delete b row <1> because of 1 remaining reference(s)","error":"referential integrity violation"}]
"table": "link1",
"row": {"i": 0, "k": ["named-uuid", "self"]},
"uuid-name": "self"}]' \
- '[{"op": "declare",
- "uuid-name": "row1"},
- {"op": "declare",
- "uuid-name": "row2"},
- {"op": "insert",
+ '[{"op": "insert",
"table": "link1",
"row": {"i": 1, "k": ["named-uuid", "row2"]},
"uuid-name": "row1"},
[[000: empty
001: {"error":null,"result":[{"uuid":["uuid","<0>"]}]}
002: i=0 k=0 ka=[] l2= uuid=<0>
-003: {"error":null,"result":[{"uuid":["uuid","<1>"]},{"uuid":["uuid","<2>"]},{"uuid":["uuid","<1>"]},{"uuid":["uuid","<2>"]}]}
+003: {"error":null,"result":[{"uuid":["uuid","<1>"]},{"uuid":["uuid","<2>"]}]}
004: i=0 k=0 ka=[] l2= uuid=<0>
004: i=1 k=2 ka=[] l2= uuid=<1>
004: i=2 k=1 ka=[] l2= uuid=<2>