OPENJPA-322 reverted change #567170 to restore previous behavior of TimeZones in Calendar fields; added test case to confirm that the Calendar fields behave as expected

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@586649 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Marc Prud'hommeaux 2007-10-20 00:49:37 +00:00
parent ba6274a19e
commit 61c789dbaf
5 changed files with 79 additions and 6 deletions

View File

@ -92,10 +92,7 @@ class SingleFieldManager
proxy = checkProxy();
if (proxy == null) {
proxy = (Proxy) _sm.newFieldProxy(field);
Calendar pcal = (Calendar) proxy;
Calendar ocal = (Calendar) objval;
pcal.setTime (ocal.getTime ());
pcal.setTimeZone (ocal.getTimeZone ());
((Calendar) proxy).setTime(((Calendar) objval).getTime());
ret = true;
}
break;

View File

@ -18,8 +18,6 @@
*/
package org.apache.openjpa.util;
import java.util.TimeZone;
/**
* Interface implemented by all generated proxies on {@link java.util.Calendar}
* types.

View File

@ -0,0 +1,57 @@
/*
* 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.openjpa.jdbc.meta;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Calendar;
import java.util.TimeZone;
import org.apache.openjpa.persistence.OpenJPAPersistence;
import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
import org.apache.openjpa.persistence.simple.TemporalFieldTypes;
import org.apache.openjpa.persistence.test.SingleEMTestCase;
public class TestCalendarField extends SingleEMTestCase {
public void setUp() {
setUp(TemporalFieldTypes.class);
}
public void testCalendarField() throws IOException, SQLException {
TimeZone tz = TimeZone.getTimeZone("Europe/Budapest");
for (TemporalFieldTypes t : find(TemporalFieldTypes.class))
remove(t);
TemporalFieldTypes tft;
tft = new TemporalFieldTypes();
assertEquals(tz, tft.getCalendarTimeZoneField().getTimeZone());
persist(tft);
// get a fresh EM
reset();
tft = find(TemporalFieldTypes.class).get(0);
assertEquals(tz, tft.getCalendarTimeZoneField().getTimeZone());
}
}

View File

@ -20,6 +20,7 @@ package org.apache.openjpa.persistence.simple;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
import javax.persistence.Entity;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
@ -51,6 +52,9 @@ public class TemporalFieldTypes {
@Temporal(TemporalType.TIMESTAMP)
private Calendar calendarTimestampField;
private Calendar calendarTimeZoneField =
Calendar.getInstance(TimeZone.getTimeZone("Europe/Budapest"));
public void setDateDefaultField(Date date) {
this.dateDefaultField = date;
}
@ -114,4 +118,13 @@ public class TemporalFieldTypes {
public Calendar getCalendarTimeStampField() {
return this.calendarTimestampField;
}
public void setCalendarTimeZoneField(Calendar calendarTimeZoneField) {
this.calendarTimeZoneField = calendarTimeZoneField;
}
public Calendar getCalendarTimeZoneField() {
return this.calendarTimeZoneField;
}
}

View File

@ -47,6 +47,14 @@ public abstract class SingleEMTestCase
em = emf.createEntityManager();
}
/**
* Clear the current EntityManager and re-initialize it.
*/
protected void reset() {
close();
em = emf.createEntityManager();
}
@Override
public void tearDown() throws Exception {
rollback();