Example usage for org.hibernate Query setLong

List of usage examples for org.hibernate Query setLong

Introduction

In this page you can find the example usage for org.hibernate Query setLong.

Prototype

@Deprecated
@SuppressWarnings("unchecked")
default Query<R> setLong(String name, long val) 

Source Link

Document

Bind a named long-valued parameter.

Usage

From source file:com.appeligo.alerts.PendingAlert.java

License:Apache License

@SuppressWarnings("unchecked")
public static List<PendingAlert> getManualAlertsForUser(User user) {
    Permissions.checkUser(user);//from  w  w  w.ja  v  a  2 s.  co  m
    Session session = getSession();
    Query query = session.getNamedQuery("PendingAlert.getManualAlertsForUser");
    query.setLong("userId", user.getUserId());
    return query.list();
}

From source file:com.appeligo.search.entity.Friend.java

License:Apache License

public static Friend findByInvitee(long id, User user) {
    Session session = getSession();// w w  w.j a  v  a 2  s  .c o  m
    Query query = session.getNamedQuery("Friend.getByInvitee");
    query.setLong("id", id);
    query.setEntity("user", user);
    return (Friend) query.uniqueResult();
}

From source file:com.appeligo.search.entity.Friend.java

License:Apache License

public static Friend findByInviter(long id, User user) {
    Session session = getSession();/*from   ww w  .  j  a v a  2 s.  c  o m*/
    Query query = session.getNamedQuery("Friend.getByInviter");
    query.setLong("id", id);
    query.setEntity("user", user);
    return (Friend) query.uniqueResult();
}

From source file:com.cabable.inventory.db.RelationshipDAO.java

public int delete(Relationship relationship) {
    Query query = namedQuery("Relationship.delete");
    query.setLong("id", relationship.getId());
    return query.executeUpdate();
}

From source file:com.cloud.bridge.util.QueryHelper.java

License:Open Source License

public static void bindParameters(Query query, Object[] params) {
    int pos = 0;/*ww w .  j  a  v  a2  s .  c om*/
    if (params != null && params.length > 0) {
        for (Object param : params) {
            if (param instanceof Byte)
                query.setByte(pos++, ((Byte) param).byteValue());
            else if (param instanceof Short)
                query.setShort(pos++, ((Short) param).shortValue());
            else if (param instanceof Integer)
                query.setInteger(pos++, ((Integer) param).intValue());
            else if (param instanceof Long)
                query.setLong(pos++, ((Long) param).longValue());
            else if (param instanceof Float)
                query.setFloat(pos++, ((Float) param).floatValue());
            else if (param instanceof Double)
                query.setDouble(pos++, ((Double) param).doubleValue());
            else if (param instanceof Boolean)
                query.setBoolean(pos++, ((Boolean) param).booleanValue());
            else if (param instanceof Character)
                query.setCharacter(pos++, ((Character) param).charValue());
            else if (param instanceof Date)
                query.setDate(pos++, (Date) param);
            else if (param instanceof Calendar)
                query.setCalendar(pos++, (Calendar) param);
            else if (param instanceof CalendarDateParam)
                query.setCalendarDate(pos++, ((CalendarDateParam) param).dateValue());
            else if (param instanceof TimestampParam)
                query.setTimestamp(pos++, ((TimestampParam) param).timestampValue());
            else if (param instanceof TimeParam)
                query.setTime(pos++, ((TimeParam) param).timeValue());
            else if (param instanceof String)
                query.setString(pos++, (String) param);
            else if (param instanceof TextParam)
                query.setText(pos++, ((TextParam) param).textValue());
            else if (param instanceof byte[])
                query.setBinary(pos++, (byte[]) param);
            else if (param instanceof BigDecimal)
                query.setBigDecimal(pos++, (BigDecimal) param);
            else if (param instanceof BigInteger)
                query.setBigInteger(pos++, (BigInteger) param);
            else if (param instanceof Locale)
                query.setLocale(pos++, (Locale) param);
            else if (param instanceof EntityParam)
                query.setEntity(pos++, ((EntityParam) param).entityValue());
            else if (param instanceof Serializable)
                query.setSerializable(pos++, (Serializable) param);
            else
                query.setEntity(pos++, param);
        }
    }
}

From source file:com.connexience.server.model.datasets.DatasetsUtils.java

License:Open Source License

/** Remove all values for a JSON multiple value data item */
private static void removeJsonMultipleValueData(Session session, JsonMultipleValueItem item)
        throws ConnexienceException {
    Query q = session.createSQLQuery("delete from datasetjson where itemid=:itemid");
    q.setLong("itemid", item.getId());
    q.executeUpdate();//w  ww .  j a va 2 s  . c o  m
}

From source file:com.connexience.server.model.datasets.DatasetsUtils.java

License:Open Source License

private static void removeMultipleValueDataRow(Session session, JsonMultipleValueItem item, long rowId)
        throws ConnexienceException {
    Query q = session.createSQLQuery("delete from datasetjson where id=:rowid");
    q.setLong("rowid", rowId);
    q.executeUpdate();//from   w  w  w . j a v  a2s.c o m
}

From source file:com.connexience.server.model.datasets.DatasetsUtils.java

License:Open Source License

/** Update some JSON data in a JsonMultipleValueData object */
private static void updateMultipleValueData(Session session, JsonMultipleValueItem item, long rowId,
        Object data) throws ConnexienceException {
    Query q = session.createQuery("from JsonDataRow as obj where obj.id=:rowId and obj.itemId=:itemId");
    q.setLong("rowId", rowId);
    q.setLong("itemId", item.getId());
    List results = q.list();// w w w .  j  av  a 2s.c  o m
    if (results.size() == 1) {
        JsonDataRow row = (JsonDataRow) results.get(0);

        if (data instanceof JSONObject) {
            // JSON object has been sent
            try {
                JSONObject js = (JSONObject) data;
                JSONObject updateJson = new JSONObject();
                Iterator keys = js.keys();
                String key;
                while (keys.hasNext()) {
                    key = (String) keys.next().toString();
                    if (!key.startsWith("_")) {
                        updateJson.put(key, js.get(key));
                    }
                }
                row.setStringValue(updateJson.toString());

            } catch (Exception e) {
                throw new ConnexienceException("Error creating JSON data row for Json data: " + e.getMessage(),
                        e);
            }

        } else if (data instanceof String) {
            // Plain text sent
            try {
                JSONObject js = new JSONObject((String) data);
                JSONObject updateJson = new JSONObject();
                Iterator keys = js.keys();
                String key;
                while (keys.hasNext()) {
                    key = (String) keys.next().toString();
                    if (!key.startsWith("_")) {
                        updateJson.put(key, js.get(key));
                    }
                }
                row.setStringValue(updateJson.toString());

            } catch (Exception e) {
                throw new ConnexienceException(
                        "Error creating JSON data row for String data: " + e.getMessage(), e);
            }

        } else if (data instanceof JSONContainer) {
            // JSONContainer data
            try {
                JSONObject js = new JSONObject(((JSONContainer) data).getStringData());
                JSONObject updateJson = new JSONObject();
                Iterator keys = js.keys();
                String key;
                while (keys.hasNext()) {
                    key = (String) keys.next().toString();
                    if (!key.startsWith("_")) {
                        updateJson.put(key, js.get(key));
                    }
                }
                row.setStringValue(updateJson.toString());

            } catch (Exception e) {
                throw new ConnexienceException(
                        "Error creating JSON data row for JsonContainer data: " + e.getMessage(), e);
            }
        }

        if (row != null) {
            row.setCollectionTime(new Date());
            session.update(row);
        } else {
            throw new ConnexienceException("Error saving JSON data row: Unsupported data");
        }
    } else {
        throw new ConnexienceException("No such row: " + rowId + " for item: " + item.getName());
    }
}

From source file:com.connexience.server.model.datasets.DatasetsUtils.java

License:Open Source License

/** Get values for a Json multiple value object */
public static JSONContainer getJsonMultipleValueData(Session session, JsonMultipleValueItem item,
        int startIndex, int maxResults, String[] filterKeys) throws ConnexienceException {
    try {//from   w  w  w  . j a  v a 2  s.co m
        Query q = session.createQuery("from JsonDataRow as obj where obj.itemId=:itemid order by obj.id asc");
        q.setLong("itemid", item.getId());

        if (startIndex >= 0) {
            q.setFirstResult(startIndex);
        }

        if (maxResults >= 0) {
            q.setMaxResults(maxResults);
        }

        List rows = q.list();
        return createResultFromList(rows, filterKeys);
    } catch (Exception ex) {
        throw new ConnexienceException("Error getting JSON values: " + ex.getMessage());
    }
}

From source file:com.connexience.server.model.datasets.DatasetsUtils.java

License:Open Source License

public static JSONContainer getJsonMultipleValueDataRow(Session session, JsonMultipleValueItem item, long rowId)
        throws ConnexienceException {
    try {//from  w w  w.j av a2s.c o m
        Query q = session.createQuery("from JsonDataRow as obj where obj.id=:rowid");
        q.setLong("rowid", rowId);
        return createResultFromList(q.list(), null);
    } catch (Exception e) {
        throw new ConnexienceException("Error getting JSON row: " + e.getMessage(), e);
    }
}