Return-Path: X-Original-To: apmail-cayenne-user-archive@www.apache.org Delivered-To: apmail-cayenne-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8FDCE18A5F for ; Fri, 22 Jan 2016 21:07:04 +0000 (UTC) Received: (qmail 1786 invoked by uid 500); 22 Jan 2016 21:07:04 -0000 Delivered-To: apmail-cayenne-user-archive@cayenne.apache.org Received: (qmail 1753 invoked by uid 500); 22 Jan 2016 21:07:04 -0000 Mailing-List: contact user-help@cayenne.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@cayenne.apache.org Delivered-To: mailing list user@cayenne.apache.org Received: (qmail 1741 invoked by uid 99); 22 Jan 2016 21:07:04 -0000 Received: from Unknown (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 Jan 2016 21:07:04 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id BD328C0D58 for ; Fri, 22 Jan 2016 21:07:03 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 3.001 X-Spam-Level: *** X-Spam-Status: No, score=3.001 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=3, URIBL_BLOCKED=0.001] autolearn=disabled Authentication-Results: spamd4-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=masslight-net.20150623.gappssmtp.com Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id Ge3gUTPTq6Is for ; Fri, 22 Jan 2016 21:06:53 +0000 (UTC) Received: from mail-wm0-f52.google.com (mail-wm0-f52.google.com [74.125.82.52]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with ESMTPS id 67DEA21195 for ; Fri, 22 Jan 2016 21:06:52 +0000 (UTC) Received: by mail-wm0-f52.google.com with SMTP id n5so151040923wmn.0 for ; Fri, 22 Jan 2016 13:06:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=masslight-net.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=MOGcKYYvWQArK0R5QItSSplHhbcqCLy/nabHP3zckKs=; b=NAHoSwCPeVIWNmRTG9y4DgxP/+7qmcBuRdPwMfi0mBole0gNV+bwEzPVGHXPts5SWj dzqVnWI6nef/5af6K49GAgQQ1Mrf938lYwFcgWCdgy4p/S8MI3E9K2vZHNLCudMd/hGc L24f7JMe9oQqeu09J5D6GmE14J3ve+dPENH0MR3IoaUedUaTpNWsdHXtxv9kB1MHeBpI lQUVzwMx47jQq7KVBec1o9a1qx49InmOBIC4LdPOovxB3FXq/lvddPpSZYKZ23BQE3Ab AilAcklAVQ8T1S80q34okzFJn4qYqh9qLHy8oCrjWzns4ZbG/bZroiPW7LPl+7ZHZmSU NKug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type; bh=MOGcKYYvWQArK0R5QItSSplHhbcqCLy/nabHP3zckKs=; b=R/XvMFV9xVcMxdU0jHFZhmumacRaAuh8x4meGvWG2uIGR+PclCn/B+npCPTJedyHaW iKd8e1zjm+PP6BjF6HzdAr5TecdayxyNsH/cZWqsfe0JUq5E0StbAWiJmlmIJaLafW1A F/zdxERTRYVNpy16UTHv/ZhcUQYCT1JQjPr2RS4y2IU6D8Tg52I3QaxoH/VLzDSczwdd nJ5MO9sj1biXsD6A6HfmXwX9h/GmBVESbJ8Ji6DLngoKKqBqOfmkN5I2J6D4vV1osUqt wvrq09Sfk8XQqZ6GeEsOujBZHDdvDJ0QsSri5VjvADkqK2rh9vE57wLfxSC66mDWSN/X 3UwA== X-Gm-Message-State: AG10YOS0SnFSu1MsP4emLrBlzZadWjEG9YKLz8h+JblWqbkVPqbK5nvDYKbeOxBSpkrVh6ZX9LHidIwjbnzelQ== X-Received: by 10.28.126.84 with SMTP id z81mr5739824wmc.29.1453496805869; Fri, 22 Jan 2016 13:06:45 -0800 (PST) MIME-Version: 1.0 Received: by 10.28.55.208 with HTTP; Fri, 22 Jan 2016 13:06:26 -0800 (PST) In-Reply-To: References: <37AF141A-E9DB-4D2A-A5B2-FF720CDAD669@karlmenn.is> <4726C965-D8F8-48D4-A7AD-ADFE7E2221BB@karlmenn.is> From: Michael Gentry Date: Fri, 22 Jan 2016 16:06:26 -0500 Message-ID: Subject: Re: Changing database connection programmatically To: Cayenne Users Content-Type: multipart/alternative; boundary=001a1141a21ecbe4700529f29891 --001a1141a21ecbe4700529f29891 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Yeah, that's pretty much what I did for my Cayenne 3.1 unit tests, although I don't like inner classes, so I did it separately. Also didn't use the expression chaining, but still, very similar concept-wise. On Fri, Jan 22, 2016 at 3:52 PM, Andrus Adamchik wrote: > In addition to Mike and Savva's suggestions, I wanted to point to our > LinkRest unit tests. Here is a base class (ignore the Jersey part, just > focus on Cayenne and Derby) [1]. > > * It manages a lifecycle of a Derby DB instance via simple DerbyManager, > ensuring filesystem folders are cleaned up between the runs. > * Cayenne XML is DataNode-less [2], expecting you to define the DataSourc= e > via API in the unit test (as well as in the main app .. not in this examp= le > though). > * ServerRuntime creation procedure includes making an in-memory DataSourc= e > and a unit test SchemaUpdateStrategy: > > CAYENNE_RUNTIME =3D new ServerRuntimeBuilder() > .addConfig("cayenne-linkrest-tests.xml") > .addModule(new Module() { > > // Java 7; for Java 8 you can use a lambda for the Module > @Override > public void configure(Binder binder) { > > binder.bind(SchemaUpdateStrategy.class).to(CreateIfNoSchemaStrategy.class= ); > } > }) > .jdbcDriver("org.apache.derby.jdbc.EmbeddedDriver") > .url("jdbc:derby:target/derby;create=3Dtrue") > .build(); > > Hope this helps. > > Andrus > > [1] > https://github.com/nhl/link-rest/blob/master/src/test/java/com/nhl/link/r= est/it/fixture/JerseyTestOnDerby.java > [2] > https://github.com/nhl/link-rest/blob/master/src/test/resources/cayenne-l= inkrest-tests.xml > > Andrus > > > On Jan 22, 2016, at 9:50 PM, Hugi Thordarson wrote: > > > > Ah, sorry about that=E2=80=A6 I=E2=80=99m using the current 4.0 snapsho= ts. > > > > - hugi > > > > > > > >> On 22. jan. 2016, at 18:47, Michael Gentry > wrote: > >> > >> Which version of Cayenne are you using? > >> > >> > >> On Fri, Jan 22, 2016 at 1:25 PM, Hugi Thordarson > wrote: > >> > >>> Hi all, > >>> > >>> I=E2=80=99m writing some tests for my DataObjects. Before the tests r= un, I=E2=80=99d > like > >>> to provision an h2 database and switch my model=E2=80=99s connection = to it for > the > >>> purpose of testing. > >>> > >>> What=E2=80=99s the preferred way to switch the connection programmati= cally? > >>> > >>> Cheers, > >>> - hugi > > > > --001a1141a21ecbe4700529f29891--