kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 0be9be9e80225a1b82ac917d1417ee952b820c42d79b00ffdb34820fe6e5d8a4 |
|---|---|
| Author | Alex Petrov <oleksandr.petrov@gmail.com> · 2015-12-13 14:57 +01:00 |
| Committer | Alex Petrov <oleksandr.petrov@gmail.com> · 2016-03-01 12:03 +01:00 |
| Parents | 17f0e5d21583 |
3 files changed
added driver-core/src/main/java/com/datastax/driver/core/schemabuilder/AlterKeyspace.java +41 −0
| @@ -0,0 +1,41 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (C) 2012-2015 DataStax Inc. | |
| 3 | + * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | + * you may not use this file except in compliance with the License. | |
| 6 | + * You may obtain a copy of the License at | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | + * See the License for the specific language governing permissions and | |
| 14 | + * limitations under the License. | |
| 15 | + */ | |
| 16 | +package com.datastax.driver.core.schemabuilder; | |
| 17 | + | |
| 18 | +/** | |
| 19 | + * A built ALTER KEYSPACE statement. | |
| 20 | + */ | |
| 21 | +public class AlterKeyspace { | |
| 22 | + | |
| 23 | + static final String COMMAND = "ALTER KEYSPACE"; | |
| 24 | + | |
| 25 | + private final String keyspaceName; | |
| 26 | + | |
| 27 | + public AlterKeyspace(String keyspaceName) { | |
| 28 | + this.keyspaceName = keyspaceName; | |
| 29 | + } | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * Add options for this ALTER KEYSPACE statement. | |
| 33 | + * | |
| 34 | + * @return the options of this ALTER KEYSPACE statement. | |
| 35 | + */ | |
| 36 | + public KeyspaceOptions with() { | |
| 37 | + return new KeyspaceOptions(COMMAND, keyspaceName); | |
| 38 | + } | |
| 39 | + | |
| 40 | +} | |
| 41 | + |
modified driver-core/src/main/java/com/datastax/driver/core/schemabuilder/SchemaBuilder.java +10 −0
| @@ -62,6 +62,16 @@ | ||
| 62 | 62 | return new Create(keyspaceName, tableName); |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | + /** | |
| 66 | + * Start building a new ALTER KEYSPACE statement. | |
| 67 | + * | |
| 68 | + * @param keyspaceName the name of the keyspace to be altered. | |
| 69 | + * @return an in-construction ALTER KEYSPACE statement. | |
| 70 | + */ | |
| 71 | + public static AlterKeyspace alterKeyspace(String keyspaceName) { | |
| 72 | + return new AlterKeyspace(keyspaceName); | |
| 73 | + } | |
| 74 | + | |
| 65 | 75 | /** |
| 66 | 76 | * Start building a new ALTER TABLE statement. |
| 67 | 77 | * |
added driver-core/src/test/java/com/datastax/driver/core/schemabuilder/AlterKeyspaceTest.java +56 −0
| @@ -0,0 +1,56 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (C) 2012-2015 DataStax Inc. | |
| 3 | + * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | + * you may not use this file except in compliance with the License. | |
| 6 | + * You may obtain a copy of the License at | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | + * See the License for the specific language governing permissions and | |
| 14 | + * limitations under the License. | |
| 15 | + */ | |
| 16 | +package com.datastax.driver.core.schemabuilder; | |
| 17 | + | |
| 18 | +import org.testng.annotations.Test; | |
| 19 | + | |
| 20 | +import java.util.HashMap; | |
| 21 | +import java.util.Map; | |
| 22 | + | |
| 23 | +import static com.datastax.driver.core.schemabuilder.SchemaBuilder.alterKeyspace; | |
| 24 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 25 | + | |
| 26 | +public class AlterKeyspaceTest { | |
| 27 | + | |
| 28 | + @Test(groups = "unit") | |
| 29 | + public void should_alter_keyspace_with_options() throws Exception { | |
| 30 | + Map<String, Object> replicationOptions = new HashMap<String, Object>(); | |
| 31 | + replicationOptions.put("class", "SimpleStrategy"); | |
| 32 | + replicationOptions.put("replication_factor", 1); | |
| 33 | + | |
| 34 | + //When | |
| 35 | + SchemaStatement statement = alterKeyspace("test").with() | |
| 36 | + .durableWrites(true) | |
| 37 | + .replication(replicationOptions); | |
| 38 | + | |
| 39 | + //Then | |
| 40 | + assertThat(statement.getQueryString()) | |
| 41 | + .isEqualTo("\n\tALTER KEYSPACE test" + | |
| 42 | + "\n\tWITH\n\t\t" + | |
| 43 | + "REPLICATION = {'replication_factor': 1, 'class': 'SimpleStrategy'}\n\t\t" + | |
| 44 | + "AND DURABLE_WRITES = true"); | |
| 45 | + } | |
| 46 | + | |
| 47 | + @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class) | |
| 48 | + public void incorrect_replication_options() throws Exception { | |
| 49 | + Map<String, Object> replicationOptions = new HashMap<String, Object>(); | |
| 50 | + replicationOptions.put("class", 5); | |
| 51 | + | |
| 52 | + //When | |
| 53 | + alterKeyspace("test").with() | |
| 54 | + .replication(replicationOptions); | |
| 55 | + } | |
| 56 | +} |