-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug fix: When saving an entity, that was saved with an aggregate obje…
…ct that contains null values, with a null value for an aggregate then EclipseLink will still generate an update statement for that record field changing it from NULL to NULL, but it should not do that as there was no change.
- Loading branch information
Showing
7 changed files
with
339 additions
and
1 deletion.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
...elink.core.test/src/org/eclipse/persistence/testing/models/aggregate/SimpleAggregate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright (c) 1998, 2018 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, | ||
* or the Eclipse Distribution License v. 1.0 which is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause | ||
*/ | ||
package org.eclipse.persistence.testing.models.aggregate; | ||
|
||
public class SimpleAggregate { | ||
private String content; | ||
|
||
public String getContent() { | ||
return content; | ||
} | ||
|
||
public void setContent(String content) { | ||
this.content = content; | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
...ore.test/src/org/eclipse/persistence/testing/models/aggregate/SimpleAggregateProject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Copyright (c) 1998, 2018 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, | ||
* or the Eclipse Distribution License v. 1.0 which is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause | ||
*/ | ||
package org.eclipse.persistence.testing.models.aggregate; | ||
|
||
import org.eclipse.persistence.descriptors.ChangedFieldsLockingPolicy; | ||
import org.eclipse.persistence.descriptors.ClassDescriptor; | ||
import org.eclipse.persistence.descriptors.RelationalDescriptor; | ||
import org.eclipse.persistence.mappings.AggregateObjectMapping; | ||
import org.eclipse.persistence.mappings.DirectToFieldMapping; | ||
|
||
public class SimpleAggregateProject extends org.eclipse.persistence.sessions.Project { | ||
|
||
public SimpleAggregateProject() { | ||
applyPROJECT(); | ||
applyLOGIN(); | ||
|
||
addDescriptor(buildSimpleAggregateClassDescriptor()); | ||
addDescriptor(buildSimpleEntityDescriptor()); | ||
} | ||
|
||
protected void applyLOGIN() { | ||
} | ||
|
||
protected void applyPROJECT() { | ||
setName("SimpleAggregateSystem"); | ||
} | ||
|
||
public ClassDescriptor buildSimpleAggregateClassDescriptor() { | ||
RelationalDescriptor descriptor = new RelationalDescriptor(); | ||
descriptor.descriptorIsAggregate(); | ||
descriptor.setJavaClass(SimpleAggregate.class); | ||
|
||
// ClassDescriptor Properties. | ||
descriptor.setAlias("SimpleAggregate"); | ||
|
||
|
||
// Query Manager. | ||
|
||
|
||
// Event Manager. | ||
|
||
// Mappings. | ||
DirectToFieldMapping contentMapping = new DirectToFieldMapping(); | ||
contentMapping.setAttributeName("content"); | ||
contentMapping.setFieldName("content->DIRECT"); | ||
descriptor.addMapping(contentMapping); | ||
|
||
return descriptor; | ||
} | ||
|
||
protected ClassDescriptor buildSimpleEntityDescriptor() { | ||
RelationalDescriptor descriptor = new RelationalDescriptor(); | ||
//descriptor.setCacheable(false); | ||
|
||
// SECTION: DESCRIPTOR | ||
descriptor.setJavaClass(SimpleEntity.class); | ||
descriptor.addTableName("SIMPLEENTITY"); | ||
descriptor.addPrimaryKeyFieldName("SIMPLEENTITY.ID"); | ||
|
||
ChangedFieldsLockingPolicy lockingPolicy = new ChangedFieldsLockingPolicy(); | ||
descriptor.setOptimisticLockingPolicy(lockingPolicy); | ||
|
||
// SECTION: DIRECTTOFIELDMAPPING | ||
DirectToFieldMapping directtofieldmapping = new DirectToFieldMapping(); | ||
directtofieldmapping.setAttributeName("id"); | ||
directtofieldmapping.setIsReadOnly(false); | ||
directtofieldmapping.setFieldName("SIMPLEENTITY.ID"); | ||
descriptor.addMapping(directtofieldmapping); | ||
|
||
DirectToFieldMapping fieldmapping = new DirectToFieldMapping(); | ||
fieldmapping.setAttributeName("field"); | ||
fieldmapping.setIsReadOnly(false); | ||
fieldmapping.setFieldName("SIMPLEENTITY.FIELD"); | ||
descriptor.addMapping(fieldmapping); | ||
|
||
AggregateObjectMapping aggregateObjectMapping = new AggregateObjectMapping(); | ||
aggregateObjectMapping.setAttributeName("simpleAggregate"); | ||
aggregateObjectMapping.setReferenceClass(SimpleAggregate.class); | ||
aggregateObjectMapping.setIsNullAllowed(true); | ||
aggregateObjectMapping.addFieldNameTranslation("SIMPLEENTITY.CONTENT", "content->DIRECT"); | ||
descriptor.addMapping(aggregateObjectMapping); | ||
|
||
return descriptor; | ||
} | ||
|
||
} |
87 changes: 87 additions & 0 deletions
87
...core.test/src/org/eclipse/persistence/testing/models/aggregate/SimpleAggregateSystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright (c) 1998, 2018 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, | ||
* or the Eclipse Distribution License v. 1.0 which is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause | ||
*/ | ||
package org.eclipse.persistence.testing.models.aggregate; | ||
|
||
import org.eclipse.persistence.queries.ReadObjectQuery; | ||
import org.eclipse.persistence.sessions.DatabaseSession; | ||
import org.eclipse.persistence.sessions.UnitOfWork; | ||
import org.eclipse.persistence.testing.framework.TestSystem; | ||
import org.eclipse.persistence.testing.tests.dynamic.QuerySQLTracker; | ||
import org.eclipse.persistence.tools.schemaframework.SchemaManager; | ||
|
||
public class SimpleAggregateSystem extends TestSystem { | ||
|
||
public SimpleAggregateSystem() { | ||
project = new SimpleAggregateProject(); | ||
} | ||
|
||
@Override | ||
public void addDescriptors(DatabaseSession session) { | ||
if (project == null) { | ||
project = new SimpleAggregateProject(); | ||
} | ||
session.addDescriptors(project); | ||
} | ||
|
||
@Override | ||
public void createTables(DatabaseSession session) { | ||
SchemaManager schemaManager = new SchemaManager(session); | ||
|
||
schemaManager.replaceObject(SimpleEntity.tableDefinition()); | ||
} | ||
|
||
@Override | ||
public void populate(DatabaseSession session) { | ||
|
||
QuerySQLTracker qTracker = QuerySQLTracker.install(session); | ||
|
||
{ | ||
UnitOfWork uow = session.acquireUnitOfWork(); | ||
|
||
SimpleEntity instance = new SimpleEntity(); | ||
instance.setId("1"); | ||
instance.setField("constant"); | ||
instance.setSimpleAggregate(new SimpleAggregate()); | ||
session.writeObject(instance); | ||
uow.registerObject(instance); | ||
uow.commit(); | ||
} | ||
|
||
{ | ||
UnitOfWork uow = session.acquireUnitOfWork(); | ||
|
||
ReadObjectQuery query = new ReadObjectQuery(); | ||
final SimpleEntity queryInstance = new SimpleEntity(); | ||
queryInstance.setId("1"); | ||
query.setSelectionObject(queryInstance); | ||
final SimpleEntity instance = (SimpleEntity) uow.executeQuery(query); | ||
if (instance == null) { | ||
throw new RuntimeException("Object was not found"); | ||
} | ||
if (instance.getSimpleAggregate() == null) { | ||
//throw new RuntimeException("SimpleAggregate is null"); | ||
} | ||
instance.setSimpleAggregate(instance.getSimpleAggregate() == null ? new SimpleAggregate() : null); | ||
|
||
qTracker.reset(); | ||
|
||
instance.setSimpleAggregate(null); | ||
uow.registerObject(instance); | ||
uow.commit(); | ||
|
||
if (qTracker.getQueries().size() > 0) { | ||
throw new RuntimeException("Unexpected query was executed: " + qTracker.getQueries()); | ||
} | ||
} | ||
|
||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...ipselink.core.test/src/org/eclipse/persistence/testing/models/aggregate/SimpleEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (c) 1998, 2018 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, | ||
* or the Eclipse Distribution License v. 1.0 which is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause | ||
*/ | ||
package org.eclipse.persistence.testing.models.aggregate; | ||
|
||
import org.eclipse.persistence.tools.schemaframework.TableDefinition; | ||
|
||
public class SimpleEntity { | ||
private String id; | ||
private String field; | ||
private SimpleAggregate simpleAggregate; | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
public String getField() { | ||
return field; | ||
} | ||
|
||
public void setField(String field) { | ||
this.field = field; | ||
} | ||
|
||
public SimpleAggregate getSimpleAggregate() { | ||
return simpleAggregate; | ||
} | ||
|
||
public void setSimpleAggregate(SimpleAggregate simpleAggregate) { | ||
this.simpleAggregate = simpleAggregate; | ||
} | ||
|
||
public static TableDefinition tableDefinition() { | ||
TableDefinition definition = new TableDefinition(); | ||
|
||
definition.setName("SIMPLEENTITY"); | ||
|
||
definition.addIdentityField("ID", String.class, 15); | ||
definition.addField("FIELD", String.class, 15); | ||
definition.addField("CONTENT", String.class, 20); | ||
|
||
return definition; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...re.test/src/org/eclipse/persistence/testing/tests/aggregate/SimpleAggregateTestModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (c) 1998, 2018 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, | ||
* or the Eclipse Distribution License v. 1.0 which is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause | ||
*/ | ||
package org.eclipse.persistence.testing.tests.aggregate; | ||
|
||
import org.eclipse.persistence.testing.framework.TestModel; | ||
import org.eclipse.persistence.testing.framework.TestSuite; | ||
import org.eclipse.persistence.testing.models.aggregate.SimpleAggregateSystem; | ||
|
||
public class SimpleAggregateTestModel extends TestModel { | ||
public SimpleAggregateTestModel() { | ||
setDescription("This model tests reading/writing/deleting of the simple aggregate model."); | ||
} | ||
|
||
@Override | ||
public void addForcedRequiredSystems() { | ||
//We need to ensure that the correct database schema is created | ||
addForcedRequiredSystem(new SimpleAggregateSystem()); | ||
} | ||
|
||
@Override | ||
public void addRequiredSystems() { | ||
} | ||
|
||
@Override | ||
public void addTests() { | ||
addTest(getUpdateObjectTestSuite()); | ||
} | ||
|
||
public static TestSuite getUpdateObjectTestSuite() { | ||
TestSuite suite = new TestSuite(); | ||
suite.setName("AggregateUpdateObjectTestSuite"); | ||
suite.setDescription("This suite tests the updating of each object in the aggregate model."); | ||
|
||
return suite; | ||
} | ||
|
||
public static junit.framework.TestSuite suite() { | ||
return new SimpleAggregateTestModel(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters