Java Code Examples for org.apache.cassandra.config.CFMetaData#addTriggerDefinition()

The following examples show how to use org.apache.cassandra.config.CFMetaData#addTriggerDefinition() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TriggersSchemaTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void newKsContainsCfWithTrigger() throws Exception
{
    TriggerDefinition td = TriggerDefinition.create(triggerName, triggerClass);
    CFMetaData cfm1 = CFMetaData.compile(String.format("CREATE TABLE %s (k int PRIMARY KEY, v int)", cfName), ksName);
    cfm1.addTriggerDefinition(td);
    KSMetaData ksm = KSMetaData.newKeyspace(ksName,
                                            SimpleStrategy.class,
                                            Collections.singletonMap("replication_factor", "1"),
                                            true,
                                            Collections.singletonList(cfm1));
    MigrationManager.announceNewKeyspace(ksm);

    CFMetaData cfm2 = Schema.instance.getCFMetaData(ksName, cfName);
    assertFalse(cfm2.getTriggers().isEmpty());
    assertEquals(1, cfm2.getTriggers().size());
    assertEquals(td, cfm2.getTriggers().get(triggerName));
}
 
Example 2
Source File: TriggersSchemaTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void addNewCfWithTriggerToKs() throws Exception
{
    KSMetaData ksm = KSMetaData.newKeyspace(ksName,
                                            SimpleStrategy.class,
                                            Collections.singletonMap("replication_factor", "1"),
                                            true,
                                            Collections.EMPTY_LIST);
    MigrationManager.announceNewKeyspace(ksm);

    CFMetaData cfm1 = CFMetaData.compile(String.format("CREATE TABLE %s (k int PRIMARY KEY, v int)", cfName), ksName);
    TriggerDefinition td = TriggerDefinition.create(triggerName, triggerClass);
    cfm1.addTriggerDefinition(td);

    MigrationManager.announceNewColumnFamily(cfm1);

    CFMetaData cfm2 = Schema.instance.getCFMetaData(ksName, cfName);
    assertFalse(cfm2.getTriggers().isEmpty());
    assertEquals(1, cfm2.getTriggers().size());
    assertEquals(td, cfm2.getTriggers().get(triggerName));
}
 
Example 3
Source File: TriggersSchemaTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void addTriggerToCf() throws Exception
{
    CFMetaData cfm1 = CFMetaData.compile(String.format("CREATE TABLE %s (k int PRIMARY KEY, v int)", cfName), ksName);
    KSMetaData ksm = KSMetaData.newKeyspace(ksName,
                                            SimpleStrategy.class,
                                            Collections.singletonMap("replication_factor", "1"),
                                            true,
                                            Collections.singletonList(cfm1));
    MigrationManager.announceNewKeyspace(ksm);

    CFMetaData cfm2 = Schema.instance.getCFMetaData(ksName, cfName).copy();
    TriggerDefinition td = TriggerDefinition.create(triggerName, triggerClass);
    cfm2.addTriggerDefinition(td);
    MigrationManager.announceColumnFamilyUpdate(cfm2, false);

    CFMetaData cfm3 = Schema.instance.getCFMetaData(ksName, cfName);
    assertFalse(cfm3.getTriggers().isEmpty());
    assertEquals(1, cfm3.getTriggers().size());
    assertEquals(td, cfm3.getTriggers().get(triggerName));
}
 
Example 4
Source File: TriggersSchemaTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void removeTriggerFromCf() throws Exception
{
    TriggerDefinition td = TriggerDefinition.create(triggerName, triggerClass);
    CFMetaData cfm1 = CFMetaData.compile(String.format("CREATE TABLE %s (k int PRIMARY KEY, v int)", cfName), ksName);
    cfm1.addTriggerDefinition(td);
    KSMetaData ksm = KSMetaData.newKeyspace(ksName,
                                            SimpleStrategy.class,
                                            Collections.singletonMap("replication_factor", "1"),
                                            true,
                                            Collections.singletonList(cfm1));
    MigrationManager.announceNewKeyspace(ksm);

    CFMetaData cfm2 = Schema.instance.getCFMetaData(ksName, cfName).copy();
    cfm2.removeTrigger(triggerName);
    MigrationManager.announceColumnFamilyUpdate(cfm2, false);

    CFMetaData cfm3 = Schema.instance.getCFMetaData(ksName, cfName).copy();
    assertTrue(cfm3.getTriggers().isEmpty());
}
 
Example 5
Source File: CreateTriggerStatement.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public boolean announceMigration(boolean isLocalOnly) throws ConfigurationException, InvalidRequestException
{
    CFMetaData cfm = Schema.instance.getCFMetaData(keyspace(), columnFamily()).copy();

    TriggerDefinition triggerDefinition = TriggerDefinition.create(triggerName, triggerClass);

    if (!ifNotExists || !cfm.containsTriggerDefinition(triggerDefinition))
    {
        cfm.addTriggerDefinition(triggerDefinition);
        logger.info("Adding trigger with name {} and class {}", triggerName, triggerClass);
        MigrationManager.announceColumnFamilyUpdate(cfm, false, isLocalOnly);
        return true;
    }
    return false;
}
 
Example 6
Source File: TriggerExecutorTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
private static CFMetaData makeCfMetaData(String ks, String cf, TriggerDefinition trigger)
{

    CFMetaData metadata = CFMetaData.sparseCFMetaData(ks, cf, CompositeType.getInstance(UTF8Type.instance));

    metadata.keyValidator(UTF8Type.instance);
    metadata.addOrReplaceColumnDefinition(ColumnDefinition.partitionKeyDef(metadata,
                                                                           UTF8Type.instance.fromString("pkey"),
                                                                           UTF8Type.instance,
                                                                           null));
    metadata.addOrReplaceColumnDefinition(ColumnDefinition.regularDef(metadata,
                                                                      UTF8Type.instance.fromString("c1"),
                                                                      UTF8Type.instance,
                                                                      0));
    metadata.addOrReplaceColumnDefinition(ColumnDefinition.regularDef(metadata,
                                                                      UTF8Type.instance.fromString("c2"),
                                                                      UTF8Type.instance,
                                                                      0));
    try
    {
        if (trigger != null)
            metadata.addTriggerDefinition(trigger);
    }
    catch (InvalidRequestException e)
    {
        throw new AssertionError(e);
    }

    return metadata.rebuild();
}