// String indexName = metadata.getIndexName();
// String filter = getFilter();
Metamodel metaModel = kunderaMetadata.getApplicationMetadata().getMetamodel(getPersistenceUnit());
EntityType entityType = metaModel.entity(entityClass);
if (null == filter)
{
List<String> clauses = new ArrayList<String>();
addDiscriminatorClause(clauses, entityType);
return;
}
List<String> clauses = tokenize(filter, INTER_CLAUSE_PATTERN,true);
// parse and structure for "between" clause , if present, else it will
// return original clause
/*int i=0;
String temp=null;
while(clauses.iterator().hasNext())
{
if(clauses.get(i).equals("AND") || clauses.get(i).equals("OR") || clauses.get(i).equals("BETWEEN"))
temp=" "+clauses.get(i)+" ";
clauses.set(i, temp);
i++;
}*/
clauses = parseFilterForBetweenClause(clauses);
// clauses must be alternate Inter and Intra combination, starting with
// Intra.
boolean newClause = true;
for (String clause : clauses)
{
if(Arrays.asList(INTER_CLAUSE_OPERATORS).contains(clause.toUpperCase().trim()) || (clause.startsWith("(") && clause.endsWith(")")))
{
filtersQueue.add(clause.toUpperCase().trim());
newClause = true;
}
else if (newClause)
{
List<String> tokens = tokenize(clause, INTRA_CLAUSE_PATTERN,false);
if (tokens.size() != 3)
{
throw new PersistenceException("bad jpa query: " + clause);
}
// strip alias from property name
String property = tokens.get(0);
if (property.indexOf(".") > 0)
{
property = property.substring((entityAlias + ".").length());
}
String columnName = null;
try
{
columnName = ((AbstractAttribute) entityType.getAttribute(property)).getJPAColumnName();
}
catch (IllegalArgumentException iaex)
{
logger.warn("No column found by this name : " + property + " checking for embeddedfield");
}