Skip to content

Commit

Permalink
Merge pull request #8 from nikhil-jagmalani/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
sanketsarang authored Jan 15, 2019
2 parents 84e65ef + 300cfe4 commit e75434c
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 83 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.blobcity</groupId>
<artifactId>db-java-adapter</artifactId>
<version>1.2.8</version>
<version>1.2.9</version>
<packaging>jar</packaging>

<name>BlobCity DB Java Adapter</name>
Expand Down
164 changes: 82 additions & 82 deletions src/main/java/com/blobcity/db/DbQueryResponse.java
Original file line number Diff line number Diff line change
@@ -1,82 +1,82 @@
/*
* Copyright 2014, BlobCity iSolutions Pvt. Ltd.
*/
package com.blobcity.db;

import com.blobcity.db.exceptions.DbOperationException;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
import java.util.List;

/**
* Class to wrap responses from the database for internal representation before it gets returned to the client
*
* @author Karun AB
*/
class DbQueryResponse {

// Ack code
private final int ackCode;
// Select keys
private final List keys;
// Contains
private final boolean contains;
// Error handling
private final String errorCode;
private final String errorCause;
// Response data
private final JsonElement payload;

public DbQueryResponse(final String response) {
final JsonObject jsonObj = new JsonParser().parse(response).getAsJsonObject();

ackCode = jsonObj.get(QueryConstants.ACK).getAsInt();
keys = new Gson().fromJson(jsonObj.get(QueryConstants.KEYS), new TypeToken<List>() {
}.getType());

final JsonElement containsElement = jsonObj.get(QueryConstants.CONTAINS);
contains = containsElement != null ? jsonObj.get(QueryConstants.CONTAINS).getAsBoolean() : false;

final JsonElement codeElement = jsonObj.get(QueryConstants.CODE);
errorCode = codeElement != null ? jsonObj.get(QueryConstants.CODE).getAsString() : null;
final JsonElement causeElement = jsonObj.get(QueryConstants.CAUSE);
errorCause = causeElement != null ? jsonObj.get(QueryConstants.CAUSE).getAsString() : null;

payload = jsonObj.get(QueryConstants.PAYLOAD);
}

public int getAckCode() {
return ackCode;
}

public boolean isSuccessful() {
return ackCode == 1;
}

public List getKeys() {
return keys;
}

public boolean contains() {
return contains;
}

public String getErrorCode() {
return errorCode;
}

public String getErrorCause() {
return errorCause;
}

public DbOperationException createException() {
return new DbOperationException(errorCode, errorCause);
}

public JsonElement getPayload() {
return payload;
}
}
/*
* Copyright 2014, BlobCity iSolutions Pvt. Ltd.
*/
package com.blobcity.db;

import com.blobcity.db.exceptions.DbOperationException;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
import java.util.List;

/**
* Class to wrap responses from the database for internal representation before it gets returned to the client
*
* @author Karun AB
*/
public class DbQueryResponse {

// Ack code
private final int ackCode;
// Select keys
private final List keys;
// Contains
private final boolean contains;
// Error handling
private final String errorCode;
private final String errorCause;
// Response data
private final JsonElement payload;

public DbQueryResponse(final String response) {
final JsonObject jsonObj = new JsonParser().parse(response).getAsJsonObject();

ackCode = jsonObj.get(QueryConstants.ACK).getAsInt();
keys = new Gson().fromJson(jsonObj.get(QueryConstants.KEYS), new TypeToken<List>() {
}.getType());

final JsonElement containsElement = jsonObj.get(QueryConstants.CONTAINS);
contains = containsElement != null ? jsonObj.get(QueryConstants.CONTAINS).getAsBoolean() : false;

final JsonElement codeElement = jsonObj.get(QueryConstants.CODE);
errorCode = codeElement != null ? jsonObj.get(QueryConstants.CODE).getAsString() : null;
final JsonElement causeElement = jsonObj.get(QueryConstants.CAUSE);
errorCause = causeElement != null ? jsonObj.get(QueryConstants.CAUSE).getAsString() : null;

payload = jsonObj.get(QueryConstants.PAYLOAD);
}

public int getAckCode() {
return ackCode;
}

public boolean isSuccessful() {
return ackCode == 1;
}

public List getKeys() {
return keys;
}

public boolean contains() {
return contains;
}

public String getErrorCode() {
return errorCode;
}

public String getErrorCause() {
return errorCause;
}

public DbOperationException createException() {
return new DbOperationException(errorCode, errorCause);
}

public JsonElement getPayload() {
return payload;
}
}

0 comments on commit e75434c

Please sign in to comment.