I got the following problem and no idea on how to solve it.
I am using SqlJet to access and manage a small Sqlite DB.
It's amazing the simplicity of this library! But now, I have to execute a complex query which cannot be expressed using the methods provided by the library. On the website, they say
SQLJet does not support SQL queries; there is an API to work with the
database on a lower level
And I was wondering, anybody of you know what is this lower level API to execute SQL queries?
As far as I can tell from my research, there is no support for arbitrary SQL queries in SQLJet. I first thought it was a sqlite wrapper, which it isn't, so there is also no way to use JDBC.
Other than the lookup rows by name and index stuff, the "lower level" API they are talking about on their page, seems just to be direct access to the internal DB representation, as mentioned in this post.
From a quick glance at the JavaDoc and sources, it might be the SqlJetDb.getSchema() and getTable() methods. There is no proper API documentation or Tutorials, there is even a complaint about this in the issue tracker.
Maybe you can describe what you want to do. Either there is a way to do it though the limited interface SQLJet offers, or I'm afraid I can't help.
Its also good idea to contact the developers directly, as it seems there is not much information to be found elsewhere.
Related
Note:There is a good chance I'm not using the correct terminology here and that maybe the reason I'm not finding the answers to my question. I apologize upfront if this has been already answered, so please just direct me there.
I am looking for an open source framework written in Java that would allow me to build pluggable data connectors (and obviously have some built in already) and almost have a query language (abstraction layer) that would translate into any of those connections.
For example: I would be able to say:
Fetch 1 record from a Mongo DB that matches name='John Doe'
and get JSON as a response
or I could say
Fetch all records from a MySQL DB that matches name='John Doe'
and get a JSON as a response
If not exactly what I described, I am willing to work with anything that would have a part of this solved.
Thank you in advance!
You're not going to find a "Swiss army knife" data abstraction framework that does all of the above. Perhaps the closest things to what you ask for would be JPA providers for both Mongo and MySQL (Hibernate is a well-regarded JPA provider for MySQL, and a quick google search shows Kundera, DataNucleus and Hibernate OGM for Mongo). This will let you map your data to Java Objects, which might be a step further than what you ask for since you explicitly asked for JSON; however, there are numerous options for mapping the resulting objects into JSON if you need to present JSON to a user or another system (Jackson comes to mind for this).
Try YADA, an open source data-abstraction framework.
From the README:
YADA is like a Universal Remote Control for data.
For example, what if you could access
any data set
at any data source
in any format
from any environment
using just a URL
with just one-time configuration?
You can with YADA.
Or, what if you could get data
from multiple sources
in different formats
merging the results
into a single set
on-the-fly
with uniform column names
using just one URL?
You can with YADA.
Full disclosure: I am the creator of YADA.
I would like to know which alternatives exist to replace DDL utils from Apache.
I ask this because ddlutils project seams to be Dead, and also it does not support H2 Databases. I've searched for it, and I found suggestions like liquidbase or flyway.
My problem is: These frameworks run when project starts and change DB structure based on some XML files. They are really designed for Database Migration.
What I want is a framework to CREATE/ALTER Tables in Runtime, in a high abstraction level., i.e. supportting at least Mysql, Sqlserver, oracle, and H2.
For example I could tell to the engine that I want to create a table with a Field AGE with Type Number, and the framework would rephrase to:
create table MY( id bigint(20))
create table MY(id bigint)
create table MY (id, number)
depending on the underlying db engine.
Any suggestions?
I could see there is a patch for ddlutils, for it to support H2. However I wasn't able to patch my svn checkout...
Any help will be appreciated.
thanks in advance
rui
I know this is an old thread, but wanted to give a definitive answer.
Yes, DdlUtils is dead, hasn't seen an update in 2 years now.
However, it looks like the guys might have switched over to https://www.symmetricds.org. Their repo is https://github.com/JumpMind/symmetric-ds.
As soon as you scratch away at the surface, you'll find that the core of DdlUtils is still in there (even has some of the old Apache copyright notices).
Class names have changed, APIs have changed so there is not a 1-to-1 mapping, but it is getting regular updates and includes H2 and other database support. Honestly I'd rather be getting those things instead of keeping the old APIs.
You're not going to find a guide on using Symmetric DS in the same way as the old DdlUtils doco, but there is enough in the code that you should be able to piece it together.
Take a look on jOOQ it is very useful in generating DDL (and DML too)
create.createTable("table")
.column("column1", INTEGER)
.column("column2", VARCHAR(10).nullable(false))
.constraints(
constraint("pk").primaryKey("column1"),
constraint("uk").unique("column2"),
constraint("fk").foreignKey("column2").references("some_other_table"),
constraint("ck").check(field(name("column2")).like("A%"))
)
.execute();
This looks promising: https://bitbucket.org/aragot/play-sql-dialects/src
At least as a start.
Mogwai ERD designer might help though they do not formally support H2 but you could put H2 into compatibility mode with one of the supported DB systems: https://sourceforge.net/p/mogwai
Is there any way for us to query the db to suggest index creation/index deletion that would improve the performance of the db system?
We understand that a dba can manually view the trace files to create/drop indices but can i write a java program that queries the db engine to suggest the same automatically.
Or some open source tools that i can check out to perform the same automatically.
Thx.
Well there's no standard JDBC way to do this. There may be specific driver implementations for specific DBS that would allow you to EXPLAIN your query (trace the use of indexes), etc. But there's no one-size fits all answer here.
in general I would lean to saying NO.
Your index performance is dependent on the queries you would fire on them...So No !
With MySQL specifically, you can flag slow queries, as well as queries not using indexes.
Ultimately, the database will do its best (within what you've created) to optimize your query.
http://dev.mysql.com/doc/refman/5.0/en/slow-query-log.html
This data would be logged to a file, and not necessarily available via an API.
Problem Domain:
I am working on a new revision of a Java application that connects via SSH to a proprietary, Linux-based platform's Command Line Interface (CLI). Everything on the platform that I would want to do or know is only available via CLI commands and stdout.
One of the commands available retrieves information from an internal database (not using SQL) with the following command arguments: query, sub-query, result format, and sorting preference.
Solution Being Considered:
I would like to expose an API that encapsulates the low-level details of the SSH/CLI behavior and achieve the following:
Eliminate the current error-prone method of embedded query strings (currently very prone to typos).
Make the API intuitive as the current query and command formats are not commonly understood.
Provide consistent error and result responses.
I am considering creating query builder and response classes at the lowest level that implement the SSH/CLI behavior; then creating a layer above that to allow retrieval of attributes from the platform by attribute-category (as compared with database tables).
Question:
I have been digging through my Gang of Four book and other resources to find any sensible approaches that might be a starting point; also looking at information on Syntax Trees.
Before I find myself implementing "SQL for proprietary platform" I wanted to see if anyone has any advice, similar experience, resources, or other input on solutions to this problem. Any thoughts on implementation, available frameworks, CLI processing, or other resources would be appreciated.
It can't hurt to look at Sun/Oracle's guide For Driver Writers. Even if the JDBC API isn't a good fit, you'll end up inventing something similar. You may even be able to leverage some of the myriad existing JDBC tools.
I found what I was looking for after stumbling on a different question: ID 2068478 at
Query Object Pattern (Design Pattern), which lead me to the "Repository" pattern as well:
http://martinfowler.com/eaaCatalog/repository.html
There is an example of the Query Object Pattern using C# and a Syntax Tree here:
http://www.lostechies.com/blogs/chad_myers/archive/2008/08/01/query-objects-with-the-repository-pattern.aspx
Note: I will attempt to update with an example if possible.
Thank you,
-bn
I had hoped this was baked into the most recent release, but if it is, I can't find the docs via a simple Google search. Failing that, I'd prefer a simple library, but I'll settle for a tutorial.
Thanks.
Ibator can help you with this. Let it autogenerate everything, and you'll find by-Example Queries in the SQL Maps, as well as corresponding Java bindings in the DAOs.
Check "Example Class Usage Notes" on http://ibatis.apache.org/docs/tools/ibator/ for more information.