You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by to...@apache.org on 2015/02/13 00:15:58 UTC
[03/10] incubator-usergrid git commit: First pass at removing
unnecessary 1.0 files.
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/WithinNode.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/WithinNode.java b/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/WithinNode.java
deleted file mode 100644
index 35afda6..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/WithinNode.java
+++ /dev/null
@@ -1,109 +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.query.ir;
-
-
-/**
- * Intermediate represnetation of the within operator
- *
- * @author tnine
- */
-public class WithinNode extends QueryNode {
-
- private final String propertyName;
- private final float distance;
- private final float lattitude;
- private final float longitude;
- private final QuerySlice slice;
-
-
- /**
- * @param propertyName
- * @param distance
- * @param lattitude
- * @param longitude
- */
- public WithinNode( String propertyName, float distance, float lattitude, float longitude, int nodeId ) {
- this.propertyName = propertyName;
- this.distance = distance;
- this.lattitude = lattitude;
- this.longitude = longitude;
- this.slice = new QuerySlice( "location", nodeId );
- }
-
-
- /** @return the propertyName */
- public String getPropertyName() {
- return propertyName;
- }
-
-
- /** @return the distance */
- public float getDistance() {
- return distance;
- }
-
-
- /** @return the lattitude */
- public float getLattitude() {
- return lattitude;
- }
-
-
- /** @return the longitude */
- public float getLongitude() {
- return longitude;
- }
-
-
- /** @return the slice */
- public QuerySlice getSlice() {
- return slice;
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.apache.usergrid.persistence.query.ir.QueryNode#visit(org.apache.usergrid.persistence
- * .query.ir.NodeVisitor)
- */
- @Override
- public void visit( NodeVisitor visitor ) throws Exception {
- visitor.visit( this );
- }
-
-
- @Override
- public int getCount() {
- return 1;
- }
-
-
- @Override
- public boolean ignoreHintSize() {
- return false;
- }
-
-
- @Override
- public String toString() {
- return "WithinNode [propertyName=" + propertyName + ", distance=" + distance + ", lattitude=" + lattitude
- + ", longitude=" + longitude + "]";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/AbstractScanColumn.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/AbstractScanColumn.java b/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/AbstractScanColumn.java
deleted file mode 100644
index fc4a1d6..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/AbstractScanColumn.java
+++ /dev/null
@@ -1,83 +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.query.ir.result;
-
-
-import java.nio.ByteBuffer;
-import java.util.UUID;
-import org.apache.cassandra.utils.ByteBufferUtil;
-
-
-/**
- *
- * @author: tnine
- *
- */
-public abstract class AbstractScanColumn implements ScanColumn {
-
- private final UUID uuid;
- private final ByteBuffer buffer;
-
-
- protected AbstractScanColumn( UUID uuid, ByteBuffer buffer ) {
- this.uuid = uuid;
- this.buffer = buffer;
- }
-
-
- @Override
- public UUID getUUID() {
- return uuid;
- }
-
-
- @Override
- public ByteBuffer getCursorValue() {
- return buffer == null ? null :buffer.duplicate();
- }
-
-
- @Override
- public boolean equals( Object o ) {
- if ( this == o ) {
- return true;
- }
- if ( !( o instanceof AbstractScanColumn ) ) {
- return false;
- }
-
- AbstractScanColumn that = ( AbstractScanColumn ) o;
-
- return uuid.equals(that.uuid);
-
- }
-
-
- @Override
- public int hashCode() {
- return uuid.hashCode();
- }
-
-
- @Override
- public String toString() {
- return "AbstractScanColumn{" +
- "uuid=" + uuid +
- ", buffer=" + ByteBufferUtil.bytesToHex( buffer ) +
- '}';
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/CollectionResultsLoaderFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/CollectionResultsLoaderFactory.java b/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/CollectionResultsLoaderFactory.java
deleted file mode 100644
index 2904bbc..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/CollectionResultsLoaderFactory.java
+++ /dev/null
@@ -1,41 +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.query.ir.result;
-
-
-import org.apache.usergrid.persistence.EntityManager;
-import org.apache.usergrid.persistence.index.query.Query;
-import org.apache.usergrid.persistence.index.query.Query.Level;
-import static org.apache.usergrid.persistence.index.query.Query.Level.IDS;
-import static org.apache.usergrid.persistence.index.query.Query.Level.REFS;
-
-
-/** Implementation for loading collection results */
-public class CollectionResultsLoaderFactory implements ResultsLoaderFactory {
-
- @Override
- public ResultsLoader getResultsLoader( EntityManager em, Query query, Level level ) {
- switch ( level ) {
- case IDS:
- return new IDLoader();
- case REFS:
- return new EntityRefLoader( query.getEntityType() );
- default:
- return new EntityResultsLoader( em );
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/ConnectionIndexSliceParser.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/ConnectionIndexSliceParser.java b/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/ConnectionIndexSliceParser.java
deleted file mode 100644
index 51f0c9a..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/ConnectionIndexSliceParser.java
+++ /dev/null
@@ -1,87 +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.query.ir.result;
-
-
-import java.nio.ByteBuffer;
-import java.util.UUID;
-
-import org.apache.usergrid.persistence.Schema;
-
-import me.prettyprint.hector.api.beans.DynamicComposite;
-
-
-/**
- * Parser for reading uuid connections from ENTITY_COMPOSITE_DICTIONARIES and DICTIONARY_CONNECTED_ENTITIES type
- *
- * @author tnine
- */
-public class ConnectionIndexSliceParser implements SliceParser {
-
- private final String connectedEntityType;
-
-
- /** @param connectedEntityType Could be null if we want to return all types */
- public ConnectionIndexSliceParser( String connectedEntityType ) {
- this.connectedEntityType = connectedEntityType;
- }
-
-
- /* (non-Javadoc)
- * @see org.apache.usergrid.persistence.query.ir.result.SliceParser#parse(java.nio.ByteBuffer)
- */
- @Override
- public ScanColumn parse( ByteBuffer buff ) {
- DynamicComposite composite = DynamicComposite.fromByteBuffer( buff.duplicate() );
-
- String connectedType = composite.get( 1 ).toString();
-
-
- //connection type has been defined and it doesn't match, skip it
- if ( connectedEntityType != null && !connectedEntityType.equals( connectedType ) ) {
- return null;
- }
-
- //we're checking a loopback and it wasn't specified, skip it
- if ( ( connectedEntityType != null && !connectedEntityType.equalsIgnoreCase( connectedType ) ) || Schema
- .TYPE_CONNECTION.equalsIgnoreCase( connectedType ) ) {
- return null;
- }
-
- return new ConnectionColumn( ( UUID ) composite.get( 0 ), connectedType, buff );
- // return composite;
- // return null;
- }
-
-
- public static class ConnectionColumn extends AbstractScanColumn {
-
- private final String connectedType;
-
-
- public ConnectionColumn( UUID uuid, String connectedType, ByteBuffer column ) {
- super( uuid, column );
- this.connectedType = connectedType;
- }
-
-
- /** Get the target type from teh column */
- public String getTargetType() {
- return connectedType;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/ConnectionRefLoader.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/ConnectionRefLoader.java b/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/ConnectionRefLoader.java
deleted file mode 100644
index 0419aea..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/ConnectionRefLoader.java
+++ /dev/null
@@ -1,81 +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.query.ir.result;
-
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.UUID;
-
-import org.apache.usergrid.persistence.ConnectionRef;
-import org.apache.usergrid.persistence.EntityRef;
-import org.apache.usergrid.persistence.Results;
-import org.apache.usergrid.persistence.SimpleEntityRef;
-import org.apache.usergrid.persistence.cassandra.ConnectionRefImpl;
-
-
-/**
- *
- * @author: tnine
- *
- */
-public class ConnectionRefLoader implements ResultsLoader {
-
- private final UUID sourceEntityId;
- private final String sourceType;
- private final String connectionType;
- private final String targetEntityType;
-
-
- public ConnectionRefLoader( ConnectionRef connectionRef ) {
- this.sourceType = connectionRef.getConnectingEntity().getType();
- this.sourceEntityId = connectionRef.getConnectingEntity().getUuid();
- this.connectionType = connectionRef.getConnectionType();
- this.targetEntityType = connectionRef.getConnectedEntity().getType();
- }
-
-
- @Override
- public Results getResults( List<ScanColumn> entityIds, String type ) throws Exception {
-
-
- final EntityRef sourceRef = new SimpleEntityRef( sourceType, sourceEntityId );
-
- List<ConnectionRef> refs = new ArrayList<ConnectionRef>( entityIds.size() );
-
- for ( ScanColumn column : entityIds ) {
-
- SimpleEntityRef targetRef;
-
- if ( column instanceof ConnectionIndexSliceParser.ConnectionColumn ) {
- final ConnectionIndexSliceParser.ConnectionColumn connectionColumn =
- ( ConnectionIndexSliceParser.ConnectionColumn ) column;
- targetRef = new SimpleEntityRef( connectionColumn.getTargetType(), connectionColumn.getUUID() );
- }
-
- else {
- targetRef = new SimpleEntityRef( targetEntityType, column.getUUID() );
- }
-
- final ConnectionRef ref = new ConnectionRefImpl( sourceRef, connectionType, targetRef );
-
- refs.add( ref );
- }
-
- return Results.fromConnections( refs );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/ConnectionResultsLoaderFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/ConnectionResultsLoaderFactory.java b/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/ConnectionResultsLoaderFactory.java
deleted file mode 100644
index 0e58449..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/ConnectionResultsLoaderFactory.java
+++ /dev/null
@@ -1,50 +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.query.ir.result;
-
-
-import org.apache.usergrid.persistence.ConnectionRef;
-import org.apache.usergrid.persistence.EntityManager;
-import org.apache.usergrid.persistence.index.query.Query;
-import org.apache.usergrid.persistence.index.query.Query.Level;
-import static org.apache.usergrid.persistence.index.query.Query.Level.IDS;
-import static org.apache.usergrid.persistence.index.query.Query.Level.REFS;
-
-
-/** Implementation for loading connectionResults results */
-public class ConnectionResultsLoaderFactory implements ResultsLoaderFactory {
-
- private final ConnectionRef connection;
-
-
- public ConnectionResultsLoaderFactory( ConnectionRef connection ) {
- this.connection = connection;
- }
-
-
- @Override
- public ResultsLoader getResultsLoader( EntityManager em, Query query, Level level ) {
- switch ( level ) {
- case IDS://Note that this is technically wrong. However, to support backwards compatibility with the
- // existing apis and usage, both ids and refs return a connection ref when dealing with connections
- case REFS:
- return new ConnectionRefLoader( connection );
- default:
- return new EntityResultsLoader( em );
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/ConnectionTypesIterator.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/ConnectionTypesIterator.java b/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/ConnectionTypesIterator.java
deleted file mode 100644
index e22b6b1..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/ConnectionTypesIterator.java
+++ /dev/null
@@ -1,190 +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.query.ir.result;
-
-
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.NoSuchElementException;
-import java.util.UUID;
-
-import org.apache.usergrid.persistence.Schema;
-import org.apache.usergrid.persistence.cassandra.CassandraService;
-
-import me.prettyprint.hector.api.beans.HColumn;
-
-import static org.apache.usergrid.persistence.Schema.DICTIONARY_CONNECTED_TYPES;
-import static org.apache.usergrid.persistence.Schema.DICTIONARY_CONNECTING_TYPES;
-import static org.apache.usergrid.persistence.cassandra.ApplicationCF.ENTITY_DICTIONARIES;
-import static org.apache.usergrid.persistence.cassandra.CassandraPersistenceUtils.key;
-import static org.apache.usergrid.persistence.cassandra.Serializers.*;
-
-/** Iterator to iterate all types of connections the entity participates in */
-public class ConnectionTypesIterator implements Iterator<String>, Iterable<String> {
-
- private final CassandraService cass;
- private final UUID applicationId;
- private final Object key;
- // private final UUID entityId;
- private final int pageSize;
- // private static final String dictionaryName;
-
-
- private boolean hasMore = true;
- private Object start = null;
-
- private Iterator<String> lastResults;
-
-
- /**
- * The connection types iterator.
- *
- * @param cass The cassandra service to use
- * @param applicationId The application id to use
- * @param entityId The entityId to use. Can be a source for outgoing connections, or target for incoming
- * connections
- * @param outgoing True if this is a search from source->target on the edge, false if it is a search from
- * target<-source
- * @param pageSize The page size to use for batch fetching
- */
- public ConnectionTypesIterator( CassandraService cass, UUID applicationId, UUID entityId, boolean outgoing,
- int pageSize ) {
- this.cass = cass;
- this.applicationId = applicationId;
- this.pageSize = pageSize;
-
- this.key =
- outgoing ? key( entityId, DICTIONARY_CONNECTED_TYPES ) : key( entityId, DICTIONARY_CONNECTING_TYPES );
- }
-
-
- @Override
- public Iterator<String> iterator() {
- return this;
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see java.util.Iterator#hasNext()
- */
- @Override
- public boolean hasNext() {
-
- // We've either 1) paged everything we should and have 1 left from our
- // "next page" pointer
- // Our currently buffered results don't exist or don't have a next. Try to
- // load them again if they're less than the page size
- if ( ( lastResults == null || !lastResults.hasNext() ) && hasMore ) {
- try {
- return load();
- }
- catch ( Exception e ) {
- throw new RuntimeException( "Error loading next page of indexbucket scanner", e );
- }
- }
-
- return lastResults.hasNext();
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see java.util.Iterator#next()
- */
- @Override
- public String next() {
-
- if ( !hasNext() ) {
- throw new NoSuchElementException( "There are no elements left in this iterator" );
- }
-
- return lastResults.next();
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see java.util.Iterator#remove()
- */
- @Override
- public void remove() {
- throw new UnsupportedOperationException( "You can't remove from a result set, only advance" );
- }
-
-
- /**
- * Search the collection index using all the buckets for the given collection. Load the next page. Return false if
- * nothing was loaded, true otherwise
- */
-
- public boolean load() throws Exception {
-
- // nothing left to load
- if ( !hasMore ) {
- return false;
- }
-
- // if we skip the first we need to set the load to page size +2, since we'll
- // discard the first
- // and start paging at the next entity, otherwise we'll just load the page
- // size we need
- int selectSize = pageSize + 1;
-
-
- List<HColumn<ByteBuffer, ByteBuffer>> results =
- cass.getColumns( cass.getApplicationKeyspace( applicationId ), ENTITY_DICTIONARIES, key, start, null,
- selectSize, false );
-
- // we loaded a full page, there might be more
- if ( results.size() == selectSize ) {
- hasMore = true;
-
- // set the bytebuffer for the next pass
- start = results.get( results.size() - 1 ).getName();
-
- results.remove( results.size() - 1 );
- }
- else {
- hasMore = false;
- }
-
-
- List<String> stringResults = new ArrayList<String>( results.size() );
-
- //do the parse here
- for ( HColumn<ByteBuffer, ByteBuffer> col : results ) {
- final String value = se.fromByteBuffer( col.getName() );
-
- //always ignore loopback, this is legacy data that needs cleaned up, and it doesn't belong here
- if ( !Schema.TYPE_CONNECTION.equalsIgnoreCase( value ) ) {
- stringResults.add( value );
- }
- }
-
-
- lastResults = stringResults.iterator();
-
-
- return stringResults.size() > 0;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/EmptyIterator.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/EmptyIterator.java b/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/EmptyIterator.java
deleted file mode 100644
index 933bd2a..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/EmptyIterator.java
+++ /dev/null
@@ -1,63 +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.query.ir.result;
-
-
-import java.util.Iterator;
-import java.util.Set;
-import java.util.UUID;
-
-import org.apache.usergrid.persistence.cassandra.CursorCache;
-
-
-/** Iterator that never returns results */
-public class EmptyIterator implements ResultIterator {
- @Override
- public void reset() {
- //no op
- }
-
-
- @Override
- public void finalizeCursor( CursorCache cache, UUID lastValue ) {
- //no op
- }
-
-
- @Override
- public Iterator<Set<ScanColumn>> iterator() {
- return this;
- }
-
-
- @Override
- public boolean hasNext() {
- return false;
- }
-
-
- @Override
- public Set<ScanColumn> next() {
- return null;
- }
-
-
- @Override
- public void remove() {
- throw new UnsupportedOperationException( "Not supported" );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/EntityRefLoader.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/EntityRefLoader.java b/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/EntityRefLoader.java
deleted file mode 100644
index cc24022..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/EntityRefLoader.java
+++ /dev/null
@@ -1,51 +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.query.ir.result;
-
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.usergrid.persistence.EntityRef;
-import org.apache.usergrid.persistence.Results;
-import org.apache.usergrid.persistence.SimpleEntityRef;
-
-
-public class EntityRefLoader implements ResultsLoader {
-
- private String type;
-
-
- public EntityRefLoader( String type ) {
- this.type = type;
- }
-
-
- /* (non-Javadoc)
- * @see org.apache.usergrid.persistence.query.ir.result.ResultsLoader#getResults(java.util.List)
- */
- @Override
- public Results getResults( List<ScanColumn> entityIds, String type ) throws Exception {
- Results r = new Results();
- List<EntityRef> refs = new ArrayList<EntityRef>( entityIds.size() );
- for ( ScanColumn id : entityIds ) {
- refs.add( new SimpleEntityRef( type, id.getUUID() ) );
- }
- r.setRefs( refs );
- return r;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/EntityResultsLoader.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/EntityResultsLoader.java b/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/EntityResultsLoader.java
deleted file mode 100644
index f7623f4..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/EntityResultsLoader.java
+++ /dev/null
@@ -1,47 +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.query.ir.result;
-
-
-import java.util.List;
-
-import org.apache.usergrid.persistence.EntityManager;
-import org.apache.usergrid.persistence.Results;
-
-
-/** @author tnine */
-public class EntityResultsLoader implements ResultsLoader {
-
- private EntityManager em;
-
-
- /**
- *
- */
- public EntityResultsLoader( EntityManager em ) {
- this.em = em;
- }
-
-
- /* (non-Javadoc)
- * @see org.apache.usergrid.persistence.query.ir.result.ResultsLoader#getResults(java.util.List)
- */
- @Override
- public Results getResults( List<ScanColumn> entityIds, String type ) throws Exception {
- return em.getEntities( ScanColumnTransformer.getIds( entityIds ), type );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/GeoIterator.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/GeoIterator.java b/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/GeoIterator.java
deleted file mode 100644
index 92f6f03..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/GeoIterator.java
+++ /dev/null
@@ -1,351 +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.query.ir.result;
-
-
-import java.nio.ByteBuffer;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.NoSuchElementException;
-import java.util.Set;
-import java.util.UUID;
-
-import org.apache.usergrid.persistence.cassandra.CursorCache;
-import org.apache.usergrid.persistence.geo.EntityLocationRef;
-import org.apache.usergrid.persistence.geo.GeoIndexSearcher;
-import org.apache.usergrid.persistence.geo.GeoIndexSearcher.SearchResults;
-import org.apache.usergrid.persistence.geo.model.Point;
-import org.apache.usergrid.persistence.query.ir.QuerySlice;
-
-import static org.apache.usergrid.persistence.cassandra.Serializers.*;
-
-/**
- * Simple wrapper around list results until the geo library is updated so support iteration and set returns
- *
- * @author tnine
- */
-public class GeoIterator implements ResultIterator {
-
- /**
- *
- */
- private static final String DELIM = "+";
- private static final String TILE_DELIM = "TILE";
-
- private final GeoIndexSearcher searcher;
- private final int resultSize;
- private final QuerySlice slice;
- private final LinkedHashMap<UUID, LocationScanColumn> idOrder;
- private final Point center;
- private final double distance;
- private final String propertyName;
-
- private Set<ScanColumn> toReturn;
- private Set<ScanColumn> lastLoaded;
-
- // set when parsing cursor. If the cursor has gone to the end, this will be
- // true, we should return no results
- private boolean done = false;
-
- /** Moved and used as part of cursors */
- private EntityLocationRef last;
- private List<String> lastCellsSearched;
-
- /** counter that's incremented as we load pages. If pages loaded = 1 when reset,
- * we don't have to reload from cass */
- private int pagesLoaded = 0;
-
-
- /**
- *
- */
- public GeoIterator( GeoIndexSearcher searcher, int resultSize, QuerySlice slice, String propertyName, Point center,
- double distance ) {
- this.searcher = searcher;
- this.resultSize = resultSize;
- this.slice = slice;
- this.propertyName = propertyName;
- this.center = center;
- this.distance = distance;
- this.idOrder = new LinkedHashMap<UUID, LocationScanColumn>( resultSize );
- this.lastLoaded = new LinkedHashSet<ScanColumn>( resultSize );
- parseCursor();
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Iterable#iterator()
- */
- @Override
- public Iterator<Set<ScanColumn>> iterator() {
- return this;
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see java.util.Iterator#hasNext()
- */
- @Override
- public boolean hasNext() {
- advance();
- return !done || toReturn != null;
- }
-
-
- private void advance() {
- // already loaded, do nothing
- if ( done || toReturn != null ) {
- return;
- }
-
- idOrder.clear();
- lastLoaded.clear();
-
-
- SearchResults results;
-
- try {
- results =
- searcher.proximitySearch( last, lastCellsSearched, center, propertyName, 0, distance, resultSize );
- }
- catch ( Exception e ) {
- throw new RuntimeException( "Unable to search geo locations", e );
- }
-
- List<EntityLocationRef> locations = results.entityLocations;
-
- lastCellsSearched = results.lastSearchedGeoCells;
-
- for (final EntityLocationRef location : locations) {
-
- final UUID id = location.getUuid();
-
- final LocationScanColumn locationScan = new LocationScanColumn(location);
-
- idOrder.put(id, locationScan);
- lastLoaded.add(locationScan);
-
- last = location;
- }
-
- if ( locations.size() < resultSize ) {
- done = true;
- }
-
- if ( lastLoaded.size() > 0 ) {
- toReturn = lastLoaded;
- }
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see java.util.Iterator#next()
- */
- @Override
- public Set<ScanColumn> next() {
- if ( !hasNext() ) {
- throw new NoSuchElementException();
- }
-
- Set<ScanColumn> temp = toReturn;
-
- toReturn = null;
-
- return temp;
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see java.util.Iterator#remove()
- */
- @Override
- public void remove() {
- throw new UnsupportedOperationException( "You cannot reove elements from this iterator" );
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.usergrid.persistence.query.ir.result.ResultIterator#reset()
- */
- @Override
- public void reset() {
- //only 1 iteration was invoked. Just reset the pointer rather than re-search
- if ( pagesLoaded == 1 ) {
- toReturn = lastLoaded;
- return;
- }
-
- idOrder.clear();
- lastLoaded.clear();
- lastCellsSearched = null;
- last = null;
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.apache.usergrid.persistence.query.ir.result.ResultIterator#finalizeCursor(
- * org.apache.usergrid.persistence.cassandra.CursorCache, java.util.UUID)
- */
- @Override
- public void finalizeCursor( CursorCache cache, UUID uuid ) {
-
- LocationScanColumn col = idOrder.get( uuid );
-
- if ( col == null ) {
- return;
- }
-
- final EntityLocationRef location = col.location;
-
- if ( location == null ) {
- return;
- }
-
- final int sliceHash = slice.hashCode();
-
- // get our next distance
- final double latitude = location.getLatitude();
-
- final double longitude = location.getLongitude();
-
- // now create a string value for this
- final StringBuilder builder = new StringBuilder();
-
- builder.append( uuid ).append( DELIM );
- builder.append( latitude ).append( DELIM );
- builder.append( longitude );
-
- if ( lastCellsSearched != null ) {
- builder.append( DELIM );
-
- for ( String geoCell : lastCellsSearched ) {
- builder.append( geoCell ).append( TILE_DELIM );
- }
-
- int length = builder.length();
-
- builder.delete( length - TILE_DELIM.length() - 1, length );
- }
-
- ByteBuffer buff = se.toByteBuffer( builder.toString() );
-
-
- cache.setNextCursor( sliceHash, buff );
- }
-
-
- /** Get the last cells searched in the iteraton */
- public List<String> getLastCellsSearched() {
- return Collections.unmodifiableList( lastCellsSearched );
- }
-
-
- private void parseCursor() {
- if ( !slice.hasCursor() ) {
- return;
- }
-
- String string = se.fromByteBuffer( slice.getCursor() );
-
- // was set to the end, set the no op flag
- if ( string.length() == 0 ) {
- done = true;
- return;
- }
-
- String[] parts = string.split( "\\" + DELIM );
-
- if ( parts.length < 3 ) {
- throw new RuntimeException(
- "Geo cursors must contain 3 or more parts. Incorrect cursor, please execute the query again" );
- }
-
- UUID startId = UUID.fromString( parts[0] );
- double latitude = Double.parseDouble( parts[1] );
- double longitude = Double.parseDouble( parts[2] );
-
- if ( parts.length >= 4 ) {
- String[] geoCells = parts[3].split( TILE_DELIM );
-
- lastCellsSearched = Arrays.asList( geoCells );
- }
-
- last = new EntityLocationRef( ( String ) null, startId, latitude, longitude );
- }
-
-
- private class LocationScanColumn implements ScanColumn {
-
- private final EntityLocationRef location;
-
-
- public LocationScanColumn( EntityLocationRef location ) {
- this.location = location;
- }
-
-
- @Override
- public UUID getUUID() {
- return location.getUuid();
- }
-
-
- @Override
- public ByteBuffer getCursorValue() {
- throw new UnsupportedOperationException(
- "This is not supported for location scan columns. It requires iterator information" );
- }
-
-
- @Override
- public boolean equals( Object o ) {
- if ( this == o ) {
- return true;
- }
- if ( !( o instanceof ScanColumn ) ) {
- return false;
- }
-
- ScanColumn that = ( ScanColumn ) o;
-
- return location.getUuid().equals( that.getUUID() );
- }
-
-
- @Override
- public int hashCode() {
- return location.getUuid().hashCode();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/IDLoader.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/IDLoader.java b/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/IDLoader.java
deleted file mode 100644
index e078172..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/IDLoader.java
+++ /dev/null
@@ -1,40 +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.query.ir.result;
-
-
-import java.util.List;
-
-import org.apache.usergrid.persistence.Results;
-
-
-public class IDLoader implements ResultsLoader {
-
- public IDLoader() {
- }
-
-
- /* (non-Javadoc)
- * @see org.apache.usergrid.persistence.query.ir.result.ResultsLoader#getResults(java.util.List)
- */
- @Override
- public Results getResults( List<ScanColumn> entityIds, String type ) throws Exception {
- Results r = new Results();
- r.setIds( ScanColumnTransformer.getIds( entityIds ) );
- return r;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/IntersectionIterator.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/IntersectionIterator.java b/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/IntersectionIterator.java
deleted file mode 100644
index 1fea546..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/IntersectionIterator.java
+++ /dev/null
@@ -1,170 +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.query.ir.result;
-
-
-import java.util.LinkedHashSet;
-import java.util.Set;
-import java.util.UUID;
-
-import org.apache.usergrid.persistence.cassandra.CursorCache;
-
-import com.google.common.collect.Sets;
-
-
-/**
- * An iterator that unions 1 or more subsets. It makes the assuming that sub iterators iterate from min(uuid) to
- * max(uuid)
- *
- * @author tnine
- */
-public class IntersectionIterator extends MultiIterator {
-
-
- /**
- *
- */
- public IntersectionIterator( int pageSize ) {
- super( pageSize );
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.usergrid.persistence.query.ir.result.ResultIterator#reset()
- */
- @Override
- public void doReset() {
- for ( ResultIterator itr : iterators ) {
- itr.reset();
- }
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.usergrid.persistence.query.ir.result.MergeIterator#advance()
- */
- @Override
- protected Set<ScanColumn> advance() {
- /**
- * Advance our sub iterators until the UUID's all line up
- */
-
- int size = iterators.size();
-
- if ( size == 0 ) {
- return null;
- }
-
- // edge case with only 1 iterator
- if ( size == 1 ) {
-
- ResultIterator itr = iterators.get( 0 );
-
- if ( !itr.hasNext() ) {
- return null;
- }
-
- return itr.next();
- }
-
- // begin our tree merge of the iterators
-
- return merge();
- }
-
-
- private Set<ScanColumn> merge() {
-
- Set<ScanColumn> results = new LinkedHashSet<ScanColumn>();
- ResultIterator rootIterator = iterators.get( 0 );
-
-
- //we've matched to the end
- if ( !rootIterator.hasNext() ) {
- return null;
- }
-
-
- //purposely check size first, that way we avoid another round trip if we can
- while ( results.size() < pageSize && rootIterator.hasNext() ) {
-
- Set<ScanColumn> intersection = rootIterator.next();
-
- for ( int i = 1; i < iterators.size(); i++ ) {
-
- ResultIterator joinIterator = iterators.get( i );
-
- intersection = merge( intersection, joinIterator );
-
- //nothing left short circuit, there is no point in advancing to further join iterators
- if ( intersection.size() == 0 ) {
- break;
- }
- }
-
- //now add the intermediate results and continue
- results.addAll( intersection );
- }
-
- return results;
- }
-
-
- private Set<ScanColumn> merge( Set<ScanColumn> current, ResultIterator child ) {
-
- Set<ScanColumn> results = new LinkedHashSet<ScanColumn>( pageSize );
-
- while ( results.size() < pageSize ) {
- if ( !child.hasNext() ) {
- // we've iterated to the end, reset for next pass
- child.reset();
- return results;
- }
-
-
- final Set<ScanColumn> childResults = child.next();
-
- final Set<ScanColumn> intersection = Sets.intersection( current, childResults );
-
- results.addAll( intersection );
- }
-
- return results;
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.apache.usergrid.persistence.query.ir.result.ResultIterator#finalizeCursor(
- * org.apache.usergrid.persistence.cassandra.CursorCache)
- */
- @Override
- public void finalizeCursor( CursorCache cache, UUID lastLoaded ) {
- ResultIterator itr = iterators.get( 0 );
-
- //We can only create a cursor on our root level value in the intersection iterator.
- if ( itr != null ) {
- itr.finalizeCursor( cache, lastLoaded );
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/MergeIterator.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/MergeIterator.java b/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/MergeIterator.java
deleted file mode 100644
index 8434019..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/MergeIterator.java
+++ /dev/null
@@ -1,150 +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.query.ir.result;
-
-
-import java.util.Iterator;
-import java.util.Set;
-
-
-/** @author tnine */
-public abstract class MergeIterator implements ResultIterator {
-
-
- /** kept private on purpose so advance must return the correct value */
- private Set<ScanColumn> next;
-
- /** Pointer to the last set. Equal to "next" when returned. Used to retain results after "next" is set to null */
- private Set<ScanColumn> last;
- /** The size of the pages */
- protected int pageSize;
-
- int loadCount = 0;
-
-
- /**
- *
- */
- public MergeIterator( int pageSize ) {
- this.pageSize = pageSize;
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Iterable#iterator()
- */
- @Override
- public Iterator<Set<ScanColumn>> iterator() {
- return this;
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see java.util.Iterator#hasNext()
- */
- @Override
- public boolean hasNext() {
- //if next isn't set, try to advance
- if(checkNext()){
- return true;
- }
-
-
- doAdvance();
-
-
- return checkNext();
- }
-
-
- /**
- * Single source of logic to check if a next is present.
- * @return
- */
- protected boolean checkNext(){
- return next != null && next.size() > 0;
- }
-
-
- /** Advance to the next page */
- protected void doAdvance() {
- next = advance();
-
-
- if ( next != null && next.size() > 0 ) {
- last = next;
- loadCount++;
- }
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see java.util.Iterator#next()
- */
- @Override
- public Set<ScanColumn> next() {
- if ( next == null ) {
- doAdvance();
- }
-
- Set<ScanColumn> returnVal = next;
-
- next = null;
-
- return returnVal;
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see java.util.Iterator#remove()
- */
- @Override
- public void remove() {
- throw new UnsupportedOperationException( "You can't remove from a union iterator" );
- }
-
-
- /* (non-Javadoc)
- * @see org.apache.usergrid.persistence.query.ir.result.ResultIterator#reset()
- */
- @Override
- public void reset() {
- if ( loadCount == 1 && last != null ) {
- next = last;
- return;
- }
- //clean up the last pointer
- last = null;
- //reset in the child iterators
- doReset();
- }
-
-
- /** Advance the iterator to the next value. Can return an empty set with signals no values */
- protected abstract Set<ScanColumn> advance();
-
- /** Perform the reset if required */
- protected abstract void doReset();
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/MultiIterator.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/MultiIterator.java b/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/MultiIterator.java
deleted file mode 100644
index f163f26..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/MultiIterator.java
+++ /dev/null
@@ -1,55 +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.query.ir.result;
-
-
-import java.util.ArrayList;
-import java.util.List;
-
-
-/** @author tnine */
-public abstract class MultiIterator extends MergeIterator {
-
- protected List<ResultIterator> iterators = new ArrayList<ResultIterator>();
-
-
- /**
- * @param pageSize
- */
- public MultiIterator( int pageSize ) {
- super( pageSize );
- }
-
-
- /** Add an iterator for our sub results */
- public void addIterator( ResultIterator iterator ) {
- iterators.add( iterator );
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.usergrid.persistence.query.ir.result.ResultIterator#reset()
- */
- @Override
- public void doReset() {
- for ( ResultIterator itr : iterators ) {
- itr.reset();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/OrderByIterator.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/OrderByIterator.java b/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/OrderByIterator.java
deleted file mode 100644
index ed94cd9..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/OrderByIterator.java
+++ /dev/null
@@ -1,250 +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.query.ir.result;
-
-
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
-import java.util.UUID;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.usergrid.persistence.Entity;
-import org.apache.usergrid.persistence.EntityManager;
-import org.apache.usergrid.persistence.EntityPropertyComparator;
-import org.apache.usergrid.persistence.index.query.Query;
-import org.apache.usergrid.persistence.index.query.Query.SortPredicate;
-import org.apache.usergrid.persistence.cassandra.CursorCache;
-import org.apache.usergrid.persistence.query.ir.QuerySlice;
-
-import org.apache.commons.collections.comparators.ComparatorChain;
-
-import static org.apache.usergrid.persistence.cassandra.Serializers.*;
-
-/**
- * 1) Take a result set iterator as the child 2) Iterate only over candidates and create a cursor from the candidates
- *
- * @author tnine
- */
-
-public class OrderByIterator extends MergeIterator {
-
- private static final String NAME_UUID = "uuid";
- private static final Logger logger = LoggerFactory.getLogger( OrderByIterator.class );
- private final QuerySlice slice;
- private final ResultIterator candidates;
- private final ComparatorChain subSortCompare;
- private final List<String> secondaryFields;
- private final EntityManager em;
-
- //our last result from in memory sorting
- private SortedEntitySet entries;
-
-
- /**
- * @param pageSize
- */
- public OrderByIterator( QuerySlice slice, List<Query.SortPredicate> secondary, ResultIterator candidates,
- EntityManager em, int pageSize ) {
- super( pageSize );
- this.slice = slice;
- this.em = em;
- this.candidates = candidates;
- this.subSortCompare = new ComparatorChain();
- this.secondaryFields = new ArrayList<String>( 1 + secondary.size() );
-
- //add the sort of the primary column
- this.secondaryFields.add( slice.getPropertyName() );
- this.subSortCompare
- .addComparator( new EntityPropertyComparator( slice.getPropertyName(), slice.isReversed() ) );
-
- for ( SortPredicate sort : secondary ) {
- this.subSortCompare.addComparator( new EntityPropertyComparator( sort.getPropertyName(),
- sort.getDirection() == Query.SortDirection.DESCENDING ) );
- this.secondaryFields.add( sort.getPropertyName() );
- }
-
- //do uuid sorting last, this way if all our previous sorts are equal, we'll have a reproducible sort order for
- // paging
- this.secondaryFields.add( NAME_UUID );
- this.subSortCompare.addComparator( new EntityPropertyComparator( NAME_UUID, false ) );
- }
-
-
- @Override
- protected Set<ScanColumn> advance() {
-
- ByteBuffer cursor = slice.getCursor();
-
- UUID minEntryId = null;
-
- if ( cursor != null ) {
- minEntryId = ue.fromByteBuffer( cursor );
- }
-
- entries = new SortedEntitySet( subSortCompare, em, secondaryFields, pageSize, minEntryId );
-
- /**
- * keep looping through our peek iterator. We need to inspect each forward page to ensure we have performed a
- * seek to the end of our primary range. Otherwise we need to keep aggregating. I.E if the value is a boolean
- * and we order by "true
- * asc, timestamp desc" we must load every entity that has the value "true" before sub sorting,
- * then drop all values that fall out of the sort.
- */
- while ( candidates.hasNext() ) {
-
-
- for ( ScanColumn id : candidates.next() ) {
- entries.add( id );
- }
-
- entries.load();
- }
-
-
- return entries.toIds();
- }
-
-
- @Override
- protected void doReset() {
- // no op
- }
-
-
- @Override
- public void finalizeCursor( CursorCache cache, UUID lastValue ) {
- int sliceHash = slice.hashCode();
-
- ByteBuffer bytes = ue.toByteBuffer( lastValue );
-
- if ( bytes == null ) {
- return;
- }
-
- cache.setNextCursor( sliceHash, bytes );
- }
-
-
- /** A Sorted set with a max size. When a new entry is added, the max is removed */
- public static final class SortedEntitySet extends TreeSet<Entity> {
-
- private final int maxSize;
- private final Map<UUID, ScanColumn> cursorVal = new HashMap<UUID, ScanColumn>();
- private final EntityManager em;
- private final List<String> fields;
- private final Entity minEntity;
- private final Comparator<Entity> comparator;
-
-
- public SortedEntitySet( Comparator<Entity> comparator, EntityManager em, List<String> fields, int maxSize,
- UUID minEntityId ) {
- super( comparator );
- this.maxSize = maxSize;
- this.em = em;
- this.fields = fields;
- this.comparator = comparator;
- this.minEntity = getPartialEntity( minEntityId );
- }
-
-
- @Override
- public boolean add( Entity entity ) {
-
- // don't add this entity. We get it in our scan range, but it's <= the minimum value that
- //should be allowed in the result set
- if ( minEntity != null && comparator.compare( entity, minEntity ) <= 0 ) {
- return false;
- }
-
- boolean added = super.add( entity );
-
- while ( size() > maxSize ) {
- //remove our last element, we're over size
- Entity e = this.pollLast();
- //remove it from the cursors as well
- cursorVal.remove( e.getUuid() );
- }
-
- return added;
- }
-
-
- /** add the id to be loaded, and the dynamiccomposite column that belongs with it */
- public void add( ScanColumn col ) {
- cursorVal.put( col.getUUID(), col );
- }
-
-
- private Entity getPartialEntity( UUID minEntityId ) {
- List<Entity> entities;
-
- try {
- entities = em.getPartialEntities( Collections.singletonList( minEntityId ), fields );
- }
- catch ( Exception e ) {
- logger.error( "Unable to load partial entities", e );
- throw new RuntimeException( e );
- }
-
- if ( entities == null || entities.size() == 0 ) {
- return null;
- }
-
- return entities.get( 0 );
- }
-
-
- public void load() {
- try {
- for ( Entity e : em.getPartialEntities( cursorVal.keySet(), fields ) ) {
- add( e );
- }
- }
- catch ( Exception e ) {
- logger.error( "Unable to load partial entities", e );
- throw new RuntimeException( e );
- }
- }
-
-
- /** Turn our sorted entities into a set of ids */
- public Set<ScanColumn> toIds() {
- Iterator<Entity> itr = iterator();
-
- Set<ScanColumn> columns = new LinkedHashSet<ScanColumn>( this.size() );
-
- while ( itr.hasNext() ) {
-
- UUID id = itr.next().getUuid();
-
- columns.add( cursorVal.get( id ) );
- }
-
- return columns;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/ResultIterator.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/ResultIterator.java b/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/ResultIterator.java
deleted file mode 100644
index 01a048c..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/ResultIterator.java
+++ /dev/null
@@ -1,44 +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.query.ir.result;
-
-
-import java.util.Iterator;
-import java.util.Set;
-import java.util.UUID;
-
-import org.apache.usergrid.persistence.cassandra.CursorCache;
-
-
-/**
- * Interface for iterating slice results per node. This is to be used to iterate and join or intersect values Each
- * iterator element is a set. Each set size is determined by the underlying implementation. When no sets of uuids are
- * left the iterator should fail the next statement. Note that you should not rely on the returned set being exactly
- * the same size as the specified page size. Valid sets can be returned with size >= that of the set value in the
- * underlying implementation
- *
- * @author tnine
- */
-public interface ResultIterator extends Iterable<Set<ScanColumn>>, Iterator<Set<ScanColumn>> {
-
-
- /** Reset this iterator to the start to begin iterating again */
- public void reset();
-
- /** Finalize the cursor for this results. Pass in the uuid of the last entity loaded. */
- public void finalizeCursor( CursorCache cache, UUID lastValue );
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/ResultsLoader.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/ResultsLoader.java b/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/ResultsLoader.java
deleted file mode 100644
index 955296b..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/ResultsLoader.java
+++ /dev/null
@@ -1,30 +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.query.ir.result;
-
-
-import java.util.List;
-
-import org.apache.usergrid.persistence.Results;
-
-
-/** @author tnine */
-public interface ResultsLoader {
-
- /** Load results from the list of uuids. Should return a Results entity where the query cursor can be set */
- public Results getResults( List<ScanColumn> entityIds, String type ) throws Exception;
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/ResultsLoaderFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/ResultsLoaderFactory.java b/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/ResultsLoaderFactory.java
deleted file mode 100644
index f119cb0..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/ResultsLoaderFactory.java
+++ /dev/null
@@ -1,37 +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.query.ir.result;
-
-
-import org.apache.usergrid.persistence.EntityManager;
-import org.apache.usergrid.persistence.index.query.Query;
-import org.apache.usergrid.persistence.index.query.Query.Level;
-
-
-/**
- *
- * @author: tnine
- *
- */
-public interface ResultsLoaderFactory {
-
- /**
- * Get the results loaded that will load all Ids given the results level.
- * The original query and the entity manager may be needed to load these results
- */
- public ResultsLoader getResultsLoader( EntityManager em, Query query, Level level );
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/ScanColumn.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/ScanColumn.java b/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/ScanColumn.java
deleted file mode 100644
index 289fe86..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/ScanColumn.java
+++ /dev/null
@@ -1,32 +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.query.ir.result;
-
-
-import java.nio.ByteBuffer;
-import java.util.UUID;
-
-
-/** An interface that represents a column */
-public interface ScanColumn {
-
- /** Get the uuid from the column */
- public UUID getUUID();
-
- /** Get the cursor value of this column */
- public ByteBuffer getCursorValue();
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/ScanColumnTransformer.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/ScanColumnTransformer.java b/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/ScanColumnTransformer.java
deleted file mode 100644
index 0fd35e9..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/ScanColumnTransformer.java
+++ /dev/null
@@ -1,39 +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.query.ir.result;
-
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.UUID;
-
-
-/** Simple utility to convert Scan Columns collections to lists */
-public class ScanColumnTransformer {
-
- public static List<UUID> getIds( Collection<ScanColumn> cols ) {
-
- List<UUID> ids = new ArrayList<UUID>( cols.size() );
-
- for ( ScanColumn col : cols ) {
- ids.add( col.getUUID() );
- }
-
- return ids;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/SecondaryIndexSliceParser.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/SecondaryIndexSliceParser.java b/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/SecondaryIndexSliceParser.java
deleted file mode 100644
index ea093e6..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/SecondaryIndexSliceParser.java
+++ /dev/null
@@ -1,61 +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.query.ir.result;
-
-
-import java.nio.ByteBuffer;
-import java.util.UUID;
-
-import me.prettyprint.hector.api.beans.DynamicComposite;
-
-
-/**
- * Parser for reading and writing secondary index composites
- *
- * @author tnine
- */
-public class SecondaryIndexSliceParser implements SliceParser {
-
-
- /* (non-Javadoc)
- * @see org.apache.usergrid.persistence.query.ir.result.SliceParser#parse(java.nio.ByteBuffer)
- */
- @Override
- public ScanColumn parse( ByteBuffer buff ) {
- DynamicComposite composite = DynamicComposite.fromByteBuffer( buff.duplicate() );
-
- return new SecondaryIndexColumn( ( UUID ) composite.get( 2 ), composite.get( 1 ), buff );
- }
-
-
- public static class SecondaryIndexColumn extends AbstractScanColumn {
-
- private final Object value;
-
-
- public SecondaryIndexColumn( UUID uuid, Object value, ByteBuffer buff ) {
- super( uuid, buff );
- this.value = value;
- }
-
-
- /** Get the value from the node */
- public Object getValue() {
- return this.value;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/SliceIterator.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/SliceIterator.java b/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/SliceIterator.java
deleted file mode 100644
index 2a4c3cf..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/SliceIterator.java
+++ /dev/null
@@ -1,242 +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.query.ir.result;
-
-
-import java.nio.ByteBuffer;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.Set;
-import java.util.UUID;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.usergrid.persistence.cassandra.CursorCache;
-import org.apache.usergrid.persistence.cassandra.index.IndexScanner;
-import org.apache.usergrid.persistence.exceptions.QueryIterationException;
-import org.apache.usergrid.persistence.query.ir.QuerySlice;
-
-import me.prettyprint.hector.api.beans.HColumn;
-
-
-/**
- * An iterator that will take all slices and order them correctly
- *
- * @author tnine
- */
-public class SliceIterator implements ResultIterator {
-
- private static final Logger logger = LoggerFactory.getLogger( SliceIterator.class );
-
- private final LinkedHashMap<UUID, ScanColumn> cols;
- private final QuerySlice slice;
- private final SliceParser parser;
- private final IndexScanner scanner;
- private final int pageSize;
-
- /**
- * Pointer to the uuid set until it's returned
- */
- private Set<ScanColumn> lastResult;
-
- /**
- * The pointer to the last set of parsed columns
- */
- private Set<ScanColumn> parsedCols;
-
- /**
- * counter that's incremented as we load pages. If pages loaded = 1 when reset, we don't have to reload from cass
- */
- private int pagesLoaded = 0;
-
- /**
- * Pointer to the last column we parsed
- */
- private ScanColumn last;
-
-
- /**
- * @param scanner The scanner to use to read the cols
- * @param slice The slice used in the scanner
- * @param parser The parser for the scanner results
- */
- public SliceIterator( QuerySlice slice, IndexScanner scanner, SliceParser parser ) {
- this.slice = slice;
- this.parser = parser;
- this.scanner = scanner;
- this.pageSize = scanner.getPageSize();
- this.cols = new LinkedHashMap<UUID, ScanColumn>( this.pageSize );
- this.parsedCols = new LinkedHashSet<ScanColumn>( this.pageSize );
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Iterable#iterator()
- */
- @Override
- public Iterator<Set<ScanColumn>> iterator() {
- return this;
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see java.util.Iterator#hasNext()
- */
- @Override
- public boolean hasNext() {
- if ( lastResult == null ) {
- return load();
- }
-
- return true;
- }
-
-
- private boolean load() {
- if ( !scanner.hasNext() ) {
- return false;
- }
-
- Iterator<HColumn<ByteBuffer, ByteBuffer>> results = scanner.next().iterator();
-
- cols.clear();
-
- parsedCols.clear();
-
- while ( results.hasNext() ) {
-
- ByteBuffer colName = results.next().getName().duplicate();
-
- ScanColumn parsed = parser.parse( colName );
-
- //skip this value, the parser has discarded it
- if ( parsed == null ) {
- continue;
- }
-
- last = parsed;
- cols.put( parsed.getUUID(), parsed );
- parsedCols.add( parsed );
- }
-
-
- pagesLoaded++;
-
- lastResult = parsedCols;
-
- return lastResult != null && lastResult.size() > 0;
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see java.util.Iterator#next()
- */
- @Override
- public Set<ScanColumn> next() {
- Set<ScanColumn> temp = lastResult;
- lastResult = null;
- return temp;
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see java.util.Iterator#remove()
- */
- @Override
- public void remove() {
- throw new UnsupportedOperationException( "Remove is not supported" );
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.usergrid.persistence.query.ir.result.ResultIterator#reset()
- */
- @Override
- public void reset() {
- // Do nothing, we'll just return the first page again
- if ( pagesLoaded == 1 ) {
- lastResult = parsedCols;
- return;
- }
- scanner.reset();
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.apache.usergrid.persistence.query.ir.result.ResultIterator#finalizeCursor()
- */
- @Override
- public void finalizeCursor( CursorCache cache, UUID lastLoaded ) {
- final int sliceHash = slice.hashCode();
-
- ByteBuffer bytes = null;
-
- ScanColumn col = cols.get( lastLoaded );
-
-
- //the column came from the current page
- if ( col != null ) {
- bytes = col.getCursorValue();
- }
- else {
-
- //check if we reached the end of our iterator. If we did, set the last value into the cursor. Otherwise
- //this is a bug
- if ( scanner.hasNext() ) {
- logger.error(
- "An iterator attempted to access a slice that was not iterated over. This will result in the" +
- " cursor construction failing" );
- throw new QueryIterationException(
- "An iterator attempted to access a slice that was not iterated over. This will result in the" +
- " cursor construction failing" );
- }
-
- final ByteBuffer sliceCursor = slice.getCursor();
-
- //we've never loaded anything, just re-use the existing slice
- if (last == null && sliceCursor != null ) {
- bytes = sliceCursor;
- }
-
- //use the last column we loaded. This way our scan returns nothing next time since start == finish
- else if(last != null) {
- bytes = last.getCursorValue();
- }
- }
-
-
- if ( bytes == null ) {
- return;
- }
-
- cache.setNextCursor( sliceHash, bytes );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd743734/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/SliceParser.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/SliceParser.java b/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/SliceParser.java
deleted file mode 100644
index d1ce6a1..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/query/ir/result/SliceParser.java
+++ /dev/null
@@ -1,32 +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.query.ir.result;
-
-
-import java.nio.ByteBuffer;
-
-
-/**
- * Interface to parse and compare range slices
- *
- * @author tnine
- */
-public interface SliceParser {
-
- /** Parse the slice and return it's parse type. If null is returned, the column should be considered discarded */
- public ScanColumn parse( ByteBuffer buff );
-}