Return-Path: X-Original-To: apmail-cayenne-commits-archive@www.apache.org Delivered-To: apmail-cayenne-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6699AE6D0 for ; Mon, 7 Jan 2013 20:24:13 +0000 (UTC) Received: (qmail 20473 invoked by uid 500); 7 Jan 2013 20:24:13 -0000 Delivered-To: apmail-cayenne-commits-archive@cayenne.apache.org Received: (qmail 20443 invoked by uid 500); 7 Jan 2013 20:24:13 -0000 Mailing-List: contact commits-help@cayenne.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cayenne.apache.org Delivered-To: mailing list commits@cayenne.apache.org Received: (qmail 20345 invoked by uid 99); 7 Jan 2013 20:24:12 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 07 Jan 2013 20:24:12 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 07 Jan 2013 20:24:10 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id A9DBC23889DA; Mon, 7 Jan 2013 20:23:49 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1429993 - in /cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/dba/JdbcPkGenerator.java test/java/org/apache/cayenne/dba/JdbcPkGeneratorTest.java Date: Mon, 07 Jan 2013 20:23:49 -0000 To: commits@cayenne.apache.org From: aadamchik@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130107202349.A9DBC23889DA@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: aadamchik Date: Mon Jan 7 20:23:49 2013 New Revision: 1429993 URL: http://svn.apache.org/viewvc?rev=1429993&view=rev Log: CAY-1783 JdbcPkGenerator.longPkFromDatabase would throw an exception if the PK value exceeds a range of Java int Added: cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/dba/JdbcPkGeneratorTest.java Modified: cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/JdbcPkGenerator.java Modified: cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/JdbcPkGenerator.java URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/JdbcPkGenerator.java?rev=1429993&r1=1429992&r2=1429993&view=diff ============================================================================== --- cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/JdbcPkGenerator.java (original) +++ cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/JdbcPkGenerator.java Mon Jan 7 20:23:49 2013 @@ -50,10 +50,12 @@ import org.apache.cayenne.util.IDUtil; public class JdbcPkGenerator implements PkGenerator { public static final int DEFAULT_PK_CACHE_SIZE = 20; + private static final long DEFAULT_PK_START_VALUE = 200; protected JdbcAdapter adapter; protected Map pkCache = new HashMap(); protected int pkCacheSize = DEFAULT_PK_CACHE_SIZE; + protected long pkStartValue = DEFAULT_PK_START_VALUE; public JdbcPkGenerator(JdbcAdapter adapter) { this.adapter = adapter; @@ -142,7 +144,7 @@ public class JdbcPkGenerator implements .append(" (TABLE_NAME, NEXT_ID)") .append(" VALUES ('") .append(entName) - .append("', 200)"); + .append("', ").append(pkStartValue).append(")"); return buf.toString(); } @@ -331,6 +333,14 @@ public class JdbcPkGenerator implements public void setPkCacheSize(int pkCacheSize) { this.pkCacheSize = (pkCacheSize < 1) ? 1 : pkCacheSize; } + + long getPkStartValue() { + return pkStartValue; + } + + void setPkStartValue(long startValue) { + this.pkStartValue = startValue; + } public void reset() { pkCache.clear(); @@ -352,13 +362,13 @@ public class JdbcPkGenerator implements return false; } - public int getId() { + public long getId() { if (id == null) { throw new CayenneRuntimeException("No key was retrieved for entity " + entityName); } - return id.intValue(); + return id.longValue(); } public void nextRows(Query query, List dataRows) { Added: cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/dba/JdbcPkGeneratorTest.java URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/dba/JdbcPkGeneratorTest.java?rev=1429993&view=auto ============================================================================== --- cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/dba/JdbcPkGeneratorTest.java (added) +++ cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/dba/JdbcPkGeneratorTest.java Mon Jan 7 20:23:49 2013 @@ -0,0 +1,60 @@ +/***************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + ****************************************************************/ +package org.apache.cayenne.dba; + +import java.util.Collections; + +import org.apache.cayenne.access.DataNode; +import org.apache.cayenne.di.Inject; +import org.apache.cayenne.map.DbAttribute; +import org.apache.cayenne.map.DbEntity; +import org.apache.cayenne.testdo.testmap.Artist; +import org.apache.cayenne.unit.di.server.ServerCase; +import org.apache.cayenne.unit.di.server.UseServerRuntime; + +@UseServerRuntime(ServerCase.TESTMAP_PROJECT) +public class JdbcPkGeneratorTest extends ServerCase { + + @Inject + private DbAdapter adapter; + + @Inject + private DataNode node; + + public void testLongPk() throws Exception { + + if (!JdbcPkGenerator.class.isAssignableFrom(adapter.getPkGenerator().getClass())) { + return; + } + + DbEntity artistEntity = node.getEntityResolver().lookupObjEntity(Artist.class).getDbEntity(); + + DbAttribute pkAttribute = (DbAttribute) artistEntity.getAttribute(Artist.ARTIST_ID_PK_COLUMN); + + JdbcPkGenerator pkGenerator = (JdbcPkGenerator) adapter.getPkGenerator(); + + pkGenerator.setPkStartValue(Integer.MAX_VALUE * 2l); + pkGenerator.createAutoPk(node, Collections.singletonList(artistEntity)); + pkGenerator.reset(); + + Object pk = pkGenerator.generatePk(node, pkAttribute); + assertTrue(pk instanceof Long); + assertTrue("PK is too small: " + pk, ((Long) pk).longValue() > Integer.MAX_VALUE); + } +}