Skip to content

Commit

Permalink
Fixes for Impetus#191 for hbase
Browse files Browse the repository at this point in the history
  • Loading branch information
kkmishra committed Jun 24, 2013
1 parent b46e76d commit e24d4b3
Show file tree
Hide file tree
Showing 15 changed files with 394 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.persistence.Parameter;
import javax.persistence.Query;
import javax.persistence.TemporalType;
import javax.persistence.metamodel.Attribute;
import javax.persistence.metamodel.EmbeddableType;
import javax.persistence.metamodel.EntityType;
Expand Down Expand Up @@ -65,7 +70,7 @@
*
* @author vivek.mishra
*/
public class CassQuery extends QueryImpl implements Query
public class CassQuery extends QueryImpl
{

/** the log used by this class. */
Expand Down Expand Up @@ -284,8 +289,8 @@ else if (m.getIdAttribute().equals(attribute) && compoundKey == null)
}
return columns;
}
if(log.isInfoEnabled())

if (log.isInfoEnabled())
{
log.info("No record found, returning null.");
}
Expand All @@ -311,8 +316,8 @@ private Map<Boolean, List<IndexClause>> prepareIndexClause(EntityMetadata m, boo
// check if id column are mixed with other columns or not?
String idColumn = ((AbstractAttribute) m.getIdAttribute()).getJPAColumnName();
boolean idPresent = false;
if(log.isInfoEnabled())

if (log.isInfoEnabled())
{
log.info("Preparing index clause for query {}", getJPAQuery());
}
Expand Down Expand Up @@ -651,7 +656,8 @@ else if (keyObj != null && metaModel.isEmbeddable(m.getIdAttribute().getBindable
((AbstractAttribute) keyObj.getAttribute(fieldName)).getJPAColumnName();
// compositeColumns.add(new
// BasicDBObject(compositeColumn,value));
translator.buildWhereClause(builder,((AbstractAttribute) keyObj.getAttribute(fieldName)).getBindableJavaType(),
translator.buildWhereClause(builder,
((AbstractAttribute) keyObj.getAttribute(fieldName)).getBindableJavaType(),
((AbstractAttribute) keyObj.getAttribute(fieldName)).getJPAColumnName(), value, condition);
if (partitionKey == null)
{
Expand All @@ -664,15 +670,17 @@ else if (keyObj != null && metaModel.isEmbeddable(m.getIdAttribute().getBindable
}
else if (idColumn.equals(fieldName))
{
translator.buildWhereClause(builder,((AbstractAttribute)m.getIdAttribute()).getBindableJavaType(), CassandraUtilities.getIdColumnName(m, externalProperties),
value, condition);
translator.buildWhereClause(builder,
((AbstractAttribute) m.getIdAttribute()).getBindableJavaType(),
CassandraUtilities.getIdColumnName(m, externalProperties), value, condition);
}
else
{
Metamodel metamodel = KunderaMetadataManager.getMetamodel(m.getPersistenceUnit());
Attribute attribute = ((MetamodelImpl) metamodel).getEntityAttribute(m.getEntityClazz(),
m.getFieldName(fieldName));
translator.buildWhereClause(builder, ((AbstractAttribute) attribute).getBindableJavaType(),fieldName, value, condition);
translator.buildWhereClause(builder, ((AbstractAttribute) attribute).getBindableJavaType(),
fieldName, value, condition);
allowFiltering = true;
}
}
Expand Down Expand Up @@ -711,4 +719,18 @@ private void addWhereClause(StringBuilder builder)
builder.append(CQLTranslator.ADD_WHERE_CLAUSE);
}
}

@Override
public void close()
{
// TODO Auto-generated method stub

}

@Override
public Iterator iterate()
{
// TODO Auto-generated method stub
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@
******************************************************************************/
package com.impetus.kundera.query;

import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.persistence.Parameter;
import javax.persistence.Query;
import javax.persistence.TemporalType;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -170,24 +175,19 @@ protected int onExecuteUpdate()
return 0;
}

/* @Override
public Object next()
{
// TODO Auto-generated method stub
return null;
}

@Override
public List next(int size)
public void close()
{
// TODO Auto-generated method stub
return null;

}


@Override
public void close()
public Iterator iterate()
{
// TODO Auto-generated method stub
}*/
return null;
}
}
20 changes: 20 additions & 0 deletions kundera-core/src/main/java/com/impetus/kundera/query/Query.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.impetus.kundera.query;

import java.util.Iterator;
import java.util.List;

public interface Query<E>
{
void setFetchSize(int fetchsize);

int getFetchSize();

// E next();

// List<E> next(int size);

void close();

Iterator<E> iterate();

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -1154,7 +1155,7 @@ protected String[] getColumns(final String[] columns, final EntityMetadata m)
return columnAsList.toArray(new String[] {});
}

/* public void setFetchSize(int fetchsize)
public void setFetchSize(int fetchsize)
{
this.fetchSize = fetchsize;
}
Expand All @@ -1164,9 +1165,11 @@ public int getFetchSize()
return this.fetchSize;
}

public abstract E next();
// public abstract E next();

public abstract List<E> next(int size);
// public abstract List<E> next(int size);

public abstract void close();*/
public abstract void close();

public abstract Iterator<E> iterate();
}
Original file line number Diff line number Diff line change
Expand Up @@ -784,4 +784,21 @@ public Long generate(TableGeneratorDiscriptor discriptor)
throw new KunderaException(ioex);
}
}

public void reset()
{
((HBaseDataHandler)handler).reset();
}

public Object next(EntityMetadata m)
{
return ((HBaseDataHandler)handler).next(m);
}

public boolean hasNext()
{
return ((HBaseDataHandler)handler).hasNext();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -1045,4 +1045,36 @@ public void setFetchSize(final int fetchSize)
{
((HBaseReader) hbaseReader).setFetchSize(fetchSize);
}

public Object next(EntityMetadata m)
{
Object entity = null;
HBaseData result = ((HBaseReader) hbaseReader).next();
List<HBaseData> results = new ArrayList<HBaseData>();
List output = new ArrayList();
results.add(result);
try
{
output = onRead(m.getTableName(), m.getEntityClazz(), m, output, gethTable(m.getTableName()), entity,
m.getRelationNames(), results);
}
catch (IOException e)
{
// TODO Auto-generated catch block
// TODOOOOO handle it
}

return output != null && !output.isEmpty() ? output.get(0) : output;
}

public boolean hasNext()
{
return ((HBaseReader) hbaseReader).hasNext();
}

public void reset()
{
((HBaseReader) hbaseReader).reset();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -68,7 +69,7 @@ public class HBaseQuery extends QueryImpl
* Holds reference to entity reader.
*/
private EntityReader reader = new HBaseEntityReader();

/**
* Constructor using fields.
*
Expand Down Expand Up @@ -534,24 +535,29 @@ private byte[] getBytes(String jpaFieldName, EntityMetadata m, Object value)
}
}

@Override
public Object next()
{
// TODO Auto-generated method stub
return null;
}

@Override
public List next(int size)
public void close()
{
// TODO Auto-generated method stub
return null;

}

@Override
public void close()
public Iterator iterate()
{
// TODO Auto-generated method stub

if (log.isDebugEnabled())
log.info("On getResultList() executing query: " + query);
List results = new ArrayList();

EntityMetadata m = getEntityMetadata();
Client client = persistenceDelegeator.getClient(m);

((HBaseClient)client).setFetchSize(getFetchSize());
onQuery(m, client);


return new ResultIterator((HBaseClient)client,m,persistenceDelegeator);
}
}
Loading

0 comments on commit e24d4b3

Please sign in to comment.