OPENJPA-1704: Fix PCEnhancer to generate proper readExternal method. Merged to 2.0.x - submitted by Rick Curtis

git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/2.0.x@965610 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Dick 2010-07-19 20:02:23 +00:00
parent dcb8e626a3
commit a2d0e05649
4 changed files with 100 additions and 10 deletions

View File

@ -3230,16 +3230,14 @@ public class PCEnhancer {
// else return false;
ifins.setTarget(code.getstatic().setField(Boolean.class, "FALSE", Boolean.class));
}else{
FieldMetaData versionInit = _meta.getDeclaredField(VERSION_INIT_STR);
// noop
ifins.setTarget(code.nop());
// if (pcVersionInit != false)
// return true
// else return false;
loadManagedInstance(code, false);
getfield(code, null, versionInit.getName());
ifins = ifDefaultValue(code, versionInit);
getfield(code, null, VERSION_INIT_STR);
ifins = code.ifeq();
code.getstatic().setField(Boolean.class, "TRUE", Boolean.class);
code.areturn();
ifins.setTarget(code.nop());
@ -3709,12 +3707,10 @@ public class PCEnhancer {
addSetManagedValueCode(code, fmd);
if(fmd.isVersion()==true && _addVersionInitFlag){
// if we are setting the version, flip the versionInit flag to true
FieldMetaData v = _meta.addDeclaredField(VERSION_INIT_STR, boolean.class);
v.setTransient(true);
loadManagedInstance(code, true);
code.constant().setValue(1);
// pcVersionInit = true;
putfield(code, null, v.getName(), v.getDeclaredType());
putfield(code, null, VERSION_INIT_STR, boolean.class);
}
code.vreturn();

View File

@ -75,6 +75,7 @@
dir="${project.build.testOutputDirectory}">
<include name="**/*.class" />
<exclude name="**/inheritance/serializable/*.class" />
<exclude name="**/detach/serializable/*.class" />
<exclude name="**/xml/*.class" />
<exclude name="**/Unenhanced*.class" />
<exclude name="**/AbstractUnenhanced*.class" />
@ -92,6 +93,7 @@
<classpath refid="cp" />
<fileset dir="${project.build.testOutputDirectory}">
<include name="**/inheritance/serializable/*.class" />
<include name="**/detach/serializable/*.class" />
<!-- include files from orm.xml -->
<include name="**/xml/*.class" />
<exclude name="**/persistence/delimited/identifiers/xml/*.class"/>

View File

@ -0,0 +1,48 @@
/*
* 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.persistence.detach.serializable;
import java.io.Serializable;
import java.sql.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Version;
@Entity
public class SerializableDetachedStateManager implements Serializable {
/**
*
*/
private static final long serialVersionUID = 80701492251635740L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
int id;
@Version
int version;
@Temporal(TemporalType.TIMESTAMP)
Date zDate;
}

View File

@ -0,0 +1,44 @@
/*
* 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.persistence.detach.serializable;
import java.sql.Date;
import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI;
import org.apache.openjpa.persistence.test.AbstractPersistenceTestCase;
import org.apache.openjpa.persistence.test.SingleEMFTestCase;
public class TestSerializableDetachedStateManager extends SingleEMFTestCase {
public void setUp() {
setUp(CLEAR_TABLES, SerializableDetachedStateManager.class, DROP_TABLES, "openjpa.DetachState",
"fgs(DetachedStateField=true)");
}
public void testRoundTrip() throws Exception {
SerializableDetachedStateManager c = new SerializableDetachedStateManager();
c.zDate = new Date(System.currentTimeMillis());
OpenJPAEntityManagerSPI em = emf.createEntityManager();
em.getTransaction().begin();
em.persist(c);
em.getTransaction().commit();
em.close();
AbstractPersistenceTestCase.roundtrip(c);
}
}