Is there a .NET equivalent of DynamoDBMapper? - java

I'd like to construct a CreateTableRequest object from data annotations in a class. It looks like Amazon provides DynamoDBMapper in the Java SDK, which makes this process simple.
How can I do the same in .NET/C#?
AmazonDynamoDB dynamoDBClient = new AmazonDynamoDBClient();
DynamoDBMapper mapper = new DynamoDBMapper(dynamoDBClient);
CreateTableRequest req = mapper.generateCreateTableRequest(TestClass.class);
// Table provision throughput is still required since it cannot be specified in your POJO
req.setProvisionedThroughput(new ProvisionedThroughput(5L, 5L));
// Fire off the CreateTableRequest using the low-level client
dynamoDBClient.createTable(req);

generateCreateTableRequest is unique to the Java SDK with no equivalent (yet) for the .NET SDK.
The general .NET equivalent for Java's DynamoDBMapper is the DynamoDBContext class (docs 1, docs 2). This class provides a high-level .NET object persistence model that enables you to map your client-side classes to Amazon DynamoDB tables.
However, as per docs:
The object persistence model does not provide an API to create, update, or delete tables. It provides only data operations. You can use only the AWS SDK for .NET low-level API to create, update, and delete tables.
You will have to use the low-level .NET API to create tables.

Related

Spring Data CosmosTemplate create query with System Functions

We are trying to implement a query with cosmosTemplate from spring-data-cosmosdb project.
The query has the following syntax:
"select * from movie where ARRAY_CONTAINS(movie.countries, #country)".
CosmosTemplate accepts DocumentQuery object, that is build upon Criteria object. Criteria object supports a small subset of basic predicates like in, or, is equal and etc., but doesn't have array_contains predicate.
At the moment the query is performed by using cosmos client(from sdk), instead of cosmosTemplate.
This brings us two issues:
We have to mix the code by using cosmosTemplate and cosmos client together.
Since we have complex parameterized queries that use system functions, we have to concatenate sql query string and gather sql parameters.
How queries like this should be handled with cosmosTemplate and is that even possible?
P.S we are using com.microsoft.azure:azure-cosmosdb-spring-boot-starter:2.2.5 library.
In the current GA release you will have to use the Client and template together like you mentioned.
The latest beta release includes support for QueryAnnotation Using annotated queries in repositories. Following is an example:
#Query(value = "select * from c where c.firstName = #firstName and c.lastName = #lastName")
List<User> getUsersByTitleAndValue(#Param("firstName") int firstName, #Param("lastName") String lastName);
Ravi's answer is correct. To create custom queries directly from Spring Data connector, there are current two options.
First, you can follow the instructions in the "Custom Query" section of this document
https://learn.microsoft.com/en-us/azure/developer/java/spring-framework/how-to-guides-spring-data-cosmosdb
which guide you through using the Java SDK CosmosClient directly. The current GA release of Spring Data connector does not have #Query annotation which would enable custom query annotation, that is why you need to use the Java SDK directly.
Second, upgrade to the latest beta which enables #Query annotation
https://mvnrepository.com/artifact/com.azure/azure-spring-data-cosmos
Sample code for this will be released in the next few days, and the GA release is scheduled for 9/30 so it is not a long wait.
After a research in azure sdk, I've found that at the moment not all system functions are supported by cosmosTemplate.
List of supported system functions can be found there:
https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/cosmos/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/core/query/CriteriaType.java
If you wan't to write query that uses system function, that isn't in the list in the link above, you can use either #Query annotation or directly use cosmos client instead of cosmosTemplate.

How to create a view in the Java BigQuery API?

Using the Java client library for Google BigQuery, how does one create a view?
The relevant API call is tables.insert. With the Java API, this is represented by the create method on the BigQuery service object. You first have to create a TableInfo, which encapsulates a ViewDefinition object. The documentation for setDefinition on TableInfo.Builder says:
Sets the table definition. Use StandardTableDefinition to create
simple BigQuery table. Use ViewDefinition to create a BigQuery view.
Use ExternalTableDefinition to create a BigQuery a table backed by
external data.
Sample code:
bigQuery.create(TableInfo.of(TableId.of("DatasetName", "ViewName"),
ViewDefinition.of("SELECT this, is, the, view FROM query")))

how to dynamically query database via web?

Can you recommend on a framework which enable querying of data via web?
Requirements:
ORM capabilities - I want that the representation of the model at the server & client will not be dependent.
For example: let's say that the server will return to the client layer the following model: transaction (firstName, lastName, description, amount). While in the dal-layer it's being saved like this: Customer(Id, fName, lName, address) , Transaction(id, CustomerId, description, amount)
Option to write my own query provider (For example: HiveQL, SQL & etc).
I have tried to use the following frameworks (but it's seems like it, that the first demand is not supported):
JayData: http://jaydata.org/
breezejs: http://www.breezejs.com/
Thanks in advance.
Breeze does provide this but you will need to write the server side code that translates an OData query into a query that your chosen server implements. We already provide several implementations of this code for different server/database technologies and plan on doing more in the future.
To date we have done this for .NET servers with both Entity Framework and NHibernate ORM's and against Node servers with MongoDB backends. We also have other developers working on a Ruby server implementation. If you want to write your own, you should probably take a look at the Breeeze/MongoDB source to see how this is done.
Alternately, if your chosen server tech already has an OData provider, then Breeze can talk to it.
OData does provide a way to query database via web, such as
GET http://myservice/Products?$filter=Id gt 3 and contains(Name,'abc')
GET http://myservice/Products?$select=Id,Name,Provider&$orderby=ManufactureDate desc
Here are some odata samples https://aspnet.codeplex.com/SourceControl/latest#Samples/WebApi/OData/v4/. In a controller, you can use what ever framework/provider you like to retrieve data from persistence.
If you want to use Entity Framework please follow this one:https://aspnet.codeplex.com/SourceControl/latest#Samples/WebApi/OData/v3/ODataActionsSample/.

Does spring data uses the new MongoDB Bulk API for bulk operations?

see http://docs.mongodb.org/manual/reference/method/Bulk/
Can you please point me to the version which supports this new API or in which version this support will be available?
There's currently no dedicated support for the bulk operations introduced in MongoDB 2.6. If you think these operations are worthwhile to add support for, please raise a ticket in out JIRA.
In the meantime you can use a CollectionCallback to execute bulk operations on the raw MongoDB collection:
template.execute(new CollectionCallback<Void> {
Void doInCollection(DBCollection collection) {
BulkWriteOperation operation = collection.initialize(Uno|O)rderedBulkOperation();
// bulk code goes here
operation.execute();
return null;
}
}
MongoDB Java Driver for MongoDB v2.6 does support bulk operations however since these are very new set of operations which were not provided in MongoDB v2.4, these may not have made into stable versions of Spring Data yet. I see there are planned 1.5.X SpringData but don't see any associated API / reference for these yet on their website.

How to upload form data to google app engine

To upload data to the datastore I use this java code :
DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
Entity entity = new Entity("mydetail");
entity.setProperty("entry", "entry");
ds.put(entity);
For uploading form based data is this the correct method of uploading data, ie using similar code above or is there another API I should be using ?
Yes, this the direct API to the AppEngine Datastore.
You can also use JDO interface which allows for directly storing a Java object without dealing with the Datastore API:
import javax.jdo.annotations.Persistent;
#PersistenceCapable
public class MyDetail {
// ...
#Persistent
private String entry;
// ...
There is also the JPA interface. Both of the interfaces are described on the App Engine website.
The Objectify interface is very easy and for many situations easier. It is not part of the official SDK.
You can use whichever makes more sense for you application.

Categories

Resources