How do I create JOOQ DSLContext from reactive MariaDB connection - mysql

JOOQ manual states the following:
Out of the box, all jOOQ provided publishers will block on the
underlying JDBC connection, but if you provide jOOQ with a
io.r2dbc.spi.Connection or io.r2dbc.spi.ConnectionFactory, then the
publishers will execute queries in a non-blocking fashion on an R2DBC
driver.
How do I provide DSLContext with io.r2dbc.spi.Connection or io.r2dbc.spi.ConnectionFactory ?
I tried DSL.using() but it does not accept this interface.
Also - can I define the DSLContext with reactive driver through Spring Boot ?
Thank you.

How do I provide DSLContext with io.r2dbc.spi.Connection or io.r2dbc.spi.ConnectionFactory ?
At the time of this question, jOOQ 3.14 did not yet support R2DBC. With jOOQ 3.15, you can write this:
DSLContext ctx1 = DSL.using(connection);
DSLContext ctx2 = DSL.using(connectionFactory);
Just like with JDBC connections.
Also - can I define the DSLContext with reactive driver through Spring Boot ?
I suspect that this will be possible once jOOQ 3.15 is released (~ end of Q2 2021, no promises). Until then, just expose a #Bean of type DSLContext that you build manually from an injected ConnectionFactory

Related

Entity Framework with mySQL problems - asnotracking and include table numbers

I'm testing an ASP.NET application that runs with the Entity Framework on SQL Server, and I'm having the following problem.
According to the code below, the following error is displayed: "String was not recognized as valid Boolean";
var data = DataContext.TableName
.Include("Table2")
.Include("Table2.Table3")
.Include("Table4")
.Include("Table5")
.Include("Table5.Table6")
.Include("Table7")
.Where(x => x.Id == 10)
.AsNoTracking()
.FirstOrDefault();
Versions:
.NET Framework: 4.5.2
Entity Framework: 6.2.0
MySql.Data: 8.0.11
MySql.Data.EntityFramework: 8.0.11
mySQL: 8.0
When I run the same code with the Entity Framework in SQL Server, the problem does not occur.
Does anyone know if it's a limitation of Entity Framework with mySQL?

UseRowNumberForPaging is not a valid

I'm using "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final" with SQL 2008 and according to some results found on Google, I just have to add the option to .UseRowNmberForPaging() when creating a new DBcontext. This was the solution for rc1-final but it doesn't seem to work for rc2-final.
When I add the option when configuring my service, it's not recognized.
Trying to paginate records on SQL Server 2008 with EF Core so this seems to be the recommended solution.
Here is the line I'm using to Configure the service:
services.AddDbContext<Data.Models.AC_MCLContext>(options =>
options.UseSqlServer(connection).UseRowNumberForPaging());
Does anyone know how to use the row number for paging in EntityFramework Core rc2?
A solution was given to me on another forum so I thought I'd share the answer in case anyone else ran into this issue.
The API now uses a nested closure pattern so the options should be configured as a nested structure like the example below.
services.AddDbContext<Data.Models.AC_MCLContext>(options =>
options.UseSqlServer(connection,
opt => opt.UseRowNumberForPaging()));
This can also be done from the context itself.
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(yourConnectionStringValue, opt=>opt.UseRowNumberForPaging());
}
2022 update: using .NET 6 + EF Core 6 + SQL Server 2008, you can install the package bellow (wich has a GitHub repository, so the code can be checked for safety).
https://www.nuget.org/packages/EntityFrameworkCore.UseRowNumberForPaging/
After installing the package, in Program.cs add:
using EntityFrameworkCore.UseRowNumberForPaging;
Then replace your DbContext service configuration:
builder.Services.AddDbContext<YourDbContext>(options => options.UseSqlServer(connectionString));
For:
builder.Services.AddDbContext<YourDbContext>(options => options.UseSqlServer(connectionString, o => o.UseRowNumberForPaging()));

Repository uses N1QL

I'm getting the following exception:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'answerRepository': Invocation of init method failed; nested exception is org.springframework.data.couchbase.core.UnsupportedCouchbaseFeatureException: Repository uses N1QL
I'm using Spring 4.2.0.RELEASE with spring-data-couchbase 2.0.0.M1 against Couchbase 2.5.1 enterprise edition (build-1083)
I can't see any explanation in the doc for this error.
Here is the repository:
public interface AnswerRepository extends BaseRepository<Answer, String> {
final static String DESIGN_DOCUMENT = "answers";
#View(viewName = "answers_by_quizId_startTime", designDocument = DESIGN_DOCUMENT)
public List<Answer> findByQuizIdAndStartTime(String quizId, long startTime);
Answer findByUuid(String uuid);
}
#NoRepositoryBean
public interface BaseRepository<T, ID extends Serializable> extends CrudRepository<T, ID> {
}
Maybe my Couchbase server does not support this feature, whereas my repository expects it.
I might need to code my repository differently.
It's too bad it doesn't say which method is the invalid one here.
Or it is my using of the CrudRepository in the base class ?
I wonder how to find out which views it expects to find in my Couchbase server.
Repositories in Spring Data Couchbase 2.0 rely almost exclusively on Views and N1QL. A good chunk of the new features in this version are made possible by N1QL, which is now the default mechanism Spring Data uses for things like "query derivation" (implementing a repository method by producing some sort of query that is derived from the method name).
Couchbase Server 2.5.1 doesn't have access to N1QL (which came with Couchbase Server 4.0 and of course also in the brand new 4.1 version).
If you want Spring Data to implement findByUuid for you, you'll have to annotate that method with #View and create the appropriate view that emits uuids from your Answer documents.
View query derivations are heavily restricted and give you more work since you have to write the correct map function:
a repository method based on a view can only query with one criteria.
you have to create your view correctly, emitting the correct keys corresponding to the criteria you'll query with.
you have to create one view per entity class, restricting the view to only emit if the "_class" field in the JSON matches said entity (note: this field can be renamed in the configuration so make sure to use the relevant one).
So that means that your findByQuizIdAndStartTime cannot work either. You may have to implement this (and maybe findByUuid) in the BaseRepository, relying on the CouchbaseTemplate and using its findByView method (or even queryView as a last resort).
The UnsupportedCouchbaseFeatureException is mentioned in the M1 doc chapter 7 (on N1QL based querying).
See also the section on view query derivation further down the documentation.

MySql pooled datasource in standalone JAVA app (no J2EE container, no JNDI, no TOMCAT etc.)

I've been reading dozens of topics here with no real enlightment: I'm running a standalone java app, on a Synology NAS with Java 8. I also installed MariaDB on the same NAS. So everything is local.
I am able to setup a datasource and get a connection, but I would like to be able to access it in any instance of any of my classes / threads for connection pooling. Everything seem to show that I would need JNDI. But I don't have a J2EE container and this seems overkill for my need. Idem for developping my own implementation of JNDI.
I've seen replies to similar questions where people suggest C3PO. But this is just another datasource implementation. I don't think it solves the standalone app issue with no way to access datasource from anywhere in the code :
How to retrieve DB connection using DataSource without JNDI?
Is there another way to share a datasource across java threads ?
Can I pass the Datasource instance as a parameter to each thread, so
they can get a connection when they need ?
Should I assign a given connection to each thread - also passed as a
parameter ? and in this case, never really close it properly ?
Or should I really install something like tomcat, jboss, jetty ? are
they equivalent ? Is there a super light J2EE container that could
provide JNDI ?
Thanks
Vincent
You could use the singleton pattern, like this for example:
public class DataSourceFactory {
private static DataSource instance = null;
private DataSourceFactory() { }
public static synchronized DataSource getDataSource(){
if(instance == null){
instance = // initialize your datasource
}
return instance;
}
}
Then any from any thread you can call DataSourceFactory.getDataSource() to get a reference to your DataSource object.

using Hibernate ORM in an EJB Project in Myeclipse with glassfish and mysql data base

I am new to J2EE development and its frameworks, so I'm leads to create a J2EE application usign Myeclipse,glassfish ans mysql as SGBD ... I need to create a project EJB3 session I have to use Hibernate3 ORM .. My concern is that I've worked with hibernate but in a web project type and not EJB and I really do not know how my project should be like .. I just need to understand the structure of my EJB project because normally we have 2 basic classes: EJBService and EJBserviceRemote .. EJBService, containing all my methods that I would need to call from my client (a web project for exemple) and EJBServiceRemote which contains the signature of each method .. so where do I rank the DAO classes generated by Hibernate ORM and how to call them?? shoukd I copy their code in EJBService and then declare in EJBServiceRemote to be able to call them by my client??
SOS I'm really disturbed
add all the jars that you're using in your ejb project to the following glassfish directory :
C:/..../glassfish/lib
C:/..../glassfish/domains/"your domain name"/lib
Caused by: java.lang.NoClassDefFoundError: org/hibernate/criterion/Criterion
may be you're missing one of the hibernate jars (hibernate-core.jar) or maybe you have an older version of hibernate + a recent one at the same time in your classpath.
ok everything is working now here is my methode to show data:
#SuppressWarnings("unchecked")
public int[][] afficheProduitsStockList(){
int j,a;
ProduitsStockDAO stockdao = new ProduitsStockDAO();
List<ProduitsStock> LPdt = stockdao.findAll();
a=LPdt.size();
int t[][]=new int[a][3];
Iterator it = LPdt.iterator();
while(it.hasNext()){
for(j=0;j<t.length;j++){
ProduitsStock pdt = (ProduitsStock)it.next();
t[j][0]=pdt.getCodeStock();
t[j][1]=pdt.getCodePdt();
t[j][2]=pdt.getQtePdt();
} }
return t;
}
and everything works !
Thank you all :)