All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.codehaus.mojo.cassandra.DropColumnFamiliesMojo Maven / Gradle / Ivy

Go to download

The Mojo Projects plugin for Apache Maven to allow launching a local Apache Cassandra instance from a Maven build

There is a newer version: 4.0.0
Show newest version
package org.codehaus.mojo.cassandra;

import org.apache.cassandra.thrift.SchemaDisagreementException;
import org.apache.cassandra.thrift.InvalidRequestException;
import org.apache.cassandra.thrift.Cassandra.Client;
import org.apache.commons.lang.StringUtils;
import org.apache.thrift.TException;

/**
 * Drop the specified ColumnFamilies or, if no arguments are given, 
 * the specified Keyspace 
 * 
 * @author zznate
 * @threadSafe
 * @non-goal drop
 */
public class DropColumnFamiliesMojo extends AbstractSchemaCassandraMojo {

    /**
     * The one or more comma-delimited ColumnFamilies against to be dropped. 
     * If not specified, the Keyspace will be dropped.
     * @parameter expression="${cassandra.columnFamilies}"
     */
    protected String columnFamilies;

    private String[] columnFamilyList;

    protected void parseArguments() throws IllegalArgumentException
    {
        if (StringUtils.isNotBlank(keyspace)) 
        {
            // keyspace is a required parameter but somebody could provide -Dkeyspace=
            // which would cause issues
            throw new IllegalArgumentException("The keyspace to drop column families from cannot be empty");
        }
    
        columnFamilyList = StringUtils.split(columnFamilies, ',');
    }

    @Override
    protected void executeOperation(Client client) throws InvalidRequestException, SchemaDisagreementException, TException 
    {
        if ( columnFamilyList != null && columnFamilyList.length > 0 ) 
        {
            for (int i = 0; i < columnFamilyList.length; i++) 
            {
                client.system_drop_column_family(columnFamilyList[i]);
                getLog().info("Dropped column family \"" + columnFamilyList[i] + "\".");
            }
        } 
        else 
        {
            client.system_drop_keyspace(keyspace);
            getLog().info("Dropped keyspace \"" + keyspace + "\".");
        }
        
    }
    
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy