I am trying to implement Spring Data Crate API in a project. Following the instructions provided here:
https://crate.io/a/using-sprint-data-crate-with-your-java-rest-application/
Inserts/Updates/FindById methods are covered. My question is how to create custom queries using this API.
Have you looked at our Spring Data adapter?
Declared Queries
It's also possible to use the #Query annotation to define queries:
public interface UserRepository extends CrateRepository<User, String> {
#Query("select * from users")
List<User> getAllUsers();
}
https://github.com/crate/spring-data-crate#declared-queries
please note that the crate java-client is not supported anymore since v0.57 unfortunately.
https://crate.io/docs/clients/java/
This leaves us with the java-jdbc:
https://github.com/crate/crate-sample-apps/blob/master/java/documentation.md
Spring data adapter is using the java-client.
Here is a Spring Boot application that is using JDBC in order to access CrateDB (> v0.57.0) https://github.com/klearchos/crate
And here are the official samples in order to access CreateDB through JDBC (using the Spark framework). https://github.com/crate/crate-sample-apps/tree/master/java
Related
I'm trying to connect to two different databases (both with reactive connection), but I'm not able to create a connection pool for the second database and continue using Panache.
I tried to use the #ReactiveDataSource annotation as it is in the Quarkus documentation, but I can't set this connection for some entities to perform the operations via Panache for this specific pool.
Example (Something like this):
application.properties
quarkus.datasource.db-kind=postgresql
quarkus.datasource.username=user-default
quarkus.datasource.password=password-default
quarkus.datasource.reactive.url=postgresql://localhost:5432/default
quarkus.datasource."additional1".db-kind=postgresql
quarkus.datasource."additional1".username=user-additional1
quarkus.datasource."additional1".password=password-additional1
quarkus.datasource."additional1".reactive.url=postgresql://localhost:5432/additional1
User entity
public class User extends PanacheEntity {
private String name;
}
UserRepository
(This is where the Panache configuration for a specific datasource should occur!!)
#ApplicationScoped
public class UserRepository {
#Inject
#ReactiveDataSource("additional1")
PgPool additional1Client;
public Uni<User> findUserById(int id) {
// set the _additional1Client_ pool in the Panache to make User.findById(id)........
}
}
Thanks in advance for any help.
According to the guides, it is not currently possible to create multiple reactive datasources.
Also, looking forward this feature, but it will be supported only for future Hibernate ORM 6 according to a Quarkus member comment.
I was checking the guides ant the look exactly what you did.
But when i was using name source, I didn't use the ", so try to remove them, might work then. Therfore do:
quarkus.datasource.additional1.db-kind=postgresql
As described in this artikel:
https://quarkus.io/guides/datasource#multiple-datasources
I would like to integrate Kotlin Exposed into a Kotlin application that is already using Spring Data JPA. The problem I have is that only want to use one Transaction Manager for my application, but currently I have to have two (one for JPA and another for Exposed). Is there a way to only have one Transaction Manager?
I didn't work with kotlin-exposed library before, but based on your question
,Just you have to create your own transaction-manager bean. After that spring will use your bean, and you need to configure kotlin-exposed to use it.
sample:
#Primary
#Bean("appTransactionManager")
fun appTransactionManager(
#Qualifier("appEntityManagerFactory") appEntityManagerFactory: LocalContainerEntityManagerFactoryBean
): PlatformTransactionManager {
return JpaTransactionManager(eccTransactionManager.getObject()!!)
}
I'm attempting to add Crate.IO capability to an existing Spring Data/Eclipselink/MySql web application. For this specific use case, we want to persist data to both MySql AND Crate (for evaluation purposes) in the most painless way possible. I'm using the Spring-Data-Crate project in order to be able to use Spring Data Repositories with Crate.
I've been able to setup a separate Crate specific entity manager with a filter to only utilize repos that implement CrateRepository. The problem I'm having is determining how to use the existing Spring Data/MySql entity classes with Crate. (or derive from them)
1) If I annotate an existing Spring Data #Entity class with the Spring-Data-Crate
#Table annotation, the mapping to the crate DB will fail because EclipseLink/JPA adds hidden persistence fields to entities objects that start with an underscore, which is apparently not allowed by the spring-data-crate adapter
2) I tried to use entity inheritance, with a base class that both the MySql and Crate entity can extend, with only the MySql entity having the spring data #Entity annotation. Unfortunately, this causes Spring Data to lose visibility of the base class fields unless the base class is annotated with #MappedSuperClass. But adding this annotation introduces the hidden "_"-prefixed persistence properties to the derived crate entity.
3) I could use separate entities entirely and have them implement a common interface, but I can't assign the interface as the type of the spring data crate repository.
... Not sure where to go from here
Spring Data Crate adapter project - https://github.com/KPTechnologyLab/spring-data-crate
Spring Data Crate Tutorial - https://crate.io/a/using-sprint-data-crate-with-your-java-rest-application/
i'm johannes from crate.
we didn't test the use of spring data crate in that manner so we can't state any information if this should or shouldn't work.
sorry, johannes
spring-data-mongodb. How can i dynamically create a database in mongo using spring-data-mongodb library?
I am trying to use Spring-Mongodb-Data module for CRUD operations against Mongo database and going through examples and articles my assumption is that databasename should be pre-defined in spring context xml when defining MongoTemplate bean.
In my case I have an multi-tenant application that will accept requests over http and my application should create the mongodatabase on-the-fly and use the name provided in the input http request to create the database and then load the data into collection in the newly created database.
I am trying to figure out if there is a way to dynamically populate the databasename in MongoTemplate or MongoRepository without having to provide it in spring context.xml?
Please help me.
Thanks
-RK
Have you tried the following instead of going through the pre-defined spring context configuration.
MongoTemplate getMongoTemplate(Mongo mongo, String database) {
return new MongoTemplate(mongo, database);
}
My EntityManager is using a persistence unit that uses a data source provided by our Websphere configuration. The DS configuration includes an environment specific DB to use.
The EM successfully uses this schema, but I can't figure out a way to log or display the schema being used. I was thing something like em.getCurrentSchema would be available..
Any help would be great, thanks.
No API to do this (in JPA). You could do it via JDBC and use of DatabaseMetaData.
JPA is to provide an object view of the data and ease persistence of those objects, not to just present datastore specifics to the user.