What I'm trying to achieve is similar to Spring JDBC framework. In Spring
JDBC template API there is a way to delegate ID incrementation to database,
for example: 

*....
Customer customer=new Customer();
customer.setLogin("toto")
customer.setFirstname("toto");
customer.setLastname(("Skilatchi");
.... 

GeneratedKeyHolder keyHolder = new GeneratedKeyHolder();
final Timestamp NOW=new Timestamp(System.currentTimeMillis());
JDBC_TEMPLATE.update(
                                        (Connection connection) -> {
                                                PreparedStatement ps = 
connection.prepareStatement(
                                                        "INSERT INTO CUSTOMER 
(login, firstname, lastname, phone, email, age,
creation_date, update_date) VALUES (?,?,?,?,?,?,?,?)"
                                                        ,new String[] {"id"}
                                                );
                                                int index=1;
                                                ps.setString(index++, 
customer.getLogin());
                                                
ps.setString(index++,customer.getFirstname());
                                                ps.setString(index++, 
customer.getLastname());
                                                ps.setString(index++, 
customer.getPhone());
                                                ps.setString(index++, 
customer.getEmail());
                                                ps.setInt(index++, 
customer.getAge());
                                                ps.setTimestamp(index++, NOW);
                                                ps.setTimestamp(index++, NOW);
                                                return ps;
                                        }
                                        ,keyHolder
);
customer.setId(keyHolder.getKey().longValue());
...*


After creation, the Customer.id attribute is populated automaticly with the
generated ID in database by using GeneratedKeyHolder. 

Thanks. 




Humphrey wrote
> Look here [1] on how to use the IgniteAtomicSequence.
> You can set a value for which you want to start counting.
> 
> I'm not sure what you are trying to achieve? Why not pass the Id to the
> query?
> cache.query(new SqlFieldsQuery("INSERT INTO CUSTOMER (id, login, email,
> age) VALUES (?,?,?,?)")
>                         .setArgs(
>                             ID
>                             ,customer.getLogin()
>                             ,customer.getEmail() 
>                             ,customer.getAge()
>                         )
> 
> I'm not sure how Ignite should be configured if your database has an
> autoincrement field for ID, how this should be implemented in the cache
> configuration. Maybe just leave the field ID out from the cacheCofig?
> 
> [1] https://apacheignite.readme.io/docs/id-generator





--
View this message in context: 
http://apache-ignite-users.70518.x6.nabble.com/How-to-manage-sequence-with-legacy-database-having-auto-increment-id-tp15857p15899.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Reply via email to