/** * Returns a mutation that will delete the row with primary key {@code key}. Exactly equivalent to * {@code delete(table, KeySet.singleKey(key))}. */ public static Mutation delete(String table, Key key) { return delete(table, KeySet.singleKey(key)); }
@Override public Status delete(String table, String key) { try { dbClient.writeAtLeastOnce(Arrays.asList(Mutation.delete(table, Key.of(key)))); } catch (Exception e) { LOGGER.log(Level.INFO, "delete()", e); return Status.ERROR; } return Status.OK; }
@Test public void toProtoCoalescingDelete() { List<Mutation> mutations = Arrays.asList( Mutation.delete("T", Key.of("k1")), Mutation.delete("T", Key.of("k2")), Mutation.delete("T", KeySet.range(KeyRange.closedOpen(Key.of("ka"), Key.of("kb")))), Mutation.delete("T", KeySet.range(KeyRange.closedClosed(Key.of("kc"), Key.of("kd"))))); List<com.google.spanner.v1.Mutation> proto = new ArrayList<>(); Mutation.toProto(mutations, proto); assertThat(proto.size()).isEqualTo(1); MatcherAssert.assertThat( proto.get(0), matchesProto( "delete {" + " table: 'T'" + " key_set {" + " keys { values { string_value: 'k1' } }" + " keys { values { string_value: 'k2' } }" + " ranges { start_closed { values { string_value: 'ka' } } " + " end_open { values { string_value: 'kb' } } }" + " ranges { start_closed { values { string_value: 'kc' } } " + " end_closed { values { string_value: 'kd' } } }" + " }" + "} ")); }
@Test public void delete() { KeySet keySet = KeySet.singleKey(Key.of("k1")); Mutation m = Mutation.delete("T1", keySet); assertThat(m.getOperation()).isEqualTo(Mutation.Op.DELETE); assertThat(m.getKeySet()).isEqualTo(keySet); assertThat(m.toString()).isEqualTo("delete(T1{[k1]})"); }
Mutation.newInsertOrUpdateBuilder("T").set("C").to("V").build(), Mutation.newReplaceBuilder("T").set("C").to("V").build(), Mutation.delete("T", KeySet.singleKey(Key.of("k"))));
Mutation.delete( "test", Key.of( Timestamp.ofTimeSecondsAndNanos(1, 2), Date.fromYearMonthDay(2017, 04, 17)))); reserializeAndAssert(Mutation.delete("test", KeySet.all())); reserializeAndAssert( Mutation.delete( "test", KeySet.newBuilder() .build())); reserializeAndAssert( Mutation.delete( "test", KeySet.newBuilder() .build())); reserializeAndAssert( Mutation.delete( "test", KeySet.newBuilder() .build())); reserializeAndAssert( Mutation.delete( "test", KeySet.newBuilder()
static void deleteExampleData(DatabaseClient dbClient) { List<Mutation> mutations = new ArrayList<>(); // KeySet.all() can be used to delete all the rows in a table. mutations.add(Mutation.delete("Albums", KeySet.all())); // KeySet.singleKey() can be used to delete one row at a time. for (Singer singer : SINGERS) { mutations.add( Mutation.delete("Singers", KeySet.singleKey(Key.newBuilder().append(singer.singerId).build()))); } dbClient.write(mutations); System.out.printf("Records deleted.\n"); } // [END spanner_delete_data]
@Test public void equalsAndHashCode() { EqualsTester tester = new EqualsTester(); // Equality, not identity. tester.addEqualityGroup( Mutation.newInsertBuilder("T1").build(), Mutation.newInsertBuilder("T1").build()); // Operation types are distinguished. tester.addEqualityGroup(Mutation.newInsertOrUpdateBuilder("T1").build()); tester.addEqualityGroup(Mutation.newUpdateBuilder("T1").build()); tester.addEqualityGroup(Mutation.newReplaceBuilder("T1").build()); // Table is distinguished. tester.addEqualityGroup(Mutation.newInsertBuilder("T2").build()); // Columns/values are distinguished (but by equality, not identity). tester.addEqualityGroup( Mutation.newInsertBuilder("T1").set("C").to("V").build(), Mutation.newInsertBuilder("T1").set("C").to("V").build()); // Deletes consider the key set. tester.addEqualityGroup(Mutation.delete("T1", KeySet.all())); tester.addEqualityGroup( Mutation.delete("T1", KeySet.singleKey(Key.of("k"))), Mutation.delete("T1", Key.of("k"))); tester.testEquals(); }
/** * Returns a mutation that will delete the row with primary key {@code key}. Exactly equivalent to * {@code delete(table, KeySet.singleKey(key))}. */ public static Mutation delete(String table, Key key) { return delete(table, KeySet.singleKey(key)); }
@Override public Mutation delete(Class entityClass, KeySet keys) { SpannerPersistentEntity<?> persistentEntity = this.spannerMappingContext .getPersistentEntity(entityClass); return Mutation.delete(persistentEntity.tableName(), keys); }
@Override public Mutation delete(Class entityClass, KeySet keys) { SpannerPersistentEntity<?> persistentEntity = this.spannerMappingContext .getPersistentEntity(entityClass); return Mutation.delete(persistentEntity.tableName(), keys); }
@Test public void deleteOrdering() throws Exception { SpannerSchema.Builder builder = SpannerSchema.builder(); builder.addColumn("test1", "key", "INT64"); builder.addKeyPart("test1", "key", false); builder.addColumn("test2", "key", "INT64"); builder.addKeyPart("test2", "key", false); SpannerSchema schema = builder.build(); // Verify that the encoded keys are ordered by table name then key List<Mutation> sortedMutations = Arrays.asList( Mutation.delete("test1", KeySet.all()), // non-point deletes come first Mutation.delete("test1", Key.of(1L)), Mutation.delete("test1", Key.of(2L)), Mutation.delete("test2", KeySet.prefixRange(Key.of(1L))), Mutation.delete("test2", Key.of(2L))); verifyEncodedOrdering(schema, sortedMutations); }
private static Mutation del(Long... keys) { KeySet.Builder builder = KeySet.newBuilder(); for (Long key : keys) { builder.addKey(Key.of(key)); } return Mutation.delete("test", builder.build()); }
private static Mutation delRange(Long start, Long end) { return Mutation.delete("test", KeySet.range(KeyRange.closedClosed(Key.of(start), Key.of(end)))); }
@Test public void testBatchableMutationFilterFn_cells() { Mutation all = Mutation.delete("test", KeySet.all()); Mutation prefix = Mutation.delete("test", KeySet.prefixRange(Key.of(1L))); Mutation range = Mutation.delete( "test", KeySet.range(KeyRange.openOpen(Key.of(1L), Key.newBuilder().build()))); MutationGroup[] mutationGroups =
@Test public void testBatchableMutationFilterFn_size() { Mutation all = Mutation.delete("test", KeySet.all()); Mutation prefix = Mutation.delete("test", KeySet.prefixRange(Key.of(1L))); Mutation range = Mutation.delete( "test", KeySet.range(KeyRange.openOpen(Key.of(1L), Key.newBuilder().build()))); MutationGroup[] mutationGroups =