values.put(TestModel.FIRST_NAME.getName(), "A"); values.put(TestModel.LAST_NAME.getName(), "B"); values.put(TestModel.BIRTHDAY.getName(), 1); // Putting an int where long expected values.put(TestModel.IS_HAPPY.getName(), 1); // Putting an int where boolean expected values.put(TestModel.SOME_DOUBLE.getName(), 1); // Putting an int where double expected assertTrue(checkTypesOn.get(TestModel.FIRST_NAME.getName()) instanceof String); assertTrue(checkTypesOn.get(TestModel.LAST_NAME.getName()) instanceof String); assertTrue(checkTypesOn.get(TestModel.BIRTHDAY.getName()) instanceof Long); assertTrue(checkTypesOn.get(TestModel.IS_HAPPY.getName()) instanceof Boolean); assertTrue(checkTypesOn.get(TestModel.SOME_DOUBLE.getName()) instanceof Double);
/** * Utility method to get the rowid of the model, if it exists. * * @return {@value #NO_ID} if this model was not added to the database */ public long getRowId() { Long id = null; String idPropertyName = getRowIdProperty().getName(); if (setValues != null && setValues.containsKey(idPropertyName)) { id = (Long) setValues.get(idPropertyName); } else if (values != null && values.containsKey(idPropertyName)) { id = (Long) values.get(idPropertyName); } if (id != null) { return id; } return NO_ID; }
/** * @param rowid the new rowid for this model * @return this model instance, to allow chaining calls */ public TableModel setRowId(long rowid) { if (rowid == NO_ID) { clearValue(getRowIdProperty()); } else { if (setValues == null) { setValues = newValuesStorage(); } setValues.put(getRowIdProperty().getName(), rowid); } return this; }
assertEquals(p.getQualifiedExpression(), "testModels._id"); assertEquals(p.getExpression(), "_id"); assertEquals(p.getName(), "_id"); assertEquals("newAlias", basicAlias.getName()); assertEquals("SELECT testModels._id AS newAlias", Query.select(basicAlias).toString()); assertEquals("newTable", aliasWithTable.tableModelName.tableName); assertEquals(p.getExpression(), aliasWithTable.getExpression()); assertEquals("newAlias", aliasWithTable.getName()); assertEquals("SELECT newTable._id AS newAlias", Query.select(aliasWithTable).toString()); assertEquals(TestViewModel.class, asSelectionFromTableNoAlias.tableModelName.modelClass); assertEquals(TestViewModel.VIEW.getName(), asSelectionFromTableNoAlias.tableModelName.tableName); assertEquals(basicAlias.getName(), asSelectionFromTableNoAlias.getExpression()); assertEquals(basicAlias.getName(), asSelectionFromTableNoAlias.getName()); assertFalse(asSelectionFromTableNoAlias.hasAlias()); assertEquals("SELECT testView.newAlias AS newAlias", Query.select(asSelectionFromTableNoAlias).toString()); assertEquals(TestViewModel.class, asSelectionFromTableWithAlias.tableModelName.modelClass); assertEquals(TestViewModel.VIEW.getName(), asSelectionFromTableWithAlias.tableModelName.tableName); assertEquals(basicAlias.getName(), asSelectionFromTableWithAlias.getExpression()); assertEquals("superAlias", asSelectionFromTableWithAlias.getName()); assertEquals("SELECT testView.newAlias AS superAlias", Query.select(asSelectionFromTableWithAlias).toString()); assertEquals(TestVirtualModel.ROWID.getName(), "rowid"); assertEquals(Thing.ID.getName(), "id");
/** * Utility method to get the rowid of the model, if it exists. * * @return {@value #NO_ID} if this model was not added to the database */ public long getRowId() { Long id = null; String idPropertyName = getRowIdProperty().getName(); if (setValues != null && setValues.containsKey(idPropertyName)) { id = (Long) setValues.get(idPropertyName); } else if (values != null && values.containsKey(idPropertyName)) { id = (Long) values.get(idPropertyName); } if (id != null) { return id; } return NO_ID; }
/** * @param rowid the new rowid for this model * @return this model instance, to allow chaining calls */ public TableModel setRowId(long rowid) { if (rowid == NO_ID) { clearValue(getRowIdProperty()); } else { if (setValues == null) { setValues = newValuesStorage(); } setValues.put(getRowIdProperty().getName(), rowid); } return this; }