Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id D6339200CD8 for ; Wed, 2 Aug 2017 14:34:50 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id D2E0C169533; Wed, 2 Aug 2017 12:34:50 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 22D07169532 for ; Wed, 2 Aug 2017 14:34:49 +0200 (CEST) Received: (qmail 87182 invoked by uid 500); 2 Aug 2017 12:34:49 -0000 Mailing-List: contact user-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@ignite.apache.org Delivered-To: mailing list user@ignite.apache.org Received: (qmail 87171 invoked by uid 99); 2 Aug 2017 12:34:49 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 Aug 2017 12:34:49 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 8CB911807F3 for ; Wed, 2 Aug 2017 12:34:48 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.853 X-Spam-Level: * X-Spam-Status: No, score=1.853 tagged_above=-999 required=6.31 tests=[DKIM_ADSP_CUSTOM_MED=0.001, NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_NONE=-0.0001, SPF_NEUTRAL=0.652] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id qQ8BqbZQ_yj1 for ; Wed, 2 Aug 2017 12:34:46 +0000 (UTC) Received: from mwork.nabble.com (mwork.nabble.com [162.253.133.43]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id E8D095FB62 for ; Wed, 2 Aug 2017 12:34:45 +0000 (UTC) Received: from static.162.255.23.37.macminivault.com (unknown [162.255.23.37]) by mwork.nabble.com (Postfix) with ESMTP id 66B6A58689E33 for ; Wed, 2 Aug 2017 05:34:44 -0700 (MST) Date: Wed, 2 Aug 2017 05:34:44 -0700 (MST) From: anas4120 To: user@ignite.apache.org Message-ID: <1501677284421-15899.post@n6.nabble.com> In-Reply-To: <1501668065400-15888.post@n6.nabble.com> References: <759409871.5216233.1501593451202@mail.yahoo.com> <1501654065995-15878.post@n6.nabble.com> <1501665878319-15885.post@n6.nabble.com> <1501668065400-15888.post@n6.nabble.com> Subject: Re: How to manage sequence with legacy database having auto increment id MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit archived-at: Wed, 02 Aug 2017 12:34:51 -0000 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.