I have a simple database, with one table (id, title and description), I want to add a column to storage a duedate. I use the info I found in Developer android migration and TypeConverters to migrate it, I can install to test, but it doesn't open the app.
I'll apreciate any help!
My entity
#Entity(tableName = "todo_db")
public class todoEnt {
#PrimaryKey(autoGenerate = true)
public int id;
#ColumnInfo(name = "title")
public String todoTitle;
#ColumnInfo(name = "description")
public String todoDescription;
#ColumnInfo(name = "dueDate")
public Date dueDate;
}
I have a Typeconverter
public class Convertors {
#TypeConverter
public static Date fromTimeStamp(Long value){
return value == null ? null : new Date(value);
}
#TypeConverter
public static Long dateToTimestamp(Date date){
if (date == null) {
return null;
} else {
return date.getTime();
}
}
}
And I added this to my database file
#TypeConverters({Convertors.class})
static final Migration M_1_2 = new Migration(1, 2) {
#Override
public void migrate(#NonNull SupportSQLiteDatabase database) {
database.execSQL("ALTER TABLE todo_db ADD duedate INTEGER");
}
};
INSTANCE = Room.databaseBuilder(
context.getApplicationContext(),
TDAHdb.class,
"tdah_database")
.addMigrations(M_1_2)
.allowMainThreadQueries()
.build();
With Room migrations, table and column names are case-sensitive. Change duedate in your migration to match the case of the #ColumnInfo name specified in the entity definition, dueDate:
database.execSQL("ALTER TABLE todo_db ADD dueDate INTEGER");
Related
I'm trying to unit-test my DAO using android-room. I have written an insert test that works properly. Unfortunately, the delete method doesn't seem to be working.
I've tried a few different setups for the test. None have worked.
Here is the DAO:
#Dao
public interface MonthlyDao {
#Insert(onConflict = OnConflictStrategy.REPLACE)
void saveAll(List<Monthly> goals);
#Insert(onConflict = OnConflictStrategy.REPLACE)
void save(Monthly goal);
#Update
void update(Monthly goal);
#Delete
void delete(Monthly goal);
#Query("SELECT * FROM Monthly")
LiveData<List<Monthly>> findAll();
#Query("SELECT * FROM monthly")
List<Monthly> findAllList();
}
Here is the Monthly entity:
#Entity
public class Monthly {
#PrimaryKey(autoGenerate = true)
private int monthlyId;
#TypeConverters(CalendarTypeConverter.class)
#ColumnInfo(name = "date")
private Calendar date = Calendar.getInstance();
#ColumnInfo(name = "title")
private String title;
#ColumnInfo(name = "description")
private String description;
#ColumnInfo(name = "completed")
private boolean completed;
...
public int getMonthlyId() {
return monthlyId;
}
public void setMonthlyId(int monthlyId) {
this.monthlyId = monthlyId;
}
And here is the test I am running:
#RunWith(AndroidJUnit4.class)
public class MonthlyTest {
private MonthlyDao monthlyDao;
private MonthlyGoalsDatabase db;
#Before
public void createDb() {
Context context = ApplicationProvider.getApplicationContext();
db = Room.inMemoryDatabaseBuilder(context, MonthlyGoalsDatabase.class).build();
monthlyDao = db.getMonthlyDao();
}
#After
public void closeDb() throws IOException {
db.close();
}
#Test
public void deleteGoal() throws Exception {
String title = "test delete title";
Calendar date = Calendar.getInstance();
date.set(Calendar.HOUR_OF_DAY, 0);
String desc = "test delete desc";
Monthly goal = new Monthly(title, date, desc);
monthlyDao.save(goal);
List<Monthly> goals = monthlyDao.findAllList();
Assert.assertThat(goals.get(0).getTitle(), equalTo(goal.getTitle()));
monthlyDao.delete(goal);
List<Monthly> updatedGoals = monthlyDao.findAllList();
Assert.assertTrue(updatedGoals.isEmpty());
}
I except the updatedGoals list to be empty, but it isn't. There is still the goal that I inserted during the test.
The method annotated with #Delete uses the primary key on the entity to know which row to delete from the database (because there could be multiple rows with the same data but different keys).
However, you're using the initial goal object that you created, which has no primary key, and thus cannot be used to indicate which row to remove.
Try doing this:
monthlyDao.save(goal);
List<Monthly> goals = monthlyDao.findAllList();
Assert.assertThat(goals.get(0).getTitle(), equalTo(goal.getTitle()));
monthlyDao.delete(goals.get(0)); // <-- Delete the goal returned from the find, which will have an ID
List<Monthly> updatedGoals = monthlyDao.findAllList();
Assert.assertTrue(updatedGoals.isEmpty());
That could easily be cleaned up a bit, but the above example only changes one line, to make it clear where the issue is.
See here for the relevant documentation.
I am trying to save a base64 value into my sqlite database using Room and for some reason it's not saving. Well, i'm assuming it's not saving because when I try to read the table that has the base64 column, it returns values for all the other columns except the base64 column. What am I doing wrong?
My Entity:
#Entity(tableName = "healthCareWorkerInformation",
foreignKeys = #ForeignKey(
entity = HealthCareWorker.class,
parentColumns = {"id"},
childColumns = {"hcwId"},
onDelete = ForeignKey.CASCADE),
indices = #Index(
value = {"hcwId"}))
public class HealthCareWorkersInformation {
#PrimaryKey(autoGenerate = true)
#ColumnInfo(name = "hcwInfoId")
private long id;
private long hcwId;
//#ColumnInfo(typeAffinity = ColumnInfo.BLOB)
private String base64Image;
private String updatedAt = new SimpleDateFormat("dd MM yyyy, HH:mm",
Locale.getDefault()).format(Calendar.getInstance().getTime());
public HealthCareWorkersInformation() {
}
#Ignore
public HealthCareWorkersInformation(long hcwId) {
this.hcwId = hcwId;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public long getHcwId() {
return hcwId;
}
public void setHcwId(long hcwId) {
this.hcwId = hcwId;
}
public String getBase64Image() {
return base64Image;
}
public void setBase64Image(String base64Image) {
this.base64Image = base64Image;
}
public String getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(String updatedAt) {
this.updatedAt = updatedAt;
}
}
My DAO:
#Insert
void insertHealthCareWorkerInformation(HealthCareWorkersInformation healthCareWorkersInformation);
#Query("SELECT * FROM HEALTHCAREWORKERINFORMATION")
LiveData<List<HealthCareWorkerInformation>> getHCWInfo();
Sample data I send through:
{"consentGiven":null,"hcwId":1,"patiendId":1,"name":"Ben","lastName":"Ben","dateOfBirth":"4/9/2019","phoneNumber":"+271234567","base64Image":"data:image/png;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAIBAQIBAQICAgICAgICAwUDAwMDAwYEBAMFBwYHBwcGBwcICQsJCAgKCAcHCg0KCgsMDAwMBwkODw0MDgsMDAz/2wBDAQICAgMDAwYDAwYMCAcIDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAz/wAARCAGQASwDASIAAhEBAxEB/8QAHgAAAgEFAQEBAAAAAAAAAAAAAgMEAAEFBgcICQr/xABSEAACAQIEAwUGAwYDBAYHCAMBAhEDIQA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gEwTYnkPvocFVQMpbQr0yLgGY5+/4xE4X3n78M0sxBZiAbA7H764LQJss0MndXqVUamqmOhuZI6fX5YXUYPU5lgIuDEc7bzMYo2Rify6jChY5mxM7+fr0wuA+u2u+mQLAC8nyNx74wbAJmvl9kKOiESiwvIEjUNzFvLFhXCTKpqkDSwuLW+/sCGDui6YUsSb3AgiMXZwCzhQ1QgA2gjoPL76YO8IsbLb/NKet+0VdAEgMSREfTyuMC16heZAEg6rrfb12+HwWGWrBckEtYAfwjb5/p"}
Everything else gets saved except for the base64 column. Please assist.
The problem is the semicolon in data:image/png;base64, in combination with " double quotes.
The most easy would be to save the base64 string without that prefix, which breaks the syntax and then assume it is all PNG images (or add a further field, which indicates the encoding of each image).
This problem isn't specific to Room, but specific to Java with SQLite, because that semicolon terminates the statement (which Room will generate). In Java, one can use ' single-quotes only for the primitive data-type char, while the complex data-type String excepts " double-quotes. The only way to get around this limitation, is not trying to save a String containing a ;.
To provide an example of what I mean:
private String base64String = null;
private String base64Type = "png";
public String getBase64Image() {
if(this.base64String != null) {
return "data:image/" + this.base64Type + ";base64," + this.base64String;
} else {
return null;
}
}
I have a Pojo object on which I store the ObjectID retrieved from Mongo.
When I print it, I can see this:
Object: { "_id" : { "$oid" : "5a4b939225c218fbe107199c" }, "organizationId" : "ORGANIZATION_ID", "organizationName" : "Organization name", "storeIds" : [] }
I want now to search using the ObjectID and I'm using this:
public String find(String dbId, String collection, ObjectId id) throws Exception {
BasicDBObject query = new BasicDBObject();
query.put("_id", id);
FindIterable<Document> search = collection.find(query);
}
The problem is that search is always null. How can I search using ObjectID? Is there a way to do without extracting the oid and creating the query in this way?
query.put("_id", new ObjectId(oid));
Try as,
import org.bson.types.ObjectId;
public DBObject findDocumentById(String id) {
BasicDBObject query = new BasicDBObject();
query.put("_id", new ObjectId(id));
DBObject dbObj = collection.findOne(query);
return dbObj;
}
You can find one or all the similar object ids.
For first, when the I fill the Pojo and ObjectID is filled with the values retrieved from MongoDB, a new object is created so, it will be different than the one retrieved.
What I have done is to create a new DataType, adding these two classes:
public class MongoOID {
#SerializedName("$oid")
private String oid;
public String getOid() {
return oid;
}
public void setOid(String oid) {
this.oid = oid;
}
}
public class MongoId {
#SerializedName("_id")
private MongoOID _id;
/**
* http://www.baeldung.com/migrating-to-java-8-date-time-api
*/
private LocalDateTime created;
/**
* http://www.baeldung.com/migrating-to-java-8-date-time-api
*/
private LocalDateTime updated;
//region Getter and Setter
public MongoOID get_id() {
return _id;
}
public void set_id(MongoOID _id) {
this._id = _id;
}
public LocalDateTime getCreated() {
return created;
}
public void setCreated(LocalDateTime created) {
this.created = created;
}
public LocalDateTime getUpdated() {
return updated;
}
public void setUpdated(LocalDateTime updated) {
this.updated = updated;
}
//endregion
}
So, on my Pojo, I replaced ObjectId _id with MongoID _id and I'm able to read the proper ID.
When I use this ID to query mongo, I simply use this:
BasicDBObject query = new BasicDBObject();
query.put("_id", new ObjectId(id));
where id is a String and it is :
organization.get_id().getOid()
I'm not sure this is the better way (and probably the correct neither) but it works. Unfortunately, I do not have the creation timestamp so I have had to add two key to my document (created and updated).
I have made restful API Using java hibernate jersery Framework.
I have to post data I have done it but I'm missing with one of the column that is MealTypeName.
Here is my DAO Class:
public class MealTypeDAO {
public void addMealType( MealType bean) {
Session session = SessionUtil.getSession();
Transaction tx = session.beginTransaction();
addMealType(session, bean);
tx.commit();
session.close();
}
private void addMealType(Session session, MealType bean){
MealType mealType = new MealType();
mealType.setMealTypename(bean.getMealTypename());
mealType.setModifiedon(bean.getModifiedon());
mealType.setModifiedby(bean.getModifiedby());
session.save(mealType);
}
Here is my resource class:
public class MealTypeResource {
#POST
#Path("/create")
#Consumes("application/json")
public Response addMealType(MealType meal){
meal.setMealTypename(meal.getMealTypename());
meal.setModifiedon(meal.getModifiedon());
meal.setModifiedby(meal.getModifiedby());
MealTypeDAO dao = new MealTypeDAO();
dao.addMealType(meal);
return Response.ok().build();
}
#GET
#Produces("application/json")
public Response getMealType() {
MealTypeDAO dao = new MealTypeDAO();
List mealTypes = dao.getMealType();
String json = new Gson().toJson(mealTypes);
return Response.ok().entity(json.toString()).build();
}
This is my entity class:
public class MealType {
#Id
#GeneratedValue(strategy=GenerationType.IDENTITY)
private int MealTypeId;
#Column
private String MealTypename;
#Column
private int modifiedby;
#Column
private String modifiedon;
public int getMealTypeId() {
return MealTypeId;
}
public void setMealTypeId(int mealTypeId) {
MealTypeId = mealTypeId;
}
public String getMealTypename() {
return MealTypename;
}
public void setMealTypename(String mealTypename) {
MealTypename = mealTypename;
}
public int getModifiedby() {
return modifiedby;
}
public void setModifiedby(int modifiedby) {
this.modifiedby = modifiedby;
}
public String getModifiedon() {
return modifiedon;
}
public void setModifiedon(String modifiedon) {
this.modifiedon = modifiedon;
}
MySQL DB:
CREATE TABLE `mealtype`(`Mealtypeid` int(11) NOT NULL AUTO_INCREMENT,`MealTypename` varchar(20) DEFAULT NULL,`modifiedby` int(11) NOT NULL,`modifiedon` datetime NOT NULL,PRIMARY KEY (`Mealtypeid`)) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;
Now M posting these data in JSON FORMAT From POSTMAN:
{"MealTypeId":14,"MealTypename":"adsdf","modifiedby":1,"modifiedon":"2000-01-01 00:00:00"}
And M getting these data:
{"MealTypeId":14,"modifiedby":1,"modifiedon":"2000-01-01 00:00:00"}
MealTypename is missing. How so? Can someone help me out?
You are using names with the first letter in the upper case MealTypename — this is a reason.
The getter with name getMealTypename is used for a JSON property mealTypename (not MealTypename):
public String getMealTypename() {
return MealTypename;
}
You need to specify a JSON property name:
#JsonProperty("MealTypename") — for Jackson
#SerializedName("MealTypename") — for Gson
You need to put this annotation to the field or getter of the class which you mapping to JSON (MealType).
And use the standard Java naming convention.
public class MealType {
#Id
#GeneratedValue(strategy=GenerationType.IDENTITY)
private int mealTypeId;
#Column
private String mealTypename;
}
And this looks really strange:
meal.setMealTypename(meal.getMealTypename());
meal.setModifiedon(meal.getModifiedon());
meal.setModifiedby(meal.getModifiedby());
Can you provide an example for mapping collections using datastax api annotations to use Map.
class pojo {
#PartitionKey(value = 0)
#Column(name = "user_id")
String userId;
#Column(name = "attributes")
// How to map it
Map<String, String> attributes;
}
error log :
2015-08-03 16:33:34,568 INFO com.jpma.jpmc.slot.persistance.DAOFactory main - Cassandra Cluster Details: ConnectionCfg [userName=test, password=test, port=9042, seeds=[Ljava.lang.String;#1a85bd75, keySpace=test]
java.lang.Class
2015-08-03 16:33:34,646 DEBUG com.datastax.driver.mapping.EntityMapper main - Preparing query INSERT INTO "test"."user_event_date"("user_id","entry_date","entry_time","app","attributes","user_ip","user_authschemes") VALUES (?,?,?,?,?,?,?);
com.datastax.driver.core.exceptions.InvalidQueryException: Unknown identifier attributes
Based on the error message you are seeing, I'm guessing that attributes is not defined in your table definition. Would you mind editing your post with that?
But when I build my CQL table like this (note the compound partition key of itemid and version):
CREATE TABLE products.itemmaster (
itemid text,
version int,
productid uuid,
supplierskumap map<uuid, text>,
PRIMARY KEY ((itemid,version), productid)
);
...insert this row:
INSERT INTO products.itemmaster (itemid,version,productid,supplierskumap)
VALUES ('item1',1,26893749-dcfc-42c7-892c-bee8c9cff630,
{1351f82f-5dc5-4328-82f4-962429c92a2b:'86CCG123'});
...and I build my POJO like this:
#Table(keyspace = "products", name = "itemmaster")
public class Product {
#PartitionKey(0)
private String itemid;
#PartitionKey(1)
private int version;
#ClusteringColumn
private UUID productid;
#Column(name="supplierskumap")
private Map<UUID,String> suppliersku;
public UUID getProductid() {
return productid;
}
public void setProductid(UUID _productid) {
this.productid = _productid;
}
public int getVersion() {
return this.version;
}
public void setVersion(int _version)
{
this.version = _version;
}
public String getItemid() {
return itemid;
}
public void setItemid(String _itemid) {
this.itemid = _itemid;
}
public Map<UUID, String> getSuppliersku() {
return suppliersku;
}
public void setSuppliersku(Map<UUID, String> _suppliersku) {
this.suppliersku = _suppliersku;
}
}
...with this constructor and getProd method on my data access object (dao):
public ProductsDAO()
{
session = connect(CASSANDRA_NODES, USERNAME, PASSWORD);
prodMapper = new MappingManager(session).mapper(Product.class);
}
public Product getProd(String itemid, int version, UUID productid) {
return prodMapper.get(itemid,version,sku);
}
...then this main class successfully queries my table and maps my Map:
private static void main(String[] args) {
ProductsDAO dao = new ProductsDAO();
Product prod = dao.getProd("item1", 1, UUID.fromString("26893749-dcfc-42c7-892c-bee8c9cff630"));
System.out.println(
prod.getProductid() + " - " +
prod.getItemid() + " - " +
prod.getSuppliersku().get(UUID.fromString("1351f82f-5dc5-4328-82f4-962429c92a2b")));
dao.closeCassandra();
}
...and produces this output:
26893749-dcfc-42c7-892c-bee8c9cff630 - item1 - 86CCG123
NOTE: Edit made to the above example to support a compound partition key.