diff --git a/cayenne/src/main/java/org/apache/cayenne/access/jdbc/reader/EntityRowReader.java b/cayenne/src/main/java/org/apache/cayenne/access/jdbc/reader/EntityRowReader.java index d6be56bea5..71be824fbe 100644 --- a/cayenne/src/main/java/org/apache/cayenne/access/jdbc/reader/EntityRowReader.java +++ b/cayenne/src/main/java/org/apache/cayenne/access/jdbc/reader/EntityRowReader.java @@ -54,7 +54,7 @@ class EntityRowReader implements RowReader { this.entityName = classDescriptor.getEntity().getName(); } - int segmentWidth = segmentMetadata.getFields().size(); + int segmentWidth = segmentMetadata.getColumnCount(); this.startIndex = segmentMetadata.getColumnOffset(); this.converters = new ExtendedType[segmentWidth]; this.types = new int[segmentWidth]; diff --git a/cayenne/src/main/java/org/apache/cayenne/access/translator/select/DescriptorColumnExtractor.java b/cayenne/src/main/java/org/apache/cayenne/access/translator/select/DescriptorColumnExtractor.java index ef34829d24..6f95329fb3 100644 --- a/cayenne/src/main/java/org/apache/cayenne/access/translator/select/DescriptorColumnExtractor.java +++ b/cayenne/src/main/java/org/apache/cayenne/access/translator/select/DescriptorColumnExtractor.java @@ -151,8 +151,10 @@ public boolean visitToOne(ToOneProperty property) { int count = result.getDbAttributes().size(); for(int i=0; i fields; private int offset; + private int columnCount; public DefaultEntityResultSegment(ClassDescriptor classDescriptor, Map fields, int offset) { + this(classDescriptor, fields, offset, fields != null ? fields.size() : 0); + } + + public DefaultEntityResultSegment(ClassDescriptor classDescriptor, + Map fields, int offset, int columnCount) { this.classDescriptor = classDescriptor; this.fields = fields; this.offset = offset; + this.columnCount = columnCount; } public ClassDescriptor getClassDescriptor() { @@ -47,6 +54,11 @@ public Map getFields() { return fields; } + @Override + public int getColumnCount() { + return columnCount; + } + public int getColumnOffset() { return offset; } diff --git a/cayenne/src/main/java/org/apache/cayenne/map/EntityResult.java b/cayenne/src/main/java/org/apache/cayenne/map/EntityResult.java index 49ba254b48..cb9a814a33 100644 --- a/cayenne/src/main/java/org/apache/cayenne/map/EntityResult.java +++ b/cayenne/src/main/java/org/apache/cayenne/map/EntityResult.java @@ -75,6 +75,13 @@ public Map getDbFields(EntityResolver resolver) { return dbFields; } + /** + * Returns the total number of fields added to this result. + */ + public int getFieldCount() { + return fields != null ? fields.size() : 0; + } + private ObjEntity getRootEntity(EntityResolver resolver) { if (entityName != null) { return resolver.getObjEntity(entityName); diff --git a/cayenne/src/main/java/org/apache/cayenne/map/SQLResult.java b/cayenne/src/main/java/org/apache/cayenne/map/SQLResult.java index 18bde420d7..298d2095a1 100644 --- a/cayenne/src/main/java/org/apache/cayenne/map/SQLResult.java +++ b/cayenne/src/main/java/org/apache/cayenne/map/SQLResult.java @@ -61,6 +61,7 @@ public List getResolvedComponents(EntityResolver resolver) { } else if (component instanceof EntityResult) { EntityResult entityResult = (EntityResult) component; Map fields = entityResult.getDbFields(resolver); + int columnCount = entityResult.getFieldCount(); String entityName = entityResult.getEntityName(); if (entityName == null) { @@ -68,8 +69,8 @@ public List getResolvedComponents(EntityResolver resolver) { } ClassDescriptor classDescriptor = resolver.getClassDescriptor(entityName); - resolvedComponents.add(new DefaultEntityResultSegment(classDescriptor, fields, offset)); - offset = offset + fields.size(); + resolvedComponents.add(new DefaultEntityResultSegment(classDescriptor, fields, offset, columnCount)); + offset = offset + columnCount; } else if (component instanceof EmbeddedResult) { EmbeddedResult embeddedResult = (EmbeddedResult)component; Map fields = embeddedResult.getFields(); diff --git a/cayenne/src/main/java/org/apache/cayenne/query/EntityResultSegment.java b/cayenne/src/main/java/org/apache/cayenne/query/EntityResultSegment.java index 20c36e02ed..71e367e65a 100644 --- a/cayenne/src/main/java/org/apache/cayenne/query/EntityResultSegment.java +++ b/cayenne/src/main/java/org/apache/cayenne/query/EntityResultSegment.java @@ -39,6 +39,11 @@ public interface EntityResultSegment { */ Map getFields(); + /** + * Returns the total number of columns in this segment. + */ + int getColumnCount(); + /** * Performs a reverse lookup of the column path for a given ResultSet label. */ diff --git a/cayenne/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorResultMetadata.java b/cayenne/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorResultMetadata.java index 38d501e09d..f57c71a837 100644 --- a/cayenne/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorResultMetadata.java +++ b/cayenne/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorResultMetadata.java @@ -52,6 +52,11 @@ public String getColumnPath(String resultSetLabel) { return reverseFields.get(resultSetLabel); } + @Override + public int getColumnCount() { + return fields.size(); + } + void addObjectField(String attributeName, String column) { ObjEntity entity = classDescriptor.getEntity(); diff --git a/cayenne/src/test/java/org/apache/cayenne/access/VerticalInheritanceIT.java b/cayenne/src/test/java/org/apache/cayenne/access/VerticalInheritanceIT.java index c49c8ab2cb..df59c2bb8c 100644 --- a/cayenne/src/test/java/org/apache/cayenne/access/VerticalInheritanceIT.java +++ b/cayenne/src/test/java/org/apache/cayenne/access/VerticalInheritanceIT.java @@ -22,6 +22,7 @@ import org.apache.cayenne.ObjectContext; import org.apache.cayenne.Persistent; import org.apache.cayenne.di.Inject; +import org.apache.cayenne.exp.ExpressionFactory; import org.apache.cayenne.query.ColumnSelect; import org.apache.cayenne.query.EJBQLQuery; import org.apache.cayenne.query.ObjectSelect; @@ -727,6 +728,55 @@ public void testUpdateFlattenedRelationshipWithInverse() throws SQLException { } } + @Test + public void testColumnQueryVerticallyInheritedToVerticallyInherited() throws SQLException { + TableHelper ivDocumentTable = new TableHelper(dbHelper, "IV_DOCUMENT"); + ivDocumentTable.setColumns("ID", "TYPE").setColumnTypes(Types.INTEGER, Types.CHAR); + + TableHelper ivDocumentLineTable = new TableHelper(dbHelper, "IV_DOCUMENT_LINE"); + ivDocumentLineTable.setColumns("ID", "TYPE", "DOCUMENT_ID").setColumnTypes(Types.INTEGER, Types.CHAR, Types.INTEGER); + + TableHelper IvDocumentATable = new TableHelper(dbHelper, "IV_DOCUMENT_A"); + IvDocumentATable.setColumns("ID").setColumnTypes(Types.INTEGER); + + TableHelper IvDocumentALineTable = new TableHelper(dbHelper, "IV_DOCUMENT_A_LINE"); + IvDocumentALineTable.setColumns("ID").setColumnTypes(Types.INTEGER); + + TableHelper IvDocumentBTable = new TableHelper(dbHelper, "IV_DOCUMENT_B"); + IvDocumentBTable.setColumns("ID", "RELATED_A_ID").setColumnTypes(Types.INTEGER, Types.INTEGER); + + TableHelper IvDocumentBLineTable = new TableHelper(dbHelper, "IV_DOCUMENT_B_LINE"); + IvDocumentBLineTable.setColumns("ID").setColumnTypes(Types.INTEGER); + + int documentAId = 1; + ivDocumentTable.insert(documentAId, "A"); + IvDocumentATable.insert(documentAId); + + int documentALineId = 2; + ivDocumentLineTable.insert(documentALineId, "A", documentAId); + IvDocumentALineTable.insert(documentALineId); + + int documentBId = 3; + ivDocumentTable.insert(documentBId, "B"); + IvDocumentBTable.insert(documentBId, documentAId); + + int documentBLineId = 4; + ivDocumentLineTable.insert(documentBLineId, "B", documentBId); + IvDocumentBLineTable.insert(documentBLineId); + + { + ObjectContext newContext = runtime.newContext(); + + IvDocument documentA = ObjectSelect.query(IvDocumentALine.class).where(ExpressionFactory.matchDbIdExp("ID", documentALineId)).column(IvDocumentALine.DOCUMENT).selectOne(newContext); + assertNotNull(documentA); + assertEquals(IvDocumentA.class, documentA.getClass()); + + IvDocument documentB = ObjectSelect.query(IvDocumentBLine.class).where(ExpressionFactory.matchDbIdExp("ID", documentBLineId)).column(IvDocumentBLine.DOCUMENT).selectOne(newContext); + assertNotNull(documentB); + assertEquals(IvDocumentB.class, documentB.getClass()); + } + } + @Test public void testDeleteFlattenedNoValues() throws SQLException { ivAbstractTable.insert(1, null, "S"); @@ -1188,6 +1238,7 @@ public void testColumnSelectVerticalInheritance_Sub1() throws SQLException { } @Test +// @Ignore("Address CAY-2911") public void testColumnSelectVerticalInheritance_Sub1Sub1() throws SQLException { TableHelper ivRootTable = new TableHelper(dbHelper, "IV_ROOT"); ivRootTable.setColumns("ID", "NAME", "DISCRIMINATOR"); diff --git a/cayenne/src/test/java/org/apache/cayenne/testdo/inheritance_vertical/IvDocument.java b/cayenne/src/test/java/org/apache/cayenne/testdo/inheritance_vertical/IvDocument.java new file mode 100644 index 0000000000..4b56a1bb23 --- /dev/null +++ b/cayenne/src/test/java/org/apache/cayenne/testdo/inheritance_vertical/IvDocument.java @@ -0,0 +1,10 @@ +package org.apache.cayenne.testdo.inheritance_vertical; + + +import org.apache.cayenne.testdo.inheritance_vertical.auto._IvDocument; + +public abstract class IvDocument extends _IvDocument { + + private static final long serialVersionUID = 1L; + +} diff --git a/cayenne/src/test/java/org/apache/cayenne/testdo/inheritance_vertical/IvDocumentA.java b/cayenne/src/test/java/org/apache/cayenne/testdo/inheritance_vertical/IvDocumentA.java new file mode 100644 index 0000000000..76eaa00a86 --- /dev/null +++ b/cayenne/src/test/java/org/apache/cayenne/testdo/inheritance_vertical/IvDocumentA.java @@ -0,0 +1,10 @@ +package org.apache.cayenne.testdo.inheritance_vertical; + + +import org.apache.cayenne.testdo.inheritance_vertical.auto._IvDocumentA; + +public class IvDocumentA extends _IvDocumentA { + + private static final long serialVersionUID = 1L; + +} diff --git a/cayenne/src/test/java/org/apache/cayenne/testdo/inheritance_vertical/IvDocumentALine.java b/cayenne/src/test/java/org/apache/cayenne/testdo/inheritance_vertical/IvDocumentALine.java new file mode 100644 index 0000000000..b3cc3ef1ac --- /dev/null +++ b/cayenne/src/test/java/org/apache/cayenne/testdo/inheritance_vertical/IvDocumentALine.java @@ -0,0 +1,10 @@ +package org.apache.cayenne.testdo.inheritance_vertical; + + +import org.apache.cayenne.testdo.inheritance_vertical.auto._IvDocumentALine; + +public class IvDocumentALine extends _IvDocumentALine { + + private static final long serialVersionUID = 1L; + +} diff --git a/cayenne/src/test/java/org/apache/cayenne/testdo/inheritance_vertical/IvDocumentB.java b/cayenne/src/test/java/org/apache/cayenne/testdo/inheritance_vertical/IvDocumentB.java new file mode 100644 index 0000000000..980a3ae4fa --- /dev/null +++ b/cayenne/src/test/java/org/apache/cayenne/testdo/inheritance_vertical/IvDocumentB.java @@ -0,0 +1,10 @@ +package org.apache.cayenne.testdo.inheritance_vertical; + + +import org.apache.cayenne.testdo.inheritance_vertical.auto._IvDocumentB; + +public class IvDocumentB extends _IvDocumentB { + + private static final long serialVersionUID = 1L; + +} diff --git a/cayenne/src/test/java/org/apache/cayenne/testdo/inheritance_vertical/IvDocumentBLine.java b/cayenne/src/test/java/org/apache/cayenne/testdo/inheritance_vertical/IvDocumentBLine.java new file mode 100644 index 0000000000..fdf25f3bb9 --- /dev/null +++ b/cayenne/src/test/java/org/apache/cayenne/testdo/inheritance_vertical/IvDocumentBLine.java @@ -0,0 +1,10 @@ +package org.apache.cayenne.testdo.inheritance_vertical; + + +import org.apache.cayenne.testdo.inheritance_vertical.auto._IvDocumentBLine; + +public class IvDocumentBLine extends _IvDocumentBLine { + + private static final long serialVersionUID = 1L; + +} diff --git a/cayenne/src/test/java/org/apache/cayenne/testdo/inheritance_vertical/IvDocumentLine.java b/cayenne/src/test/java/org/apache/cayenne/testdo/inheritance_vertical/IvDocumentLine.java new file mode 100644 index 0000000000..e668ca403f --- /dev/null +++ b/cayenne/src/test/java/org/apache/cayenne/testdo/inheritance_vertical/IvDocumentLine.java @@ -0,0 +1,10 @@ +package org.apache.cayenne.testdo.inheritance_vertical; + + +import org.apache.cayenne.testdo.inheritance_vertical.auto._IvDocumentLine; + +public abstract class IvDocumentLine extends _IvDocumentLine { + + private static final long serialVersionUID = 1L; + +} diff --git a/cayenne/src/test/java/org/apache/cayenne/testdo/inheritance_vertical/auto/_IvDocument.java b/cayenne/src/test/java/org/apache/cayenne/testdo/inheritance_vertical/auto/_IvDocument.java new file mode 100644 index 0000000000..87773fb83a --- /dev/null +++ b/cayenne/src/test/java/org/apache/cayenne/testdo/inheritance_vertical/auto/_IvDocument.java @@ -0,0 +1,118 @@ +package org.apache.cayenne.testdo.inheritance_vertical.auto; + +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.List; + +import org.apache.cayenne.PersistentObject; +import org.apache.cayenne.exp.property.ListProperty; +import org.apache.cayenne.exp.property.NumericIdProperty; +import org.apache.cayenne.exp.property.PropertyFactory; +import org.apache.cayenne.exp.property.SelfProperty; +import org.apache.cayenne.exp.property.StringProperty; +import org.apache.cayenne.testdo.inheritance_vertical.IvDocument; +import org.apache.cayenne.testdo.inheritance_vertical.IvDocumentLine; + +/** + * Class _IvDocument was generated by Cayenne. + * It is probably a good idea to avoid changing this class manually, + * since it may be overwritten next time code is regenerated. + * If you need to make any customizations, please use subclass. + */ +public abstract class _IvDocument extends PersistentObject { + + private static final long serialVersionUID = 1L; + + public static final SelfProperty SELF = PropertyFactory.createSelf(IvDocument.class); + + public static final NumericIdProperty ID_PK_PROPERTY = PropertyFactory.createNumericId("ID", "IvDocument", Integer.class); + public static final String ID_PK_COLUMN = "ID"; + + public static final StringProperty TYPE = PropertyFactory.createString("type", String.class); + public static final ListProperty LINES = PropertyFactory.createList("lines", IvDocumentLine.class); + + protected String type; + + protected Object lines; + + public void setType(String type) { + beforePropertyWrite("type", this.type, type); + this.type = type; + } + + public String getType() { + beforePropertyRead("type"); + return this.type; + } + + public void addToLines(IvDocumentLine obj) { + addToManyTarget("lines", obj, true); + } + + public void removeFromLines(IvDocumentLine obj) { + removeToManyTarget("lines", obj, true); + } + + @SuppressWarnings("unchecked") + public List getLines() { + return (List)readProperty("lines"); + } + + @Override + public Object readPropertyDirectly(String propName) { + if(propName == null) { + throw new IllegalArgumentException(); + } + + switch(propName) { + case "type": + return this.type; + case "lines": + return this.lines; + default: + return super.readPropertyDirectly(propName); + } + } + + @Override + public void writePropertyDirectly(String propName, Object val) { + if(propName == null) { + throw new IllegalArgumentException(); + } + + switch (propName) { + case "type": + this.type = (String)val; + break; + case "lines": + this.lines = val; + break; + default: + super.writePropertyDirectly(propName, val); + } + } + + private void writeObject(ObjectOutputStream out) throws IOException { + writeSerialized(out); + } + + private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { + readSerialized(in); + } + + @Override + protected void writeState(ObjectOutputStream out) throws IOException { + super.writeState(out); + out.writeObject(this.type); + out.writeObject(this.lines); + } + + @Override + protected void readState(ObjectInputStream in) throws IOException, ClassNotFoundException { + super.readState(in); + this.type = (String)in.readObject(); + this.lines = in.readObject(); + } + +} diff --git a/cayenne/src/test/java/org/apache/cayenne/testdo/inheritance_vertical/auto/_IvDocumentA.java b/cayenne/src/test/java/org/apache/cayenne/testdo/inheritance_vertical/auto/_IvDocumentA.java new file mode 100644 index 0000000000..d00d592d7b --- /dev/null +++ b/cayenne/src/test/java/org/apache/cayenne/testdo/inheritance_vertical/auto/_IvDocumentA.java @@ -0,0 +1,92 @@ +package org.apache.cayenne.testdo.inheritance_vertical.auto; + +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; + +import org.apache.cayenne.exp.property.EntityProperty; +import org.apache.cayenne.exp.property.NumericIdProperty; +import org.apache.cayenne.exp.property.PropertyFactory; +import org.apache.cayenne.exp.property.SelfProperty; +import org.apache.cayenne.testdo.inheritance_vertical.IvDocument; +import org.apache.cayenne.testdo.inheritance_vertical.IvDocumentA; +import org.apache.cayenne.testdo.inheritance_vertical.IvDocumentB; + +/** + * Class _IvDocumentA was generated by Cayenne. + * It is probably a good idea to avoid changing this class manually, + * since it may be overwritten next time code is regenerated. + * If you need to make any customizations, please use subclass. + */ +public abstract class _IvDocumentA extends IvDocument { + + private static final long serialVersionUID = 1L; + + public static final SelfProperty SELF = PropertyFactory.createSelf(IvDocumentA.class); + + public static final NumericIdProperty ID_PK_PROPERTY = PropertyFactory.createNumericId("ID", "IvDocumentA", Integer.class); + public static final String ID_PK_COLUMN = "ID"; + + public static final EntityProperty RELATED_B = PropertyFactory.createEntity("relatedB", IvDocumentB.class); + + + protected Object relatedB; + + public void setRelatedB(IvDocumentB relatedB) { + setToOneTarget("relatedB", relatedB, true); + } + + public IvDocumentB getRelatedB() { + return (IvDocumentB)readProperty("relatedB"); + } + + @Override + public Object readPropertyDirectly(String propName) { + if(propName == null) { + throw new IllegalArgumentException(); + } + + switch(propName) { + case "relatedB": + return this.relatedB; + default: + return super.readPropertyDirectly(propName); + } + } + + @Override + public void writePropertyDirectly(String propName, Object val) { + if(propName == null) { + throw new IllegalArgumentException(); + } + + switch (propName) { + case "relatedB": + this.relatedB = val; + break; + default: + super.writePropertyDirectly(propName, val); + } + } + + private void writeObject(ObjectOutputStream out) throws IOException { + writeSerialized(out); + } + + private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { + readSerialized(in); + } + + @Override + protected void writeState(ObjectOutputStream out) throws IOException { + super.writeState(out); + out.writeObject(this.relatedB); + } + + @Override + protected void readState(ObjectInputStream in) throws IOException, ClassNotFoundException { + super.readState(in); + this.relatedB = in.readObject(); + } + +} diff --git a/cayenne/src/test/java/org/apache/cayenne/testdo/inheritance_vertical/auto/_IvDocumentALine.java b/cayenne/src/test/java/org/apache/cayenne/testdo/inheritance_vertical/auto/_IvDocumentALine.java new file mode 100644 index 0000000000..9ea9be797f --- /dev/null +++ b/cayenne/src/test/java/org/apache/cayenne/testdo/inheritance_vertical/auto/_IvDocumentALine.java @@ -0,0 +1,73 @@ +package org.apache.cayenne.testdo.inheritance_vertical.auto; + +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; + +import org.apache.cayenne.exp.property.NumericIdProperty; +import org.apache.cayenne.exp.property.PropertyFactory; +import org.apache.cayenne.exp.property.SelfProperty; +import org.apache.cayenne.testdo.inheritance_vertical.IvDocumentLine; +import org.apache.cayenne.testdo.inheritance_vertical.IvDocumentALine; + +/** + * Class _IvDocumentALine was generated by Cayenne. + * It is probably a good idea to avoid changing this class manually, + * since it may be overwritten next time code is regenerated. + * If you need to make any customizations, please use subclass. + */ +public abstract class _IvDocumentALine extends IvDocumentLine { + + private static final long serialVersionUID = 1L; + + public static final SelfProperty SELF = PropertyFactory.createSelf(IvDocumentALine.class); + + public static final NumericIdProperty ID_PK_PROPERTY = PropertyFactory.createNumericId("ID", "IvDocumentALine", Integer.class); + public static final String ID_PK_COLUMN = "ID"; + + + + + @Override + public Object readPropertyDirectly(String propName) { + if(propName == null) { + throw new IllegalArgumentException(); + } + + switch(propName) { + default: + return super.readPropertyDirectly(propName); + } + } + + @Override + public void writePropertyDirectly(String propName, Object val) { + if(propName == null) { + throw new IllegalArgumentException(); + } + + switch (propName) { + default: + super.writePropertyDirectly(propName, val); + } + } + + private void writeObject(ObjectOutputStream out) throws IOException { + writeSerialized(out); + } + + private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { + readSerialized(in); + } + + @Override + protected void writeState(ObjectOutputStream out) throws IOException { + super.writeState(out); + } + + @Override + protected void readState(ObjectInputStream in) throws IOException, ClassNotFoundException { + super.readState(in); + } + +} diff --git a/cayenne/src/test/java/org/apache/cayenne/testdo/inheritance_vertical/auto/_IvDocumentB.java b/cayenne/src/test/java/org/apache/cayenne/testdo/inheritance_vertical/auto/_IvDocumentB.java new file mode 100644 index 0000000000..aa7e7a3069 --- /dev/null +++ b/cayenne/src/test/java/org/apache/cayenne/testdo/inheritance_vertical/auto/_IvDocumentB.java @@ -0,0 +1,92 @@ +package org.apache.cayenne.testdo.inheritance_vertical.auto; + +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; + +import org.apache.cayenne.exp.property.EntityProperty; +import org.apache.cayenne.exp.property.NumericIdProperty; +import org.apache.cayenne.exp.property.PropertyFactory; +import org.apache.cayenne.exp.property.SelfProperty; +import org.apache.cayenne.testdo.inheritance_vertical.IvDocument; +import org.apache.cayenne.testdo.inheritance_vertical.IvDocumentA; +import org.apache.cayenne.testdo.inheritance_vertical.IvDocumentB; + +/** + * Class _IvDocumentB was generated by Cayenne. + * It is probably a good idea to avoid changing this class manually, + * since it may be overwritten next time code is regenerated. + * If you need to make any customizations, please use subclass. + */ +public abstract class _IvDocumentB extends IvDocument { + + private static final long serialVersionUID = 1L; + + public static final SelfProperty SELF = PropertyFactory.createSelf(IvDocumentB.class); + + public static final NumericIdProperty ID_PK_PROPERTY = PropertyFactory.createNumericId("ID", "IvDocumentB", Integer.class); + public static final String ID_PK_COLUMN = "ID"; + + public static final EntityProperty RELATED_A = PropertyFactory.createEntity("relatedA", IvDocumentA.class); + + + protected Object relatedA; + + public void setOrder(IvDocumentA relatedA) { + setToOneTarget("relatedA", relatedA, true); + } + + public IvDocumentA getRelatedA() { + return (IvDocumentA)readProperty("relatedA"); + } + + @Override + public Object readPropertyDirectly(String propName) { + if(propName == null) { + throw new IllegalArgumentException(); + } + + switch(propName) { + case "relatedA": + return this.relatedA; + default: + return super.readPropertyDirectly(propName); + } + } + + @Override + public void writePropertyDirectly(String propName, Object val) { + if(propName == null) { + throw new IllegalArgumentException(); + } + + switch (propName) { + case "relatedA": + this.relatedA = val; + break; + default: + super.writePropertyDirectly(propName, val); + } + } + + private void writeObject(ObjectOutputStream out) throws IOException { + writeSerialized(out); + } + + private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { + readSerialized(in); + } + + @Override + protected void writeState(ObjectOutputStream out) throws IOException { + super.writeState(out); + out.writeObject(this.relatedA); + } + + @Override + protected void readState(ObjectInputStream in) throws IOException, ClassNotFoundException { + super.readState(in); + this.relatedA = in.readObject(); + } + +} diff --git a/cayenne/src/test/java/org/apache/cayenne/testdo/inheritance_vertical/auto/_IvDocumentBLine.java b/cayenne/src/test/java/org/apache/cayenne/testdo/inheritance_vertical/auto/_IvDocumentBLine.java new file mode 100644 index 0000000000..ef99fedffe --- /dev/null +++ b/cayenne/src/test/java/org/apache/cayenne/testdo/inheritance_vertical/auto/_IvDocumentBLine.java @@ -0,0 +1,73 @@ +package org.apache.cayenne.testdo.inheritance_vertical.auto; + +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; + +import org.apache.cayenne.exp.property.NumericIdProperty; +import org.apache.cayenne.exp.property.PropertyFactory; +import org.apache.cayenne.exp.property.SelfProperty; +import org.apache.cayenne.testdo.inheritance_vertical.IvDocumentLine; +import org.apache.cayenne.testdo.inheritance_vertical.IvDocumentBLine; + +/** + * Class _IvDocumentBLine was generated by Cayenne. + * It is probably a good idea to avoid changing this class manually, + * since it may be overwritten next time code is regenerated. + * If you need to make any customizations, please use subclass. + */ +public abstract class _IvDocumentBLine extends IvDocumentLine { + + private static final long serialVersionUID = 1L; + + public static final SelfProperty SELF = PropertyFactory.createSelf(IvDocumentBLine.class); + + public static final NumericIdProperty ID_PK_PROPERTY = PropertyFactory.createNumericId("ID", "IvDocumentBLine", Integer.class); + public static final String ID_PK_COLUMN = "ID"; + + + + + @Override + public Object readPropertyDirectly(String propName) { + if(propName == null) { + throw new IllegalArgumentException(); + } + + switch(propName) { + default: + return super.readPropertyDirectly(propName); + } + } + + @Override + public void writePropertyDirectly(String propName, Object val) { + if(propName == null) { + throw new IllegalArgumentException(); + } + + switch (propName) { + default: + super.writePropertyDirectly(propName, val); + } + } + + private void writeObject(ObjectOutputStream out) throws IOException { + writeSerialized(out); + } + + private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { + readSerialized(in); + } + + @Override + protected void writeState(ObjectOutputStream out) throws IOException { + super.writeState(out); + } + + @Override + protected void readState(ObjectInputStream in) throws IOException, ClassNotFoundException { + super.readState(in); + } + +} diff --git a/cayenne/src/test/java/org/apache/cayenne/testdo/inheritance_vertical/auto/_IvDocumentLine.java b/cayenne/src/test/java/org/apache/cayenne/testdo/inheritance_vertical/auto/_IvDocumentLine.java new file mode 100644 index 0000000000..26c68e99d2 --- /dev/null +++ b/cayenne/src/test/java/org/apache/cayenne/testdo/inheritance_vertical/auto/_IvDocumentLine.java @@ -0,0 +1,112 @@ +package org.apache.cayenne.testdo.inheritance_vertical.auto; + +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; + +import org.apache.cayenne.PersistentObject; +import org.apache.cayenne.exp.property.EntityProperty; +import org.apache.cayenne.exp.property.NumericIdProperty; +import org.apache.cayenne.exp.property.PropertyFactory; +import org.apache.cayenne.exp.property.SelfProperty; +import org.apache.cayenne.exp.property.StringProperty; +import org.apache.cayenne.testdo.inheritance_vertical.IvDocument; +import org.apache.cayenne.testdo.inheritance_vertical.IvDocumentLine; + +/** + * Class _IvDocumentLine was generated by Cayenne. + * It is probably a good idea to avoid changing this class manually, + * since it may be overwritten next time code is regenerated. + * If you need to make any customizations, please use subclass. + */ +public abstract class _IvDocumentLine extends PersistentObject { + + private static final long serialVersionUID = 1L; + + public static final SelfProperty SELF = PropertyFactory.createSelf(IvDocumentLine.class); + + public static final NumericIdProperty ID_PK_PROPERTY = PropertyFactory.createNumericId("ID", "IvDocumentLine", Integer.class); + public static final String ID_PK_COLUMN = "ID"; + + public static final StringProperty TYPE = PropertyFactory.createString("type", String.class); + public static final EntityProperty DOCUMENT = PropertyFactory.createEntity("document", IvDocument.class); + + protected String type; + + protected Object document; + + public void setType(String type) { + beforePropertyWrite("type", this.type, type); + this.type = type; + } + + public String getType() { + beforePropertyRead("type"); + return this.type; + } + + public void setDocument(IvDocument document) { + setToOneTarget("document", document, true); + } + + public IvDocument getDocument() { + return (IvDocument)readProperty("document"); + } + + @Override + public Object readPropertyDirectly(String propName) { + if(propName == null) { + throw new IllegalArgumentException(); + } + + switch(propName) { + case "type": + return this.type; + case "document": + return this.document; + default: + return super.readPropertyDirectly(propName); + } + } + + @Override + public void writePropertyDirectly(String propName, Object val) { + if(propName == null) { + throw new IllegalArgumentException(); + } + + switch (propName) { + case "type": + this.type = (String)val; + break; + case "document": + this.document = val; + break; + default: + super.writePropertyDirectly(propName, val); + } + } + + private void writeObject(ObjectOutputStream out) throws IOException { + writeSerialized(out); + } + + private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { + readSerialized(in); + } + + @Override + protected void writeState(ObjectOutputStream out) throws IOException { + super.writeState(out); + out.writeObject(this.type); + out.writeObject(this.document); + } + + @Override + protected void readState(ObjectInputStream in) throws IOException, ClassNotFoundException { + super.readState(in); + this.type = (String)in.readObject(); + this.document = in.readObject(); + } + +} diff --git a/cayenne/src/test/resources/inheritance-vertical.map.xml b/cayenne/src/test/resources/inheritance-vertical.map.xml index f5b8509f06..c085e0bdbd 100644 --- a/cayenne/src/test/resources/inheritance-vertical.map.xml +++ b/cayenne/src/test/resources/inheritance-vertical.map.xml @@ -44,6 +44,28 @@ + + + + + + + + + + + + + + + + + + + + + + @@ -142,6 +164,24 @@ + + + + + + + + + + + + + + + + + + @@ -248,6 +288,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -335,6 +411,10 @@ + + + +