com.alachisoft.ncache.client.internal.util.QueryCommandHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ncache-professional-client Show documentation
Show all versions of ncache-professional-client Show documentation
NCache Professional client for java.
package com.alachisoft.ncache.client.internal.util;
import com.alachisoft.ncache.common.protobuf.KeyValueProtocol;
import com.alachisoft.ncache.common.protobuf.ValueWithTypeProtocol;
import com.alachisoft.ncache.runtime.util.NCDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class QueryCommandHelper {
public static java.util.List getValuesFromMap(Map from)
{
java.util.List keyValueList= new ArrayList();
ValueWithTypeProtocol.ValueWithType.Builder valueWithType = null;
for(Object object : from.entrySet()) {
KeyValueProtocol.KeyValue.Builder keyValue = KeyValueProtocol.KeyValue.newBuilder();
Map.Entry entry = (Map.Entry)object;
keyValue.setKey(entry.getKey().toString());
if (entry.getValue() instanceof java.util.ArrayList)
{
java.util.ArrayList list = (java.util.ArrayList)entry.getValue();
for (Object value : list)
{
if (value == null)
{
throw new IllegalArgumentException("NCache query does not support null values. ", (RuntimeException)null);
}
java.lang.Class type = value.getClass();
if (!(IndexHelper.isIndexable(type)))
{
throw new IllegalArgumentException("The provided type is not indexable.Parameter name: " + type.getName());
}
valueWithType = com.alachisoft.ncache.common.protobuf.ValueWithTypeProtocol.ValueWithType.newBuilder();
valueWithType.setValue(getValueString(value));
{
valueWithType.setType(value.getClass().getName());
}
keyValue.addValue(valueWithType);
}
}
else
{
if (entry.getValue() == null)
{
throw new IllegalArgumentException("NCache query does not support null values. ", (RuntimeException)null);
}
java.lang.Class type = entry.getValue().getClass();
if (!(IndexHelper.isIndexable(type) ))
{
throw new IllegalArgumentException("The provided type is not indexable.Parameter name: " + type.getName());
}
valueWithType = com.alachisoft.ncache.common.protobuf.ValueWithTypeProtocol.ValueWithType.newBuilder();
valueWithType.setValue(getValueString(entry.getValue()));
{
valueWithType.setType(entry.getValue().getClass().getName());
}
keyValue.addValue(valueWithType);
}
keyValueList.add(keyValue.build());
}
return keyValueList;
}
private static String getValueString(Object value)
{
String valueString = "";
//[salman] inform the user that null is not supported.
if (value == null)
{
throw new RuntimeException("NCache query does not support null values");
}
if (value instanceof String) //Asif Imam::Catter for case in-sensitive comparison
{
valueString = value.toString();
return valueString;
}
if (value instanceof java.util.Date)
{
valueString = Long.toString(new NCDateTime((java.util.Date)value).getTicks());
return valueString;
}
return value.toString();
}
}