public void update(Routine updatedRoutine) throws Exception { SQLiteDatabase database = dbHelper.getWritableDatabase(); database.beginTransaction(); try { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.UK); Date date = new Date(); ContentValues values = new ContentValues(); int routineId = updatedRoutine.getId(); String[] whereArgs = new String[] {Integer.toString(routineId)}; values.put(DbHelper.ROUTINE_NAME, updatedRoutine.getName()); values.put(DbHelper.ROUTINE_DATE_UPDATED, dateFormat.format(date)); database.update(DbHelper.ROUTINES, values, DbHelper.ROUTINE_ID + "=?", whereArgs); values.clear(); database.delete(DbHelper.STEPS, DbHelper.STEP_ROUTINE_ID + "=?", whereArgs); saveSteps(updatedRoutine, database); database.setTransactionSuccessful(); } catch (Exception e) { database.endTransaction(); database.close(); throw e; } database.endTransaction(); database.close(); }
public List<Routine> selectRoutines() { List<Routine> result = new ArrayList<Routine>(); SQLiteDatabase database = dbHelper.getReadableDatabase(); String query = "SELECT ROUTINE.RTNE_ID,RTNE_NAME, SUM(STEP_SECONDS) FROM ROUTINE JOIN STEP ON STEP.RTNE_ID = ROUTINE.RTNE_ID GROUP BY ROUTINE.RTNE_ID, RTNE_NAME;"; Cursor cur = database.rawQuery(query, null); while (cur.moveToNext()) { Routine nextRoutine = new Routine(cur.getString(1), ""); nextRoutine.setId(cur.getInt(0)); nextRoutine.setDurationInSeconds(cur.getLong(2)); result.add(nextRoutine); } return result; }
private void saveSteps(Routine routine, SQLiteDatabase database) { ContentValues values = new ContentValues(); int stepId = this.selectMaxStepId() + 1; int stepOrdinal = 1; for (Step step : routine.getSteps()) { values.clear(); values.put(DbHelper.STEP_ID, stepId); values.put(DbHelper.STEP_NAME, step.getName()); values.put(DbHelper.STEP_ORDINAL, stepOrdinal); values.put(DbHelper.STEP_SECONDS, step.getDurationSeconds()); values.put(DbHelper.STEP_ROUTINE_ID, routine.getId()); stepId++; stepOrdinal++; database.insertOrThrow(DbHelper.STEPS, null, values); } }
public TriggerDefSQL( HsqlNameManager.HsqlName name, int when, int operation, boolean forEachRow, Table table, Table[] transitions, RangeVariable[] rangeVars, Expression condition, String conditionSQL, int[] updateColumns, Routine routine) { super( name, when, operation, forEachRow, table, transitions, rangeVars, condition, conditionSQL, updateColumns); this.routine = routine; this.references = routine.getReferences(); }
@Override public void insert(Routine newRoutine) throws Exception { SQLiteDatabase database = dbHelper.getWritableDatabase(); database.beginTransaction(); try { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.UK); Date date = new Date(); ContentValues values = new ContentValues(); values.put(DbHelper.ROUTINE_ID, newRoutine.getId()); values.put(DbHelper.ROUTINE_NAME, newRoutine.getName()); values.put(DbHelper.ROUTINE_DATE_CREATED, dateFormat.format(date)); values.put(DbHelper.ROUTINE_DATE_UPDATED, dateFormat.format(date)); database.insertOrThrow(DbHelper.ROUTINES, null, values); saveSteps(newRoutine, database); database.setTransactionSuccessful(); } catch (Exception ex) { database.endTransaction(); database.close(); throw ex; } database.endTransaction(); database.close(); }
public void addSpecificRoutine(Database database, Routine routine) { int signature = routine.getParameterSignature(); Type[] types = routine.getParameterTypes(); for (int i = 0; i < this.routines.length; i++) { if (routines[i].parameterTypes.length == types.length) { if (routineType == SchemaObject.PROCEDURE) { throw Error.error(ErrorCode.X_42605); } if (routines[i].isAggregate() != routine.isAggregate()) { throw Error.error(ErrorCode.X_42605); } boolean match = true; for (int j = 0; j < types.length; j++) { if (!routines[i].parameterTypes[j].equals(types[j])) { match = false; break; } } if (match) { throw Error.error(ErrorCode.X_42605); } } } if (routine.getSpecificName() == null) { HsqlName specificName = database.nameManager.newSpecificRoutineName(name); routine.setSpecificName(specificName); } else { routine.getSpecificName().parent = name; routine.getSpecificName().schema = name.schema; } routine.setName(name); routine.routineSchema = this; routines = (Routine[]) ArrayUtil.resizeArray(routines, routines.length + 1); routines[routines.length - 1] = routine; }
public void paintComponent(Graphics g) { super.paintComponent(g); int borderSize = 10; int radius = 3; double x_scale = (double) (this.getWidth() - borderSize * 2) / maxX; double y_scale = (double) (this.getHeight() - borderSize * 2) / maxY; double scale = Math.min(x_scale, y_scale); if (lastRoutine != null) { g.setColor(Color.red); for (int i = 0; i < lastRoutine.getSize(); i++) { g.fillOval( (int) (lastRoutine.getX(i) * scale - radius), (int) (lastRoutine.getY(i) * scale - radius), 2 * radius, 2 * radius); if (i != 0) { g.drawLine( (int) (lastRoutine.getX(i) * scale), (int) (lastRoutine.getY(i) * scale), (int) (lastRoutine.getX(i - 1) * scale), (int) (lastRoutine.getY(i - 1) * scale)); } } } if (currentRoutine != null) { g.setColor(Color.black); for (int i = 0; i < currentRoutine.getSize(); i++) { g.fillOval( (int) (currentRoutine.getX(i) * scale - radius), (int) (currentRoutine.getY(i) * scale - radius), 2 * radius, 2 * radius); if (i != 0) { g.drawLine( (int) (currentRoutine.getX(i) * scale), (int) (currentRoutine.getY(i) * scale), (int) (currentRoutine.getX(i - 1) * scale), (int) (currentRoutine.getY(i - 1) * scale)); } } lastRoutine = currentRoutine; } }
public void setOriginalRoutine(Routine orignalRoutine) { this.originalRoutine = orignalRoutine.copyRoutine(); maxX = orignalRoutine.getMaxX(); maxY = orignalRoutine.getMaxY(); }
public static void registerRoutine() { Routine.registerRoutine( Pattern.compile("un(s?)tag\\.(.*)", Pattern.CASE_INSENSITIVE), new UntagRoutineBuilder()); }
public Routine selectRoutine(int routineId) throws Exception { final String sql = "SELECT " + DbHelper.ROUTINES + "." + DbHelper.ROUTINE_ID + ", " + DbHelper.ROUTINE_NAME + ", " + DbHelper.STEP_ID + ", " + DbHelper.STEP_NAME + ", " + DbHelper.STEP_SECONDS + ", " + DbHelper.STEP_ORDINAL + " " + " FROM " + DbHelper.ROUTINES + " JOIN " + DbHelper.STEPS + " ON " + DbHelper.STEPS + "." + DbHelper.STEP_ROUTINE_ID + " = " + DbHelper.ROUTINES + "." + DbHelper.ROUTINE_ID + " " + " WHERE " + DbHelper.ROUTINES + "." + DbHelper.ROUTINE_ID + " = ? " + " ORDER BY " + DbHelper.STEP_ORDINAL; Routine result = null; SQLiteDatabase database = dbHelper.getReadableDatabase(); try { Cursor cur = database.rawQuery(sql, new String[] {String.format("%d", routineId)}); if (!cur.moveToFirst()) { database.close(); return result; } result = new Routine(cur.getString(1), ""); result.setId(cur.getInt(0)); long totalDuration = 0; ArrayList<Step> steps = new ArrayList<Step>(); do { Step step = new Step(); step.setId(cur.getInt(2)); step.setName(cur.getString(3)); step.setDurationSeconds(cur.getLong(4)); step.setOrdinal(cur.getInt(5)); totalDuration += step.getDurationSeconds(); steps.add(step); } while (cur.moveToNext()); result.setDurationInSeconds(totalDuration); result.setSteps(steps); database.close(); } catch (Exception e) { database.close(); throw e; } return result; }