i have a Servlet(Jersey2 + Jax-rs) API app running on Azure App Service.
This API is retrieving data from Azure Table Storage and send back to client side.
So here is my question, Which is better choice between "static method" and "instance" for implementing Azure Storage SDK.
for example what my codes look like is,
public class AzureTableStorage {
private static final String storageConnectionString = "DefaultEndpointsProtocol=http;" + "AccountName=;"
+ "AccountKey=";
public static CloudTable getTable() {
try {
CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);
CloudTableClient tableClient = storageAccount.createCloudTableClient();
CloudTable cloudTable = tableClient.getTableReference("");
return cloudTable;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static Entity getEntity(String rowKey) {
// TODO Auto-generated method stub
try {
TableOperation operation = TableOperation.retrieve("", "", xxx.class);
Entity entity = AzureTableStorage.getTable().execute(operation).getResultAsType();
// Output the entity.
return entity;
} catch (Exception e) {
// Output the stack trace.
e.printStackTrace();
return null;
}
}
}
and using like
AzureTableStorage.getEntity(rowKey);
Is this bad idea?
Please can anyone give me some answer?
BTW I already have looked,
Java: when to use static methods
But still cant find out.