Search in sources :

Example 11 with IntStringPair

use of com.serotonin.db.pair.IntStringPair in project ma-core-public by infiniteautomation.

the class VarNames method contextToString.

public static String contextToString(List<IntStringPair> context) {
    DataPointDao dataPointDao = DataPointDao.instance;
    StringBuilder sb = new StringBuilder();
    boolean first = true;
    for (IntStringPair ivp : context) {
        DataPointVO dp = dataPointDao.getDataPoint(ivp.getKey(), false);
        if (first)
            first = false;
        else
            sb.append(", ");
        if (dp == null)
            sb.append("?=");
        else
            sb.append(dp.getExtendedName()).append("=");
        sb.append(ivp.getValue());
    }
    return sb.toString();
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) IntStringPair(com.serotonin.db.pair.IntStringPair)

Example 12 with IntStringPair

use of com.serotonin.db.pair.IntStringPair in project ma-core-public by infiniteautomation.

the class ScriptUtils method prepareEngine.

/**
 * Prepare the Engine by adding all Global Bindings
 * @param engine
 */
public static void prepareEngine(ScriptEngine engine) {
    Bindings globalBindings = new SimpleBindings();
    // Add constants to the context.
    globalBindings.put("SECOND", Common.TimePeriods.SECONDS);
    globalBindings.put("MINUTE", Common.TimePeriods.MINUTES);
    globalBindings.put("HOUR", Common.TimePeriods.HOURS);
    globalBindings.put("DAY", Common.TimePeriods.DAYS);
    globalBindings.put("WEEK", Common.TimePeriods.WEEKS);
    globalBindings.put("MONTH", Common.TimePeriods.MONTHS);
    globalBindings.put("YEAR", Common.TimePeriods.YEARS);
    globalBindings.put(POINTS_CONTEXT_KEY, new ArrayList<String>());
    for (IntStringPair isp : Common.ROLLUP_CODES.getIdKeys(Common.Rollups.NONE)) globalBindings.put(Common.ROLLUP_CODES.getCode(isp.getKey()), isp.getKey());
    // Add in Additional Utilities with Global Scope
    globalBindings.put(DateTimeUtility.CONTEXT_KEY, new DateTimeUtility());
    globalBindings.put(UnitUtility.CONTEXT_KEY, new UnitUtility());
    // Holder for modifying timestamps of meta points, in Engine Scope so it can be modified by all
    engine.getBindings(ScriptContext.ENGINE_SCOPE).put(TIMESTAMP_CONTEXT_KEY, null);
    engine.setBindings(globalBindings, ScriptContext.GLOBAL_SCOPE);
}
Also used : IntStringPair(com.serotonin.db.pair.IntStringPair) SimpleBindings(javax.script.SimpleBindings) Bindings(javax.script.Bindings) SimpleBindings(javax.script.SimpleBindings)

Example 13 with IntStringPair

use of com.serotonin.db.pair.IntStringPair in project ma-core-public by infiniteautomation.

the class DataPointDao method getPropertiesMap.

/*
     * (non-Javadoc)
     * 
     * @see com.serotonin.m2m2.db.dao.AbstractBasicDao#getPropertiesMap()
     */
@Override
protected Map<String, IntStringPair> getPropertiesMap() {
    HashMap<String, IntStringPair> map = new HashMap<String, IntStringPair>();
    map.put("dataSourceName", new IntStringPair(Types.VARCHAR, "ds.name"));
    map.put("dataSourceTypeName", new IntStringPair(Types.VARCHAR, "ds.dataSourceType"));
    map.put("dataSourceXid", new IntStringPair(Types.VARCHAR, "ds.xid"));
    map.put("dataSourceEditPermission", new IntStringPair(Types.VARCHAR, "ds.editPermission"));
    map.put("templateName", new IntStringPair(Types.VARCHAR, "template.name"));
    map.put("templateXid", new IntStringPair(Types.VARCHAR, "template.xid"));
    return map;
}
Also used : IntStringPair(com.serotonin.db.pair.IntStringPair) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 14 with IntStringPair

use of com.serotonin.db.pair.IntStringPair in project ma-core-public by infiniteautomation.

the class UserCommentDao method getPropertiesMap.

/* (non-Javadoc)
	 * @see com.serotonin.m2m2.db.dao.AbstractBasicDao#getPropertiesMap()
	 */
@Override
protected Map<String, IntStringPair> getPropertiesMap() {
    Map<String, IntStringPair> map = new HashMap<String, IntStringPair>();
    map.put("username", new IntStringPair(Types.VARCHAR, "u.username"));
    map.put("referenceId", new IntStringPair(Types.INTEGER, "typeKey"));
    map.put("timestamp", new IntStringPair(Types.BIGINT, "ts"));
    return map;
}
Also used : IntStringPair(com.serotonin.db.pair.IntStringPair) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 15 with IntStringPair

use of com.serotonin.db.pair.IntStringPair in project ma-core-public by infiniteautomation.

the class AbstractBasicDao method getQueryColumn.

/**
 * @param argument
 * @return
 */
public SQLQueryColumn getQueryColumn(String prop) {
    boolean mapped = false;
    Set<String> properties = this.propertyTypeMap.keySet();
    String dbCol = prop;
    Integer sqlType;
    if (propertiesMap.containsKey(prop)) {
        IntStringPair pair = propertiesMap.get(prop);
        dbCol = pair.getValue();
        sqlType = pair.getKey();
        mapped = true;
    } else {
        sqlType = this.propertyTypeMap.get(dbCol);
    }
    if (mapped || properties.contains(dbCol)) {
        if (mapped)
            return new SQLQueryColumn(dbCol, sqlType);
        else
            return new SQLQueryColumn(this.tablePrefix + dbCol, sqlType);
    }
    // No Column matches...
    throw new ShouldNeverHappenException("No column found for: " + prop);
}
Also used : SQLQueryColumn(com.infiniteautomation.mango.db.query.SQLQueryColumn) IntStringPair(com.serotonin.db.pair.IntStringPair) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException)

Aggregations

IntStringPair (com.serotonin.db.pair.IntStringPair)31 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)10 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)9 JsonArray (com.serotonin.json.type.JsonArray)6 JsonObject (com.serotonin.json.type.JsonObject)6 LinkedHashMap (java.util.LinkedHashMap)6 ScriptException (javax.script.ScriptException)5 DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)4 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)4 ScriptPermissions (com.serotonin.m2m2.rt.script.ScriptPermissions)4 User (com.serotonin.m2m2.vo.User)4 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)4 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)3 JsonValue (com.serotonin.json.type.JsonValue)3 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)3 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)3 IDataPointValueSource (com.serotonin.m2m2.rt.dataImage.IDataPointValueSource)3 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)3 ResultTypeException (com.serotonin.m2m2.rt.script.ResultTypeException)3