Comments (4)
Perhaps you can use this project which builds on JDBI and adds CRUD and Dao capabilities: https://gitlab.com/mvysny/jdbi-orm
from jdbi.
Right, there is no one obvious right way to do this. To get something flexible enough for general purpose use, you need to get into the realm of O/R Mapping etc. I think once you go down that path, you are probably better off using a tool which really wants to do O/R Mapping (Hibernate, OpenJPA, etc).
I think there is certainly room for some basic mapping functionality, but I would be very careful about including it in the core.
I'd probably start with chained statement locators and a base dao interface which is type parameterized on the dto type. Then make a child interface which makes the DTO type concrete (so that classmate can figure out the type). You can then guess table names and field names from the dto type, or use jpa or jdo annotations to override behavior. How fancy you get is up to you.
This is the path, btw, of just using JDBI as a sql execution layer for an ORM -- if you cannot use the most basic things, and you want sophisticated ORM, then use HIbernate or OpenJPA.
from jdbi.
I strongly believe that there is no need a deep O/R mapping. Almost all projects would be mapped by simple functions. All necessary things is registering a strategy. A translating strategy is a two separated function which will provide same values. f(dbName) = g(propertyName) = z
public interface TranslatingStrategyAware {
public TranslatingStrategy getDbTranslatingStrategy();
public TranslatingStrategy getPropertyTranslatingStrategy();
}
And a strategy must not be changed from one db to another
dbi = new DBI(datasource);
dbi.setTranslatingStrategy(someStrategy)
Default strategy is lowering for both db and property as in BeanMapper you have done. BTW I have dropped my requests for snake case because of this. My pull requests are not addressing real problem entirely. A bean mapper with a strategy is not the solution for snake case problem. Database should has a strategy not mapper.
But I am not sure how StatementLocator, StatementRewriter and other parts will get this information. This might break backward compatibility by introducing some new parameters to StatementRewriter, StatementLocator etc.
And could you please explain this part? Especially first part.
I'd probably start with chained statement locators and a base dao interface which is type parameterized on the dto type.
from jdbi.
So setting this globally feels off, it seems like a function of the bean mapper.
Perhaps an argument to BeanMapper() ?
I think folks usually use BeanMapper via map(Class), which makes it a tad awkward, but I'd be happy to consider overloading that method to accept a name translator of some sort, as you suggest.
from jdbi.
Related Issues (20)
- Add test for non-default locale and timezone HOT 1
- Memory consumption for generated SqlObject DAO HOT 4
- @UseFreemarkerSqlLocator is ignored when it comes before @UseFreemarkerEngine HOT 5
- Can not set static final field HOT 4
- DAO/SqlObject interface performance HOT 8
- Investigate libyears HOT 2
- JDBI can't find the registered value mapper for a Map<String, MyClass<SomeOtherClass>> return type HOT 4
- Exceptiona are thrown after tests execution, if the database test container is closed prematurely. HOT 14
- Thread-based nesting behavior for managed handles is surprising and not adequately documented HOT 5
- japicmp chokes when run on a tag
- reproducible build validation for a tag needs to skip japicmp
- createQuery does not throw any error when bind call has incorrect parameter number
- [MSSQL] Snapshot transaction isolation level cannot be used with `inTransaction` methods HOT 1
- [postgres] INSERT and SELECT in one request doesn't work properly HOT 2
- Move Oracle artifact back into main build
- InTransaction does not call transactionHandler.inTransaction when initalAutoCommit=false HOT 4
- How to specify CaseStrategy for MapMapper in SqlObject Extension? HOT 3
- Nested objects doesn't work with inner joins and register bean mapper HOT 6
- OptionalRowMapperFactory can cause NullPointerExceptions with custom Row Mappers HOT 1
- Transaction not work on DAO bean without an attachment. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jdbi.