cast a Object to a GUID

@param o Object to cast
@return casted Query Object
@throws PageException
969220
public static Object toGUId(Object o) throws PageException {
	String str = toString(o);
	if (!Decision.isGUId(str)) throw new ExpressionException("can't cast [" + str + "] to guid value");
	return str;
    }
836152
public static QueryBuilder byInstanceId(Object localId, Class entityClass){
        Validate.argumentsAreNotNull(localId, entityClass);
        return new QueryBuilder(new IdFilterDefinition(instanceId(localId, entityClass)));
    }
130247
public <D> DtoQuery<D> asDto(Class<D> dtoClass) {
    return query.asDto(dtoClass);
  }
1137032
public static short toShortValue(Object o) throws PageException {
	if (o instanceof Short) return ((Short) o).shortValue();
	else if (o instanceof CharSequence) return (short) toDoubleValue(o.toString());
	else if (o instanceof Character) return (short) (((Character) o).charValue());
	else if (o instanceof Boolean) return (short) ((((Boolean) o).booleanValue()) ? 1 : 0);
	else if (o instanceof Number) return (((Number) o).shortValue());
	else if (o instanceof Castable) return (short) ((Castable) o).castToDoubleValue();
	else if (o instanceof ObjectWrap) return toShortValue(((ObjectWrap) o).getEmbededObject());

	throw new CasterException(o, "short");
    }
1201011
@Override
    protected Object processObject(Object o) {
        if (o instanceof PGobject &&
                        ((PGobject)o).getType().equals("jsonb")) {
            return ((PGobject) o).getValue();
        }
        return super.processObject(o);
    }
196658
@Override
	public <T> PagedLater<T> paged(String object, Class<T> type, Param... params) {
		if (!object.contains("/"))
			throw new IllegalArgumentException("You can only use paged() for connection requests, eg me/friends");

		// For example if type is User.class, this will produce Paged<User>
		JavaType pagedType = mapper.getTypeFactory().constructParametricType(Paged.class, mapper.getTypeFactory().constructType(type));
			
		GraphRequest<Paged<T>> req = this.graph(object, pagedType, params);
			
		return new PagedLaterAdapter<T>(this.master, req, type);
	}
699652
public static Query toQuery(Object o, boolean duplicate, Query defaultValue) {
	try {
	    return toQuery(o, duplicate);
	}
	catch (PageException e) {
	    return defaultValue;
	}
    }
28471
@Override
    public Object getValue(Query qr, int row) throws PageException {
	if (col == null) col = qr.getColumn(getColumn());
	return QueryUtil.getValue(col, row);
    }
1086614
public static Object call(PageContext pc, String sql, Object params, Struct options, String name) throws PageException {
	PageContextImpl pci = (PageContextImpl) pc;
	lucee.runtime.tag.Query qry = (lucee.runtime.tag.Query) pci.use(lucee.runtime.tag.Query.class.getName(), "cfquery", TagLibTag.ATTRIBUTE_TYPE_FIXED);

	try {
	    try {
		qry.hasBody(true);
		// set attributes
		qry.setReturnVariable(true);
		qry.setName(StringUtil.isEmpty(name) ? "QueryExecute" : name);
		if (options != null) TagUtil.setAttributeCollection(pc, qry, null, options, TagLibTag.ATTRIBUTE_TYPE_FIXED);
		qry.setParams(params);

		int res = qry.doStartTag();
		pc.initBody(qry, res);
		pc.forceWrite(sql);
		qry.doAfterBody();
	    }
	    catch (Throwable t) {
		ExceptionUtil.rethrowIfNecessary(t);
		try {
		    qry.doCatch(t);
		}
		catch (Throwable t2) {
		    ExceptionUtil.rethrowIfNecessary(t);
		    throw Caster.toPageException(t2);
		}
	    }
	    finally {
		pc.popBody();
		qry.doFinally();
	    }
	    qry.doEndTag();
	    return qry.getReturnVariable();
	}
	finally {
	    pci.reuse(qry);
	}

    }
306450
public static Byte toByte(Object o) throws PageException {
	if (o instanceof Byte) return (Byte) o;
	return new Byte(toByteValue(o));

    }
730418
public static Query toQuery(Object o, Query defaultValue) {
	if (o instanceof Query) return (Query) o;
	else if (o instanceof ObjectWrap) {
	    return toQuery(((ObjectWrap) o).getEmbededObject(defaultValue), defaultValue);
	}
	return defaultValue;
    }
57659
public static Object call(PageContext pc, Object coll, Collection.Key methodName, Object[] args, short[] types, String[] strTypes) throws PageException {

	// look for members
	short type;
	String strType;
	Map<Key, FunctionLibFunction> members = null;
	for (int i = 0; i < types.length; i++) {
	    type = types[i];
	    strType = strTypes[i];
	    members = getMembers(pc, type);
	    FunctionLibFunction member = members.get(methodName);
	    if (member != null) {
		List<FunctionLibFunctionArg> _args = member.getArg();
		if (args.length < _args.size()) {
		    ArrayList<Ref> refs = new ArrayList<Ref>();

		    int pos = member.getMemberPosition();
		    FunctionLibFunctionArg flfa;
		    Iterator<FunctionLibFunctionArg> it = _args.iterator();
		    int glbIndex = 0, argIndex = -1;
		    while (it.hasNext()) {
			glbIndex++;
			flfa = it.next();
			if (glbIndex == pos) {
			    refs.add(new Casting(strType, type, coll));
			}
			else if (args.length > ++argIndex) { // careful, argIndex is only incremented when condition above is false
			    refs.add(new Casting(flfa.getTypeAsString(), flfa.getType(), args[argIndex]));
			}
		    }
		    return new BIFCall(coll, member, refs.toArray(new Ref[refs.size()])).getValue(pc);
		}

	    }
	}

	// do reflection
	if (pc.getConfig().getSecurityManager().getAccess(lucee.runtime.security.SecurityManager.TYPE_DIRECT_JAVA_ACCESS) == lucee.runtime.security.SecurityManager.VALUE_YES) {
	    if (!(coll instanceof Undefined)) {
		Object res = callMethod(coll, methodName, args);
		if (res != DEFAULT) return res;
	    }
	}

	// merge
	if (types.length > 1) {
	    Map<Key, FunctionLibFunction> tmp;
	    members = null;
	    for (int i = 0; i < types.length; i++) {
		tmp = getMembers(pc, types[i]);
		if (members == null) members = tmp;
		else {
		    Iterator<Entry<Key, FunctionLibFunction>> it = tmp.entrySet().iterator();
		    Entry<Key, FunctionLibFunction> e;
		    while (it.hasNext()) {
			e = it.next();
			members.put(e.getKey(), e.getValue());
		    }
		}
	    }
	}
	Set<Key> set = members.keySet();
	String msg = ExceptionUtil.similarKeyMessage(set.toArray(new Key[set.size()]), methodName.getString(), "function", "functions", "Object", true);
	throw new ExpressionException(msg);
	// throw new ExpressionException("No matching function member ["+methodName+"] found, available
	// function members are ["+
	// lucee.runtime.type.util.ListUtil.sort(CollectionUtil.getKeyList(members.keySet().iterator(),
	// ","),"textnocase","asc",",")+"]");
    }
231532
public static Query toQuery(Object o, boolean duplicate) throws PageException {

	if (o instanceof Query) {
	    if (duplicate) {
		Query src = (Query) o;
		Query trg = new QueryImpl(src.getColumnNames(), src.getRowCount(), "query");

		Collection.Key[] keys = src.getColumnNames();
		QueryColumn[] columnsSrc = new QueryColumn[keys.length];
		for (int i = 0; i < columnsSrc.length; i++) {
		    columnsSrc[i] = src.getColumn(keys[i]);
		}

		keys = trg.getColumnNames();
		QueryColumn[] columnsTrg = new QueryColumn[keys.length];
		for (int i = 0; i < columnsTrg.length; i++) {
		    columnsTrg[i] = trg.getColumn(keys[i]);
		}

		int i;
		for (int row = trg.getRecordcount(); row > 0; row--) {
		    for (i = 0; i < columnsTrg.length; i++) {
			columnsTrg[i].set(row, columnsSrc[i].get(row, null));
		    }
		}
		return trg;
	    }
	    return (Query) o;
	}
	else if (o instanceof ObjectWrap) {
	    return toQuery(((ObjectWrap) o).getEmbededObject(), duplicate);
	}
	throw new CasterException(o, "query");
    }
1233762
public static <T> T castIfSameClass(Object o, Class<T> c) {
        return o != null && o.getClass() == c ? c.cast(o) : null;
    }
261576
@Override
	public long getObjectClass(long oid) {
		FilePos oie = oidIndex.findOid(oid);
		if (oie == null) {
			throw DBLogger.newObjectNotFoundException("OID not found: " + Util.oidToString(oid));
		}
		
		try {
			fileInAP.seekPage(PAGE_TYPE.DATA, oie.getPage(), oie.getOffs());
			return DataDeSerializerNoClass.getClassOid(fileInAP);
		} catch (Exception e) {
			throw DBLogger.newObjectNotFoundException(
					"ERROR reading object: " + Util.oidToString(oid));
		}
	}
696633
public static char toCharValue(Object o) throws PageException {
	if (o instanceof Character) return ((Character) o).charValue();
	else if (o instanceof Boolean) return (char) ((((Boolean) o).booleanValue()) ? 1 : 0);
	else if (o instanceof Double) return (char) (((Double) o).doubleValue());
	else if (o instanceof Number) return (char) (((Number) o).doubleValue());
	else if (o instanceof String) {
	    String str = o.toString();
	    if (str.length() > 0) return str.charAt(0);
	    throw new ExpressionException("can't cast empty string to a char");

	}
	else if (o instanceof ObjectWrap) {
	    return toCharValue(((ObjectWrap) o).getEmbededObject());
	}
	else if (o == null) return toCharValue("");
	throw new CasterException(o, "char");
    }
1269259
public static Object toVoid(Object o) throws ExpressionException {
	if (o == null) return null;
	else if (o instanceof String && o.toString().length() == 0) return null;
	else if (o instanceof Number && ((Number) o).intValue() == 0) return null;
	else if (o instanceof Boolean && ((Boolean) o).booleanValue() == false) return null;
	else if (o instanceof ObjectWrap) return toVoid(((ObjectWrap) o).getEmbededObject(null));
	throw new CasterException(o, "void");
    }