gitblit / iciql Goto Github PK
View Code? Open in Web Editor NEWa model-based, database access wrapper for JDBC
Home Page: http://iciql.com
License: Apache License 2.0
a model-based, database access wrapper for JDBC
Home Page: http://iciql.com
License: Apache License 2.0
I make PostgreSQL connection test program by using Iciql. About below entity:
@Iciql.IQTable(name="Student")
public class Student {
@Iciql.IQColumn(name = "ID", primaryKey = true, autoIncrement = true)
public Integer id;
@Iciql.IQColumn(name = "NAME")
public String name;
…
}
I try to insert a data which all column has NULL value.
db.insert(new Student(null, null));
Then below exception occurred:
com.iciql.IciqlException: ERROR: syntax error at or near ")"
Position: **
INSERT INTO Student() VALUES()
Maybe in the insert query construction process which make query in Table(...) and VALUES(...) has some technical problems when insert data which whole column is NULL assigned.
The behavior of the dsl should be the same as for db.insert(record)
The documentation to IQTable.inheritColumns
says
The inherit columns allows this model class to inherit columns from its super class. Any IQTable annotation present on the super class is ignored.
The second sentence is wrong as TableDefinition.mapFields
tests superTable.inheritColumns
. Unfortunately, it doesn't go any further. This is a bad surprise, when you make the class hierarchy deeper.
I'd suggest to iterate the whole hierarchy up to a class having no such annotation. I could provide a patch, if wanted.
Hello. I currently try to make the Model Generation in Linux via command line (CentOS) to test your tool in a Rest application with Springboot. I use the command as on the website:
java -cp iciql.jar:postgresql-9.3-1104.jdbc4.jar -url "jdbc:postgresql://localhost:5432/transtatedb" -username ..... (details)
I get an error as unrecognized -url. I checked all files for models and it was defined as such. I tried also with or withour "", with just link...
CustOrder produce toString with localized total value string representation:
@Override public String toString() { return customerId + ":" + orderId + ":" + new DecimalFormat("##.00").format(total); }
but in the assertion is used constant value string representation with dot as decimal separator (88.80) In the countries when decimal separator is different from dot this assertion is false.
assertEquals("[ANATR:10308:88.80]", orders.toString());
suggested simple solution:
assertEquals("[ANATR:10308:"+ new DecimalFormat("##.00").format(88.80) + "]", orders.toString());
IciqlLogger.activateConsoleLogger();
Not logger in console InteliJ IDE.
iciql version 2.2.0.
There is a class loader issue when iciql is used as global library in tomcat and used in a webapp.
The wrong class loader is used for proxy generation. It must be the class loader of the dao interface.
interface business.ws.control.Records is not visible from class loader
I'm using H2 embedded db and keep getting this error
Exception in thread "main" com.iciql.IciqlException: Table "MY_TEST" not found; SQL statement:
when I try to fetch anything from the my_test table.
For my model, I have this:
@Iciql.IQTable(name = "my_test")
@Iciql.IQIndexes({
@Iciql.IQIndex(name="exchange", value="exchange")
})
@Iciql.IQVersion(value = 1)
public class MyTest {
@Iciql.IQColumn(name = "id", primaryKey = true, autoIncrement = true)
public Long id;
@Iciql.IQColumn(name = "exchange", length = 20, trim = true)
public String exchange;
}
My database helper class init code looks like so:
Class.forName("org.h2.Driver");
JdbcDataSource jdbcDataSource = new JdbcDataSource();
jdbcDataSource.setURL(dbConnectionString);
jdbcDataSource.setUser(DbUsername);
jdbcDataSource.setPassword(DbPassword);
this.db = Db.open(jdbcDataSource, Iciql.Mode.PROD);
DatabaseUpgrader upgrader = new DatabaseUpgrader();
db.setDbUpgrader(upgrader);
this.db is for a private Db db;
instance var I have for the database helper class. My upgrader doesn't do anything right now except print out messages on when it is being called - nothing is printing out and not setting the upgrader doesn't do anything.
Here's the full stack trace:
Connection string for the db (the file gets created and I can connect to it via the h2 tools) looks like:
jdbc:h2:file:/Users/test/my-test-project/run/data/my-test
I read through a lot of the iciql code trying to figure out where the table get's automatically created. I've also read through the tests to try to adjust my code to resemble working test code. Still, no luck.
The project is confidential, so I can't include any of it here, unfortunately. But the above is fairly close. I'm pretty much blocked at this point
Here's the full stack trace:
Exception in thread "main" com.iciql.IciqlException: Table "MY_TEST" not found; SQL statement:
select * from my_test where exchange = ? [42102-197]
at com.iciql.Db.executeQuery(Db.java:796)
at com.iciql.DaoProxy.executeQuery(DaoProxy.java:190)
at com.iciql.DaoProxy.invoke(DaoProxy.java:117)
at com.sun.proxy.$Proxy39.findExchange(Unknown Source)
at com.my-test.services.ExchangeCacheService.fetchDataFromDatabase(ExchangeCacheService.java:180)
at com.my-test.services.ExchangeCacheService.getExchangeData(ExchangeCacheService.java:51)
at com.my-test.Application.main(Application.java:50)
Caused by: org.h2.jdbc.JdbcSQLException: Table "MY_TEST" not found; SQL statement:
select * from my_test where exchange = ? [42102-197]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:357)
at org.h2.message.DbException.get(DbException.java:179)
at org.h2.message.DbException.get(DbException.java:155)
at org.h2.command.Parser.readTableOrView(Parser.java:5920)
at org.h2.command.Parser.readTableFilter(Parser.java:1430)
at org.h2.command.Parser.parseSelectSimpleFromPart(Parser.java:2138)
at org.h2.command.Parser.parseSelectSimple(Parser.java:2287)
at org.h2.command.Parser.parseSelectSub(Parser.java:2133)
at org.h2.command.Parser.parseSelectUnion(Parser.java:1946)
at org.h2.command.Parser.parseSelect(Parser.java:1919)
at org.h2.command.Parser.parsePrepared(Parser.java:463)
at org.h2.command.Parser.parse(Parser.java:335)
at org.h2.command.Parser.parse(Parser.java:307)
at org.h2.command.Parser.prepareCommand(Parser.java:278)
at org.h2.engine.Session.prepareLocal(Session.java:611)
at org.h2.engine.Session.prepareCommand(Session.java:549)
at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1247)
at org.h2.jdbc.JdbcPreparedStatement.<init>(JdbcPreparedStatement.java:76)
at org.h2.jdbc.JdbcConnection.prepareStatement(JdbcConnection.java:304)
at com.iciql.Db.executeQuery(Db.java:786)
Thanks.
Hi,
I have a problem when using iciql package with gradle (compile 'com.gitblit.iciql:iciql:2.1.1'
)
When trying to build the project, this error occurred:
Error:trouble processing "java/lang/AutoCloseable.class"
Error:Ill-advised or mistaken usage of a core class (java.* or javax.*)
Error:when not building a core library.
Error:This is often due to inadvertently including a core library file
Error:in your application's project, when using an IDE (such as
Error:Eclipse). If you are sure you're not intentionally defining a
Error:core class, then this is the most likely explanation of what's
Error:going on.
Hi
I use in my application a generic (CRUD) dao. The interface is simple/generic enough:
public interface GenericDao<T extends Identifiable<ID>, ID extends Serializable> {
/**
* Returns the {@link Identifiable} entity with the specified identifier.
*
* @param id
* @return
*/
public T findById(ID id);
/**
* Returns all the {@link Identifiable} entities.
*
* @return
*/
public List<T> findAll();
/**
* Stores the {@link Identifiable} entity.
*
* @param entity
* @return
*/
public T save(T entity);
/**
* Removes the {@link Identifiable} entity.
*
* @param id
*/
public boolean deleteById(ID id);
/**
* Returns the total number of entities.
* @return
*/
public long count();
}
public interface EntityDao<T extends Entity> extends GenericDao<T, Long> {
}
I am using with success two particular implementation InMemory
and Csv
for fast prototype and testing.
My intention is to add a Iciql
implementation for the case when I use the application in prod.
I see from https://github.com/gitblit/iciql/blob/master/src/main/java/com/iciql/DaoProxy.java#L540 that in theory it is possible to achieve this.
Can you provide me some snippet about the best implementation for a IciqlGenericDao
?
Is it possible a signature like this for a custom Dao?
public interface CustomerDao extends EntityDao<Customer> {
public Customer findByEmail(String email);
}
public class CsvCustomerDao extends IciqlEntityDao<Customer> implements CustomerDao {
public Customer findByEmail(String email) {
// annotation or an elegant/simple code
}
}
Hi,
I develop a system based on DB2, and I'd like to use this for testing.
However JDBC drivers provided by IBM in http://www-01.ibm.com/support/docview.wss?uid=swg21601089 are
"com.ibm.db2.jcc.DB2Driver" and "COM.ibm.db2.jdbc.app.DB2Driver".
Is "COM.ibm.db2.jdbc.net.DB2Driver" right name?
I try to use the iciql builtin support for database and table versioning.
I read http://iciql.com/table_versioning.html but I want to supply a feedback. My main goal of this post is to validate my approach.
The problem:
Date createdDate
to my User
entityI understand from documentation that I must add the IQVersion
annotation on User
class definition. My User
class now looks like:
@Iciql.IQVersion(1)
public class User extends IciqlEntity {
// old properties annotated with @IQColumn
@Iciql.IQColumn
private Date createdDate;
// getters and setters
}
Also I understand that I must create a DbUpgrader
. So I created EntitiesUpgrader
:
@Iciql.IQVersion(1)
public class EntitiesUpgrader implements DbUpgrader {
@Override
public boolean upgradeDatabase(Db db, int fromVersion, int toVersion) {
System.out.println("EntitiesUpgrader.upgradeDatabase");
System.out.println("fromVersion = " + fromVersion);
System.out.println("toVersion = " + toVersion);
return false;
}
@Override
public boolean upgradeTable(Db db, String schema, String table, int fromVersion, int toVersion) {
System.out.println("EntitiesUpgrader.upgradeTable");
return false;
}
}
When I run my application I see in console:
EntitiesUpgrader.upgradeDatabase
fromVersion = 0
toVersion = 1
My first question is:
upgradeTable
method?I understand that I must create a custom dao V1Upgrade
that contains all my modifications and use this class in my DbUpgrader.upgradeDatabase
with if (toVersion == 1) _do_my_modifications_
.
public interface V1Upgrade extends Dao {
@SqlStatement("ALTER TABLE USER ADD COLUMN CREATEDDATE DATE")
void updateUserTable();
}
I use h2
db so maybe it's an option to add a default value in updateUserTable
.
Again, I prefer the freedom of Dao from JDBI:
public interface MyDao {
@SqlUpdate("create table something (id int primary key, name varchar(100))")
void createSomethingTable();
@SqlUpdate("insert into something (id, name) values (:id, :name)")
void insert(@Bind("id") int id, @Bind("name") String name);
@SqlQuery("select name from something where id = :id")
String findNameById(@Bind("id") int id);
}
or
public interface SomeQueries {
@SqlQuery("select name from something where id = :id")
String findName(@Bind("id") int id);
@SqlQuery("select name from something where id > :from and id < :to")
List<String> findNamesBetween(@Bind("from") int from, @Bind("to") int to);
@SqlQuery("select name from something")
Iterator<String> findAllNames();
}
I don't want to be forced to extend a Crud/Generic Dao
. The Crud
operations are useful in some contexts but in the DbUpgrader context I don't see the utility. This is only an observation, maybe it's more clear for me and it's not a real issue for other people.
In the past, I implemented a similar concept for one project and I can say that this feature from Iciql
is very useful.
I wrote a iciql
module for my proof of concept generic dao project that try to use open session in view pattern. I don't know if it's a correct approach to use Iciql
.
In one of my project (web project using Pippo) I used the above generic dao with success. All I need to do is to supply a IciqlDbFactory that contains a single method Db getDb()
.
So my concrete implementation is:
public class IciqlDao<T extends Entity> extends IciqlEntityDao<T> {
public IciqlDao() {
this(DbUtils::getDb);
}
}
public class DbUtils {
// private static final String url = "jdbc:h2:mem:matilda";
private static final String url = "jdbc:h2:./data/matilda";
private static final String username = "";
private static final String password = "";
private static DataSource dataSource;
private static Db genericDb;
static {
dataSource = JdbcConnectionPool.create(url, username, password);
}
public static Db getDb() {
RouteContext routeContext = getRouteContext();
if (routeContext == null) {
// no http request response cycle
if (genericDb == null) {
log.debug("Create generic Db instance");
genericDb = createDb();
}
return genericDb;
}
Db db = routeContext.getLocal("db");
if (db == null) {
log.debug("Create request Db instance");
db = createDb();
// share db instance using local storage
routeContext.setLocal("db", db);
}
return db;
}
public static void closeDb() {
RouteContext routeContext = getRouteContext();
if (routeContext == null) {
if (genericDb != null) {
log.debug("Close generic Db instance");
genericDb.close();
}
} else {
Db db = routeContext.removeLocal("db");
if (db != null) {
log.debug("Close request Db instance");
db.close();
}
}
}
private static RouteContext getRouteContext() {
return RouteDispatcher.getRouteContext();
}
private static Db createDb() {
Db db = Db.open(dataSource);
db.setDbUpgrader(new EntitiesUpgrader());
return db;
}
}
Any observation is welcome. Is my approach a good one?
Hi,
It looks that http://gitblit.github.io/iciql/maven/ is missing a <dependency>
section.
As far as I've tried, I need to add a <dependency>
section in pom.xml, like:
<repositories>
<repository>
<id>com.iciql</id>
<name>Iciql</name>
<url>http://gitblit.github.io/iciql/maven/</url>
<layout>default</layout>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.iciql</groupId>
<artifactId>iciql</artifactId>
<version>1.6.4</version>
</dependency>
</dependencies>
Thank you in advance,
The model class is:
@IQTable
class User {
@IQColumn(primaryKey = true, autoIncrement = true)
var id: Long = 0
@IQColumn
var name: String? = null
}
The SQL DSL is working with id field:
val user = User()
val users = db.from(user).where(user.id).`is`(1).select()
The SQL DSL is NOT working with "String" type filed:
val user = User()
val users = db.from(user).where(user.name).`is`("Tom").select()
The above code will generate compile error.
It looked the method
public <A> QueryCondition<T, A> where(A x)
was conflict with method
public QueryWhere<T> where(String fragment, Object... args)
when the filed type is "String".
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.