usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From toddn...@apache.org
Subject [23/33] incubator-usergrid git commit: Removed unused 1.0 files.
Date Mon, 13 Apr 2015 19:18:30 GMT
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f95d39c7/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/CassandraService.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/CassandraService.java
b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/CassandraService.java
index 96d3fd9..b998084 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/CassandraService.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/CassandraService.java
@@ -19,9 +19,7 @@ package org.apache.usergrid.persistence.cassandra;
 
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.HashMap;
-import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
@@ -31,11 +29,8 @@ import java.util.UUID;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+
 import org.apache.usergrid.locking.LockManager;
-import org.apache.usergrid.persistence.IndexBucketLocator;
-import org.apache.usergrid.persistence.IndexBucketLocator.IndexType;
-import org.apache.usergrid.persistence.cassandra.index.IndexBucketScanner;
-import org.apache.usergrid.persistence.cassandra.index.IndexScanner;
 import org.apache.usergrid.persistence.core.astyanax.CassandraFig;
 import org.apache.usergrid.persistence.hector.CountingMutator;
 import org.apache.usergrid.utils.MapUtils;
@@ -60,32 +55,22 @@ import me.prettyprint.hector.api.Serializer;
 import me.prettyprint.hector.api.beans.ColumnSlice;
 import me.prettyprint.hector.api.beans.DynamicComposite;
 import me.prettyprint.hector.api.beans.HColumn;
-import me.prettyprint.hector.api.beans.OrderedRows;
-import me.prettyprint.hector.api.beans.Row;
-import me.prettyprint.hector.api.beans.Rows;
 import me.prettyprint.hector.api.ddl.ColumnFamilyDefinition;
 import me.prettyprint.hector.api.ddl.KeyspaceDefinition;
 import me.prettyprint.hector.api.factory.HFactory;
 import me.prettyprint.hector.api.mutation.Mutator;
 import me.prettyprint.hector.api.query.ColumnQuery;
-import me.prettyprint.hector.api.query.MultigetSliceQuery;
 import me.prettyprint.hector.api.query.QueryResult;
-import me.prettyprint.hector.api.query.RangeSlicesQuery;
 import me.prettyprint.hector.api.query.SliceQuery;
 
 import static me.prettyprint.cassandra.service.FailoverPolicy.ON_FAIL_TRY_ALL_AVAILABLE;
 import static me.prettyprint.hector.api.factory.HFactory.createColumn;
-import static me.prettyprint.hector.api.factory.HFactory.createMultigetSliceQuery;
-
-import static me.prettyprint.hector.api.factory.HFactory.createRangeSlicesQuery;
 import static me.prettyprint.hector.api.factory.HFactory.createSliceQuery;
 import static me.prettyprint.hector.api.factory.HFactory.createVirtualKeyspace;
 import static org.apache.commons.collections.MapUtils.getIntValue;
 import static org.apache.commons.collections.MapUtils.getString;
-import static org.apache.usergrid.persistence.cassandra.ApplicationCF.ENTITY_ID_SETS;
 import static org.apache.usergrid.persistence.cassandra.CassandraPersistenceUtils.batchExecute;
 import static org.apache.usergrid.utils.ConversionUtils.bytebuffer;
-import static org.apache.usergrid.utils.ConversionUtils.bytebuffers;
 import static org.apache.usergrid.utils.JsonUtils.mapToFormattedJsonString;
 import static org.apache.usergrid.utils.MapUtils.asMap;
 import static org.apache.usergrid.utils.MapUtils.filter;
@@ -523,96 +508,6 @@ public class CassandraService {
         return results;
     }
 
-
-    public Map<ByteBuffer, List<HColumn<ByteBuffer, ByteBuffer>>> multiGetColumns(
Keyspace ko, Object columnFamily,
-                                                                                   List<?>
keys, Object start,
-                                                                                   Object
finish, int count,
-                                                                                   boolean
reversed ) throws Exception {
-
-        if ( db_logger.isDebugEnabled() ) {
-            db_logger.debug( "multiGetColumns cf=" + columnFamily + " keys=" + keys + " start="
+ start + " finish="
-                    + finish + " count=" + count + " reversed=" + reversed );
-        }
-
-        MultigetSliceQuery<ByteBuffer, ByteBuffer, ByteBuffer> q = createMultigetSliceQuery(
ko, be, be, be );
-        q.setColumnFamily( columnFamily.toString() );
-        q.setKeys( bytebuffers( keys ) );
-
-        ByteBuffer start_bytes = null;
-        if ( start instanceof DynamicComposite ) {
-            start_bytes = ( ( DynamicComposite ) start ).serialize();
-        }
-        else if ( start instanceof List ) {
-            start_bytes = DynamicComposite.toByteBuffer( ( List<?> ) start );
-        }
-        else {
-            start_bytes = bytebuffer( start );
-        }
-
-        ByteBuffer finish_bytes = null;
-        if ( finish instanceof DynamicComposite ) {
-            finish_bytes = ( ( DynamicComposite ) finish ).serialize();
-        }
-        else if ( finish instanceof List ) {
-            finish_bytes = DynamicComposite.toByteBuffer( ( List<?> ) finish );
-        }
-        else {
-            finish_bytes = bytebuffer( finish );
-        }
-
-        q.setRange( start_bytes, finish_bytes, reversed, count );
-        QueryResult<Rows<ByteBuffer, ByteBuffer, ByteBuffer>> r = q.execute();
-        Rows<ByteBuffer, ByteBuffer, ByteBuffer> rows = r.get();
-
-        Map<ByteBuffer, List<HColumn<ByteBuffer, ByteBuffer>>> results
=
-                new LinkedHashMap<ByteBuffer, List<HColumn<ByteBuffer, ByteBuffer>>>();
-        for ( Row<ByteBuffer, ByteBuffer, ByteBuffer> row : rows ) {
-            results.put( row.getKey(), row.getColumnSlice().getColumns() );
-        }
-
-        return results;
-    }
-
-
-    /**
-     * Gets the columns.
-     *
-     * @param ko the keyspace
-     * @param columnFamily the column family
-     * @param keys the keys
-     *
-     * @return map of keys to columns
-     *
-     * @throws Exception the exception
-     */
-    public <K, N, V> Rows<K, N, V> getRows( Keyspace ko, Object columnFamily,
Collection<K> keys,
-                                            Serializer<K> keySerializer, Serializer<N>
nameSerializer,
-                                            Serializer<V> valueSerializer ) throws
Exception {
-
-        if ( db_logger.isDebugEnabled() ) {
-            db_logger.debug( "getColumns cf=" + columnFamily + " keys=" + keys );
-        }
-
-        MultigetSliceQuery<K, N, V> q = createMultigetSliceQuery( ko, keySerializer,
nameSerializer, valueSerializer );
-        q.setColumnFamily( columnFamily.toString() );
-        q.setKeys( keys );
-        q.setRange( null, null, false, ALL_COUNT );
-        QueryResult<Rows<K, N, V>> r = q.execute();
-        Rows<K, N, V> results = r.get();
-
-        if ( db_logger.isInfoEnabled() ) {
-            if ( results == null ) {
-                db_logger.info( "getColumns returned null" );
-            }
-            else {
-                db_logger.info( "getColumns returned " + results.getCount() + " columns"
);
-            }
-        }
-
-        return results;
-    }
-
-
     /**
      * Gets the columns.
      *
@@ -659,49 +554,6 @@ public class CassandraService {
 
 
     /**
-     * Gets the columns.
-     *
-     * @param ko the keyspace
-     * @param columnFamily the column family
-     * @param keys the keys
-     * @param columnNames the column names
-     *
-     * @return map of keys to columns
-     *
-     * @throws Exception the exception
-     */
-    @SuppressWarnings("unchecked")
-    public <K, N, V> Rows<K, N, V> getRows( Keyspace ko, Object columnFamily,
Collection<K> keys,
-                                            Collection<String> columnNames, Serializer<K>
keySerializer,
-                                            Serializer<N> nameSerializer, Serializer<V>
valueSerializer )
-            throws Exception {
-
-        if ( db_logger.isDebugEnabled() ) {
-            db_logger.debug( "getColumns cf=" + columnFamily + " keys=" + keys + " names="
+ columnNames );
-        }
-
-        MultigetSliceQuery<K, N, V> q = createMultigetSliceQuery( ko, keySerializer,
nameSerializer, valueSerializer );
-        q.setColumnFamily( columnFamily.toString() );
-        q.setKeys( keys );
-        q.setColumnNames( ( N[] ) nameSerializer.fromBytesSet( se.toBytesSet( new ArrayList<String>(
columnNames ) ) )
-                                                .toArray() );
-        QueryResult<Rows<K, N, V>> r = q.execute();
-        Rows<K, N, V> results = r.get();
-
-        if ( db_logger.isInfoEnabled() ) {
-            if ( results == null ) {
-                db_logger.info( "getColumns returned null" );
-            }
-            else {
-                db_logger.info( "getColumns returned " + results.getCount() + " columns"
);
-            }
-        }
-
-        return results;
-    }
-
-
-    /**
      * Gets the column.
      *
      * @param ko the keyspace
@@ -772,18 +624,6 @@ public class CassandraService {
     }
 
 
-    public HColumn<String, ByteBuffer> getColumn( Keyspace ko, Object columnFamily,
Object key, String column )
-            throws Exception {
-        return getColumn( ko, columnFamily, key, column, se, be );
-    }
-
-
-    public void setColumn( Keyspace ko, Object columnFamily, Object key, Object columnName,
Object columnValue )
-            throws Exception {
-        this.setColumn( ko, columnFamily, key, columnName, columnValue, 0 );
-    }
-
-
     public void setColumn( Keyspace ko, Object columnFamily, Object key, Object columnName,
Object columnValue,
                            int ttl ) throws Exception {
 
@@ -817,19 +657,7 @@ public class CassandraService {
     }
 
 
-    /**
-     * Sets the columns.
-     *
-     * @param ko the keyspace
-     * @param columnFamily the column family
-     * @param key the key
-     * @param map the map
-     *
-     * @throws Exception the exception
-     */
-    public void setColumns( Keyspace ko, Object columnFamily, byte[] key, Map<?, ?>
map ) throws Exception {
-        this.setColumns( ko, columnFamily, key, map, 0 );
-    }
+
 
 
     public void setColumns( Keyspace ko, Object columnFamily, byte[] key, Map<?, ?>
map, int ttl ) throws Exception {
@@ -884,95 +712,6 @@ public class CassandraService {
     }
 
 
-    /**
-     * Delete column.
-     *
-     * @param ko the keyspace
-     * @param columnFamily the column family
-     * @param key the key
-     * @param column the column
-     *
-     * @throws Exception the exception
-     */
-    public void deleteColumn( Keyspace ko, Object columnFamily, Object key, Object column
) throws Exception {
-
-        if ( db_logger.isDebugEnabled() ) {
-            db_logger.debug( "deleteColumn cf=" + columnFamily + " key=" + key + " name="
+ column );
-        }
-
-        Mutator<ByteBuffer> m = CountingMutator.createFlushingMutator( ko, be );
-        m.delete( bytebuffer( key ), columnFamily.toString(), bytebuffer( column ), be );
-    }
-
-
-    /**
-     * Gets the row keys.
-     *
-     * @param ko the keyspace
-     * @param columnFamily the column family
-     *
-     * @return set of keys
-     *
-     * @throws Exception the exception
-     */
-    public <K> Set<K> getRowKeySet( Keyspace ko, Object columnFamily, Serializer<K>
keySerializer ) throws Exception {
-
-        if ( db_logger.isDebugEnabled() ) {
-            db_logger.debug( "getRowKeys cf=" + columnFamily );
-        }
-
-        RangeSlicesQuery<K, ByteBuffer, ByteBuffer> q = createRangeSlicesQuery( ko,
keySerializer, be, be );
-        q.setColumnFamily( columnFamily.toString() );
-        q.setKeys( null, null );
-        q.setColumnNames( new ByteBuffer[0] );
-        QueryResult<OrderedRows<K, ByteBuffer, ByteBuffer>> r = q.execute();
-        OrderedRows<K, ByteBuffer, ByteBuffer> rows = r.get();
-
-        Set<K> results = new LinkedHashSet<K>();
-        for ( Row<K, ByteBuffer, ByteBuffer> row : rows ) {
-            results.add( row.getKey() );
-        }
-
-        if ( db_logger.isDebugEnabled() ) {
-            {
-                db_logger.debug( "getRowKeys returned " + results.size() + " rows" );
-            }
-        }
-
-        return results;
-    }
-
-
-    /**
-     * Gets the row keys as uui ds.
-     *
-     * @param ko the keyspace
-     * @param columnFamily the column family
-     *
-     * @return list of row key UUIDs
-     *
-     * @throws Exception the exception
-     */
-    public <K> List<K> getRowKeyList( Keyspace ko, Object columnFamily, Serializer<K>
keySerializer ) throws Exception {
-
-        RangeSlicesQuery<K, ByteBuffer, ByteBuffer> q = createRangeSlicesQuery( ko,
keySerializer, be, be );
-        q.setColumnFamily( columnFamily.toString() );
-        q.setKeys( null, null );
-        q.setColumnNames( new ByteBuffer[0] );
-        QueryResult<OrderedRows<K, ByteBuffer, ByteBuffer>> r = q.execute();
-        OrderedRows<K, ByteBuffer, ByteBuffer> rows = r.get();
-
-        List<K> list = new ArrayList<K>();
-        for ( Row<K, ByteBuffer, ByteBuffer> row : rows ) {
-            list.add( row.getKey() );
-            // K uuid = row.getKey();
-            // if (uuid != UUIDUtils.ZERO_UUID) {
-            // list.add(uuid);
-            // }
-        }
-
-        return list;
-    }
 
 
     /**
@@ -995,45 +734,6 @@ public class CassandraService {
 
 
 
-    /**
-     * Gets the id list.
-     *
-     * @param ko the keyspace
-     * @param key the key
-     * @param start the start
-     * @param finish the finish
-     * @param count the count
-     * @param reversed True if the scan should be reversed
-     * @param locator The index locator instance
-     * @param applicationId The applicationId
-     * @param collectionName The name of the collection to get the Ids for
-     *
-     * @return list of columns as UUIDs
-     *
-     * @throws Exception the exception
-     */
-    public IndexScanner getIdList( Keyspace ko, Object key, UUID start, UUID finish, int
count, boolean reversed,
-                                   IndexBucketLocator locator, UUID applicationId, String
collectionName, boolean keepFirst )
-            throws Exception {
-
-        if ( count <= 0 ) {
-            count = DEFAULT_COUNT;
-        }
-
-        if ( NULL_ID.equals( start ) ) {
-            start = null;
-        }
-
-
-        final boolean skipFirst = start != null && !keepFirst;
-
-        IndexScanner scanner =
-                new IndexBucketScanner( this, locator, ENTITY_ID_SETS, applicationId, IndexType.COLLECTION,
key, start,
-                        finish, reversed, count, skipFirst, collectionName );
-
-        return scanner;
-    }
-
 
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f95d39c7/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/CursorCache.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/CursorCache.java
b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/CursorCache.java
deleted file mode 100644
index 47bb0cf..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/CursorCache.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.persistence.cassandra;
-
-
-import java.nio.ByteBuffer;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import static java.lang.Integer.parseInt;
-
-import static org.apache.commons.codec.binary.Base64.decodeBase64;
-import static org.apache.commons.codec.binary.Base64.encodeBase64URLSafeString;
-import static org.apache.commons.lang.StringUtils.split;
-import static org.apache.usergrid.utils.ConversionUtils.bytes;
-
-
-/**
- * Internal cursor parsing
- *
- * @author tnine
- */
-public class CursorCache {
-
-    private Map<Integer, ByteBuffer> cursors = new HashMap<Integer, ByteBuffer>();
-
-
-    public CursorCache() {
-
-    }
-
-
-    /** Create a new cursor cache from the string if passed */
-    public CursorCache( String cursorString ) {
-
-        if ( cursorString == null ) {
-            return;
-        }
-
-        String decoded = new String( decodeBase64( cursorString ) );
-
-        // nothing to do
-        if ( decoded.indexOf( ':' ) < 0 ) {
-            return;
-        }
-
-        String[] cursorTokens = split( decoded, '|' );
-
-        for ( String c : cursorTokens ) {
-
-            String[] parts = split( c, ':' );
-
-            if ( parts.length >= 1 ) {
-
-                int hashCode = parseInt( parts[0] );
-
-                ByteBuffer cursorBytes = null;
-
-                if ( parts.length == 2 ) {
-                    cursorBytes = ByteBuffer.wrap( decodeBase64( parts[1] ) );
-                }
-                else {
-                    cursorBytes = ByteBuffer.allocate( 0 );
-                }
-
-                cursors.put( hashCode, cursorBytes );
-            }
-        }
-    }
-
-
-    /** Set the cursor with the given hash and the new byte buffer */
-    public void setNextCursor( int sliceHash, ByteBuffer newCursor ) {
-        cursors.put( sliceHash, newCursor );
-    }
-
-
-    /** Get the cursor by the hashcode of the slice */
-    public ByteBuffer getCursorBytes( int sliceHash ) {
-        return cursors.get( sliceHash );
-    }
-
-
-    /** Turn the cursor cache into a string */
-    public String asString() {
-        /**
-         * No cursors to return
-         */
-        if ( cursors.size() == 0 ) {
-            return null;
-        }
-
-        StringBuffer buff = new StringBuffer();
-
-        int nullCount = 0;
-        ByteBuffer value = null;
-
-        for ( Entry<Integer, ByteBuffer> entry : cursors.entrySet() ) {
-            value = entry.getValue();
-
-            buff.append( entry.getKey() );
-            buff.append( ":" );
-            buff.append( encodeBase64URLSafeString( bytes( value ) ) );
-            buff.append( "|" );
-
-            // this range was empty, mark it as a null
-            if ( value == null || value.remaining() == 0 ) {
-                nullCount++;
-            }
-        }
-
-        // all cursors are complete, return null
-        if ( nullCount == cursors.size() ) {
-            return null;
-        }
-
-        // trim off the last pipe
-        buff.setLength( buff.length() - 1 );
-
-        return encodeBase64URLSafeString( buff.toString().getBytes() );
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f95d39c7/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImpl.java
b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImpl.java
deleted file mode 100644
index 882e7d9..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImpl.java
+++ /dev/null
@@ -1,481 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.persistence.cassandra;
-
-
-import java.nio.ByteBuffer;
-import java.util.Map;
-import java.util.TreeMap;
-import java.util.UUID;
-
-import org.apache.usergrid.persistence.Entity;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.BeansException;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
-import org.apache.usergrid.persistence.DynamicEntity;
-import org.apache.usergrid.persistence.EntityManager;
-import org.apache.usergrid.persistence.EntityManagerFactory;
-import org.apache.usergrid.persistence.entities.Application;
-import org.apache.usergrid.persistence.exceptions.ApplicationAlreadyExistsException;
-import org.apache.usergrid.persistence.hector.CountingMutator;
-import org.apache.usergrid.utils.UUIDUtils;
-
-import org.apache.commons.lang.StringUtils;
-
-import com.google.common.cache.CacheBuilder;
-import com.google.common.cache.CacheLoader;
-import com.google.common.cache.LoadingCache;
-
-import me.prettyprint.hector.api.Keyspace;
-import me.prettyprint.hector.api.beans.ColumnSlice;
-import me.prettyprint.hector.api.beans.HColumn;
-import me.prettyprint.hector.api.beans.OrderedRows;
-import me.prettyprint.hector.api.beans.Row;
-import me.prettyprint.hector.api.beans.Rows;
-import me.prettyprint.hector.api.mutation.Mutator;
-import me.prettyprint.hector.api.query.QueryResult;
-import me.prettyprint.hector.api.query.RangeSlicesQuery;
-
-import static java.lang.String.CASE_INSENSITIVE_ORDER;
-
-
-import static me.prettyprint.hector.api.factory.HFactory.createRangeSlicesQuery;
-import static org.apache.usergrid.persistence.Schema.PROPERTY_NAME;
-import static org.apache.usergrid.persistence.Schema.PROPERTY_UUID;
-import static org.apache.usergrid.persistence.Schema.TYPE_APPLICATION;
-import static org.apache.usergrid.persistence.cassandra.CassandraPersistenceUtils.addInsertToMutator;
-import static org.apache.usergrid.persistence.cassandra.CassandraPersistenceUtils.asMap;
-import static org.apache.usergrid.persistence.cassandra.CassandraPersistenceUtils.batchExecute;
-import static org.apache.usergrid.persistence.cassandra.CassandraService.APPLICATIONS_CF;
-import static org.apache.usergrid.persistence.cassandra.CassandraService.PROPERTIES_CF;
-import static org.apache.usergrid.persistence.cassandra.CassandraService.RETRY_COUNT;
-import static org.apache.usergrid.utils.ConversionUtils.uuid;
-import static org.apache.usergrid.persistence.cassandra.Serializers.*;
-import org.apache.usergrid.persistence.core.util.Health;
-
-
-/**
- * Cassandra-specific implementation of Datastore
- *
- * @author edanuff
- */
-public class EntityManagerFactoryImpl implements EntityManagerFactory, ApplicationContextAware
{
-
-    private static final Logger logger = LoggerFactory.getLogger( EntityManagerFactoryImpl.class
);
-
-    public static String IMPLEMENTATION_DESCRIPTION = "Cassandra Entity Manager Factory 1.0";
-
-    public static final Class<DynamicEntity> APPLICATION_ENTITY_CLASS = DynamicEntity.class;
-
-
-    ApplicationContext applicationContext;
-
-    CassandraService cass;
-    CounterUtils counterUtils;
-
-    private boolean skipAggregateCounters;
-
-    private LoadingCache<UUID, EntityManager> entityManagers =
-            CacheBuilder.newBuilder().maximumSize( 100 ).build( new CacheLoader<UUID,
EntityManager>() {
-                public EntityManager load( UUID appId ) { // no checked exception
-                    return _getEntityManager( appId );
-                }
-            } );
-
-    private static final int REBUILD_PAGE_SIZE = 100;
-
-
-    /**
-     * Must be constructed with a CassandraClientPool.
-     *
-     * @param cass the cassandraService instance
-     */
-    public EntityManagerFactoryImpl( CassandraService cass, CounterUtils counterUtils, boolean
skipAggregateCounters ) {
-        this.cass = cass;
-        this.counterUtils = counterUtils;
-        this.skipAggregateCounters = skipAggregateCounters;
-        if ( skipAggregateCounters ) {
-            logger.warn( "NOTE: Counters have been disabled by configuration..." );
-        }
-    }
-
-
-    /*
-     * (non-Javadoc)
-     *
-     * @see org.apache.usergrid.core.Datastore#getEntityDao(java.util.UUID,
-     * java.util.UUID)
-     */
-    @Override
-    public EntityManager getEntityManager( UUID applicationId ) {
-        try {
-            return entityManagers.get( applicationId );
-        }
-        catch ( Exception ex ) {
-            ex.printStackTrace();
-        }
-        return _getEntityManager( applicationId );
-    }
-
-
-    private EntityManager _getEntityManager( UUID applicationId ) {
-        EntityManagerImpl em = new EntityManagerImpl();
-        em.init( this, cass, counterUtils, applicationId, skipAggregateCounters );
-        em.setApplicationId( applicationId );
-        return em;
-    }
-
-
-    public ApplicationContext getApplicationContext() {
-        return applicationContext;
-    }
-
-
-    /**
-     * Gets the setup.
-     *
-     * @return Setup helper
-     */
-    public SetupImpl getSetup() {
-        return new SetupImpl( this, cass );
-    }
-
-
-    @Override
-    public void setup() throws Exception {
-        Setup setup = getSetup();
-        setup.init();
-
-        if ( cass.getPropertiesMap() != null ) {
-            updateServiceProperties( cass.getPropertiesMap() );
-        }
-    }
-
-
-    /*
-     * (non-Javadoc)
-     *
-     * @see org.apache.usergrid.core.Datastore#createApplication(java.lang.String)
-     */
-    @Override
-    public UUID createApplication( String organization, String name ) throws Exception {
-        return createApplication( organization, name, null );
-    }
-
-
-    /*
-     * (non-Javadoc)
-     *
-     * @see org.apache.usergrid.core.Datastore#createApplication(java.lang.String,
-     * java.util.Map)
-     */
-    @Override
-    public UUID createApplication( String organizationName, String name, Map<String, Object>
properties )
-            throws Exception {
-
-        String appName = buildAppName( organizationName, name );
-
-        HColumn<String, ByteBuffer> column =
-                cass.getColumn( cass.getUsergridApplicationKeyspace(), APPLICATIONS_CF, appName,
PROPERTY_UUID );
-        if ( column != null ) {
-            throw new ApplicationAlreadyExistsException( name );
-            // UUID uuid = uuid(column.getValue());
-            // return uuid;
-        }
-
-        UUID applicationId = UUIDUtils.newTimeUUID();
-        logger.info( "New application id " + applicationId.toString() );
-
-        initializeApplication( organizationName, applicationId, appName, properties );
-
-        return applicationId;
-    }
-
-
-    @Override
-    public void deleteApplication(UUID applicationId) throws Exception {
-        // TODO implement deleteApplication in Usergrid 1 code base (master branch?)
-        throw new UnsupportedOperationException("Not supported.");
-    }
-
-
-    private String buildAppName( String organizationName, String name ) {
-        return StringUtils.lowerCase( name.contains( "/" ) ? name : organizationName + "/"
+ name );
-    }
-
-
-    public UUID initializeApplication( String organizationName, UUID applicationId, String
name,
-                                       Map<String, Object> properties ) throws Exception
{
-
-        String appName = buildAppName( organizationName, name );
-        // check for pre-existing
-        if ( lookupApplication( appName ) != null ) {
-            throw new ApplicationAlreadyExistsException( appName );
-        }
-        if ( properties == null ) {
-            properties = new TreeMap<String, Object>( CASE_INSENSITIVE_ORDER );
-        }
-
-        properties.put( PROPERTY_NAME, appName );
-
-        getSetup().setupApplicationKeyspace( applicationId, appName );
-
-        Keyspace ko = cass.getUsergridApplicationKeyspace();
-        Mutator<ByteBuffer> m = CountingMutator.createFlushingMutator( ko, be );
-
-        long timestamp = cass.createTimestamp();
-
-        addInsertToMutator( m, APPLICATIONS_CF, appName, PROPERTY_UUID, applicationId, timestamp
);
-        addInsertToMutator( m, APPLICATIONS_CF, appName, PROPERTY_NAME, appName, timestamp
);
-
-        batchExecute( m, RETRY_COUNT );
-
-        EntityManager em = getEntityManager( applicationId );
-        em.create( TYPE_APPLICATION, APPLICATION_ENTITY_CLASS, properties );
-
-        em.resetRoles();
-
-        return applicationId;
-    }
-
-
-    @Override
-    public UUID importApplication( String organizationName, UUID applicationId, String name,
-                                   Map<String, Object> properties ) throws Exception
{
-
-        name = buildAppName( organizationName, name );
-
-        HColumn<String, ByteBuffer> column =
-                cass.getColumn( cass.getUsergridApplicationKeyspace(), APPLICATIONS_CF, name,
PROPERTY_UUID );
-        if ( column != null ) {
-            throw new ApplicationAlreadyExistsException( name );
-            // UUID uuid = uuid(column.getValue());
-            // return uuid;
-        }
-
-        return initializeApplication( organizationName, applicationId, name, properties );
-    }
-
-
-    @Override
-    public UUID lookupApplication( String name ) throws Exception {
-        name = name.toLowerCase();
-        HColumn<String, ByteBuffer> column =
-                cass.getColumn( cass.getUsergridApplicationKeyspace(), APPLICATIONS_CF, name,
PROPERTY_UUID );
-        if ( column != null ) {
-            return uuid( column.getValue() );
-        }
-        return null;
-    }
-
-
-    /**
-     * Gets the application.
-     *
-     * @param name the name
-     *
-     * @return application for name
-     *
-     * @throws Exception the exception
-     */
-    public Application getApplication( String name ) throws Exception {
-        name = name.toLowerCase();
-        HColumn<String, ByteBuffer> column =
-                cass.getColumn( cass.getUsergridApplicationKeyspace(), APPLICATIONS_CF, name,
PROPERTY_UUID );
-        if ( column == null ) {
-            return null;
-        }
-
-        UUID applicationId = uuid( column.getValue() );
-
-        EntityManager em = getEntityManager( applicationId );
-        return ( ( EntityManagerImpl ) em ).getEntity( applicationId, Application.class );
-    }
-
-
-    @Override
-    public Map<String, UUID> getApplications() throws Exception {
-        Map<String, UUID> applications = new TreeMap<String, UUID>( CASE_INSENSITIVE_ORDER
);
-        Keyspace ko = cass.getUsergridApplicationKeyspace();
-        RangeSlicesQuery<String, String, UUID> q = createRangeSlicesQuery( ko, se,
se, ue );
-        q.setKeys( "", "\uFFFF" );
-        q.setColumnFamily( APPLICATIONS_CF );
-        q.setColumnNames( PROPERTY_UUID );
-        q.setRowCount( 10000 );
-        QueryResult<OrderedRows<String, String, UUID>> r = q.execute();
-        Rows<String, String, UUID> rows = r.get();
-        for ( Row<String, String, UUID> row : rows ) {
-            ColumnSlice<String, UUID> slice = row.getColumnSlice();
-            HColumn<String, UUID> column = slice.getColumnByName( PROPERTY_UUID );
-            applications.put( row.getKey(), column.getValue() );
-        }
-        return applications;
-    }
-
-   @Override
-    public boolean setServiceProperty( String name, String value ) {
-        try {
-            cass.setColumn( cass.getUsergridApplicationKeyspace(), PROPERTIES_CF, PROPERTIES_CF,
name, value );
-            return true;
-        }
-        catch ( Exception e ) {
-            logger.error( "Unable to set property " + name + ": " + e.getMessage() );
-        }
-        return false;
-    }
-
-
-    @Override
-    public boolean deleteServiceProperty( String name ) {
-        try {
-            cass.deleteColumn( cass.getUsergridApplicationKeyspace(), PROPERTIES_CF, PROPERTIES_CF,
name );
-            return true;
-        }
-        catch ( Exception e ) {
-            logger.error( "Unable to delete property " + name + ": " + e.getMessage() );
-        }
-        return false;
-    }
-
-
-
-    @Override
-    public boolean updateServiceProperties( Map<String, String> properties ) {
-        try {
-            cass.setColumns( cass.getUsergridApplicationKeyspace(), PROPERTIES_CF, PROPERTIES_CF.getBytes(),
properties );
-            return true;
-        }
-        catch ( Exception e ) {
-            logger.error( "Unable to update properties: " + e.getMessage() );
-        }
-        return false;
-    }
-
-
-    @Override
-    public Map<String, String> getServiceProperties() {
-        try {
-            return asMap( cass.getAllColumns( cass.getUsergridApplicationKeyspace(), PROPERTIES_CF,
PROPERTIES_CF, se, se ) );
-        }
-        catch ( Exception e ) {
-            logger.error( "Unable to load properties: " + e.getMessage() );
-        }
-        return null;
-    }
-
-
-    @Override
-    public void setApplicationContext( ApplicationContext applicationContext ) throws BeansException
{
-        this.applicationContext = applicationContext;
-    }
-
-
-    @Override
-    public long performEntityCount() {
-        throw new UnsupportedOperationException("Not supported in v1");
-    }
-
-
-    public void setCounterUtils( CounterUtils counterUtils ) {
-        this.counterUtils = counterUtils;
-    }
-
-
-    static final UUID MANAGEMENT_APPLICATION_ID = new UUID( 0, 1 );
-    static final UUID DEFAULT_APPLICATION_ID = new UUID( 0, 16 );
-
-    @Override
-    public UUID getManagementAppId() {
-        return MANAGEMENT_APPLICATION_ID;
-    }
-
-    @Override
-    public void refreshIndex() {
-        throw new UnsupportedOperationException("Not supported.");
-    }
-
-    @Override
-    public void flushEntityManagerCaches() {
-        // no-op
-    }
-
-    @Override
-    public void rebuildCollectionIndex(UUID appId, String collection, boolean reverse, ProgressObserver
po) throws Exception {
-        throw new UnsupportedOperationException("Not supported.");
-    }
-
-    @Override
-    public void rebuildInternalIndexes(ProgressObserver po) throws Exception {
-        throw new UnsupportedOperationException("Not supported.");
-    }
-
-    @Override
-    public void rebuildAllIndexes(ProgressObserver po) throws Exception {
-        throw new UnsupportedOperationException("Not supported.");
-    }
-
-    @Override
-    public void rebuildApplicationIndexes(UUID appId, ProgressObserver po) throws Exception
{
-        throw new UnsupportedOperationException("Not supported.");
-    }
-
-    @Override
-    public void addIndex(UUID appId, String suffix,final int shards,final int replicas,final
String consistency) {
-        throw new UnsupportedOperationException("Not supported in v1");
-    }
-
-    @Override
-    public Health getEntityStoreHealth() {
-        throw new UnsupportedOperationException("Not supported in v1.");
-    }
-
-
-    @Override
-    public Health getIndexHealth() {
-        return null;
-    }
-
-
-    @Override
-    public Entity restoreApplication(UUID applicationId) throws Exception {
-        throw new UnsupportedOperationException("Not supported in v1");
-    }
-
-    @Override
-    public Map<String, UUID> getDeletedApplications() throws Exception {
-        throw new UnsupportedOperationException("Not supported in v1");
-    }
-
-    public Entity createApplicationV2( String organizationName, String name ) throws Exception
{
-        throw new UnsupportedOperationException("Not supported in v1");
-    }
-
-    @Override
-    public Entity initializeApplicationV2(
-        String orgName, UUID appId, String appName, Map<String, Object> props) throws
Exception {
-        throw new UnsupportedOperationException("Not supported in v1");
-    }
-
-    @Override
-    public Entity createApplicationV2(
-        String organizationName, String name, Map<String, Object> properties) throws
Exception {
-        throw new UnsupportedOperationException("Not supported in v1");
-    }
-
-}


Mime
View raw message