diff --git a/src/main/java/org/springframework/data/mybatis/mapping/MybatisAssociation.java b/src/main/java/org/springframework/data/mybatis/mapping/MybatisAssociation.java index c9c27c06..d1bb8afd 100644 --- a/src/main/java/org/springframework/data/mybatis/mapping/MybatisAssociation.java +++ b/src/main/java/org/springframework/data/mybatis/mapping/MybatisAssociation.java @@ -55,4 +55,16 @@ public MybatisPersistentEntity getObversePersistentEntity() { return null; } + public MybatisPersistentEntity getInversePersistentEntity() { + + if (null != getInverse()) { + MybatisPersistentEntity owner = (MybatisPersistentEntity) getInverse().getOwner(); + + return owner; + + } + return null; + } + + } diff --git a/src/main/java/org/springframework/data/mybatis/mapping/MybatisManyToManyAssociation.java b/src/main/java/org/springframework/data/mybatis/mapping/MybatisManyToManyAssociation.java new file mode 100644 index 00000000..75f3602e --- /dev/null +++ b/src/main/java/org/springframework/data/mybatis/mapping/MybatisManyToManyAssociation.java @@ -0,0 +1,18 @@ +package org.springframework.data.mybatis.mapping; + +/** + * @author Jarvis Song + */ +public class MybatisManyToManyAssociation extends MybatisOneToManyAssociation { + + public MybatisManyToManyAssociation(MybatisPersistentProperty inverse, MybatisPersistentProperty obverse) { + super(inverse, obverse); + } + + public boolean preferJoinTable() { + if (null != joinColumn) { + return false; + } + return true; + } +} diff --git a/src/main/java/org/springframework/data/mybatis/mapping/MybatisManyToOneAssociation.java b/src/main/java/org/springframework/data/mybatis/mapping/MybatisManyToOneAssociation.java index bd45bc15..d8c6bdc3 100644 --- a/src/main/java/org/springframework/data/mybatis/mapping/MybatisManyToOneAssociation.java +++ b/src/main/java/org/springframework/data/mybatis/mapping/MybatisManyToOneAssociation.java @@ -52,7 +52,7 @@ public String getJoinColumnName() { } else { MybatisPersistentEntity entity = getObversePersistentEntity(); if (null != entity && entity.hasIdProperty()) { - name = ParsingUtils.reconcatenateCamelCase(getInverse().getName(), "_") + "_" + entity.getIdProperty().getColumnName(); + name = entity.getTableName() + "_" + entity.getIdProperty().getColumnName(); } } return name; diff --git a/src/main/java/org/springframework/data/mybatis/mapping/MybatisOneToManyAssociation.java b/src/main/java/org/springframework/data/mybatis/mapping/MybatisOneToManyAssociation.java new file mode 100644 index 00000000..a5228a34 --- /dev/null +++ b/src/main/java/org/springframework/data/mybatis/mapping/MybatisOneToManyAssociation.java @@ -0,0 +1,186 @@ +package org.springframework.data.mybatis.mapping; + +import org.springframework.data.mybatis.annotations.JoinColumn; +import org.springframework.data.mybatis.annotations.JoinTable; +import org.springframework.util.StringUtils; + +/** + * @author Jarvis Song + */ +public class MybatisOneToManyAssociation extends MybatisAssociation { + + protected JoinColumn joinColumn; + protected JoinTable joinTable; + + public MybatisOneToManyAssociation(MybatisPersistentProperty inverse, MybatisPersistentProperty obverse) { + super(inverse, obverse); + //user,booking + if (null != inverse) { + joinColumn = inverse.findAnnotation(JoinColumn.class); + joinTable = inverse.findAnnotation(JoinTable.class); + } + } + + public boolean preferJoinTable() { + if (null != joinTable) { + return true; + } + return false; + } + + public String getJoinTableName() { + if (null != joinTable && StringUtils.hasText(joinTable.name())) { + return joinTable.name(); + } + + MybatisPersistentEntity inversePersistentEntity = getInversePersistentEntity(); + MybatisPersistentEntity obversePersistentEntity = getObversePersistentEntity(); + if (null != inversePersistentEntity && null != obversePersistentEntity) { + return inversePersistentEntity.getTableName() + "_" + obversePersistentEntity.getTableName(); + } + return null; + } + + public String[] getJoinTableJoinColumnNames() { + if (null != joinTable) { + if (null != joinTable.joinColumns() && joinTable.joinColumns().length > 0) { + String[] result = new String[joinTable.joinColumns().length]; + for (int i = 0; i < joinTable.joinColumns().length; i++) { + String name = joinTable.joinColumns()[i].name(); + if (StringUtils.isEmpty(name)) { + MybatisPersistentEntity entity = getInversePersistentEntity(); + if (null != entity && entity.hasIdProperty()) { + name = entity.getTableName() + "_" + entity.getIdProperty().getColumnName(); + } + } + result[i] = name; + } + return result; + } + } + MybatisPersistentEntity entity = getInversePersistentEntity(); + if (null != entity && entity.hasIdProperty()) { + return new String[]{entity.getTableName() + "_" + entity.getIdProperty().getColumnName()}; + } + return new String[0]; + } + + public String[] getJoinTableJoinReferencedColumnNames() { + if (null != joinTable) { + if (null != joinTable.joinColumns() && joinTable.joinColumns().length > 0) { + String[] result = new String[joinTable.joinColumns().length]; + for (int i = 0; i < joinTable.joinColumns().length; i++) { + String name = joinTable.joinColumns()[i].referencedColumnName(); + if (StringUtils.isEmpty(name)) { + MybatisPersistentEntity entity = getInversePersistentEntity(); + if (null != entity && entity.hasIdProperty()) { + name = entity.getIdProperty().getColumnName(); + } + } + result[i] = name; + } + return result; + } + } + MybatisPersistentEntity entity = getInversePersistentEntity(); + if (null != entity && entity.hasIdProperty()) { + return new String[]{entity.getIdProperty().getColumnName()}; + } + return new String[0]; + } + + public String[] getJoinTableInverseJoinColumnNames() { + if (null != joinTable) { + if (null != joinTable.inverseJoinColumns() && joinTable.inverseJoinColumns().length > 0) { + String[] result = new String[joinTable.inverseJoinColumns().length]; + for (int i = 0; i < joinTable.inverseJoinColumns().length; i++) { + String name = joinTable.inverseJoinColumns()[i].name(); + if (StringUtils.isEmpty(name)) { + MybatisPersistentEntity entity = getObversePersistentEntity(); + if (null != entity && entity.hasIdProperty()) { + name = entity.getTableName() + "_" + entity.getIdProperty().getColumnName(); + } + } + result[i] = name; + } + return result; + } + } + MybatisPersistentEntity entity = getObversePersistentEntity(); + if (null != entity && entity.hasIdProperty()) { + return new String[]{entity.getTableName() + "_" + entity.getIdProperty().getColumnName()}; + } + return new String[0]; + } + + public String[] getJoinTableInverseJoinReferencedColumnNames() { + if (null != joinTable) { + if (null != joinTable.inverseJoinColumns() && joinTable.inverseJoinColumns().length > 0) { + String[] result = new String[joinTable.inverseJoinColumns().length]; + for (int i = 0; i < joinTable.inverseJoinColumns().length; i++) { + String name = joinTable.inverseJoinColumns()[i].referencedColumnName(); + if (StringUtils.isEmpty(name)) { + MybatisPersistentEntity entity = getObversePersistentEntity(); + if (null != entity && entity.hasIdProperty()) { + name = entity.getIdProperty().getColumnName(); + } + } + result[i] = name; + } + return result; + } + } + MybatisPersistentEntity entity = getObversePersistentEntity(); + if (null != entity && entity.hasIdProperty()) { + return new String[]{entity.getIdProperty().getColumnName()}; + } + return new String[0]; + } + + /** + * @return + */ + public String getJoinColumnName() { + //user_id(booking's) + if (null != joinColumn && StringUtils.hasText(joinColumn.name())) { + return joinColumn.name(); + } + MybatisPersistentEntity entity = getInversePersistentEntity(); + if (null != entity && entity.hasIdProperty()) { + return entity.getTableName() + "_" + entity.getIdProperty().getColumnName(); + } + + return null; + } + + public String getJoinReferencedColumnName() { + //id (user's) + + if (null != joinColumn && StringUtils.hasText(joinColumn.referencedColumnName())) { + return joinColumn.referencedColumnName(); + } + MybatisPersistentEntity entity = getInversePersistentEntity(); + if (null != entity && entity.hasIdProperty()) { + return entity.getIdProperty().getColumnName(); + } + + return null; + } + + @Override + public MybatisPersistentProperty getObverse() { + + MybatisPersistentEntity entity = getObversePersistentEntity(); + if (null == entity) { + return null; + } + if (null == joinColumn || StringUtils.isEmpty(joinColumn.referencedColumnName())) { + return entity.getIdProperty(); + } + + return entity.findByColumnName(joinColumn.referencedColumnName()); + + } + + +} diff --git a/src/main/java/org/springframework/data/mybatis/mapping/MybatisPersistentPropertyImpl.java b/src/main/java/org/springframework/data/mybatis/mapping/MybatisPersistentPropertyImpl.java index 395bf860..d0ebe4be 100644 --- a/src/main/java/org/springframework/data/mybatis/mapping/MybatisPersistentPropertyImpl.java +++ b/src/main/java/org/springframework/data/mybatis/mapping/MybatisPersistentPropertyImpl.java @@ -98,6 +98,14 @@ protected Association createAssociation() { return new MybatisOneToOneAssociation(this, null); } + if (null != findAnnotation(OneToMany.class)) { + return new MybatisOneToManyAssociation(this, null); + } + + if (null != findAnnotation(ManyToMany.class)) { + return new MybatisManyToManyAssociation(this, null); + } + return new MybatisAssociation(this, null); } diff --git a/src/main/java/org/springframework/data/mybatis/repository/support/MybatisMapperGenerator.java b/src/main/java/org/springframework/data/mybatis/repository/support/MybatisMapperGenerator.java index 8b8bcc21..3c1607f4 100644 --- a/src/main/java/org/springframework/data/mybatis/repository/support/MybatisMapperGenerator.java +++ b/src/main/java/org/springframework/data/mybatis/repository/support/MybatisMapperGenerator.java @@ -23,10 +23,7 @@ import org.springframework.data.mapping.PersistentProperty; import org.springframework.data.mapping.SimpleAssociationHandler; import org.springframework.data.mapping.SimplePropertyHandler; -import org.springframework.data.mybatis.mapping.MybatisEmbeddedAssociation; -import org.springframework.data.mybatis.mapping.MybatisManyToOneAssociation; -import org.springframework.data.mybatis.mapping.MybatisPersistentEntity; -import org.springframework.data.mybatis.mapping.MybatisPersistentProperty; +import org.springframework.data.mybatis.mapping.*; import org.springframework.data.mybatis.repository.dialect.Dialect; import org.springframework.data.repository.query.parser.Part.IgnoreCaseType; import org.springframework.data.repository.query.parser.Part.Type; @@ -240,6 +237,52 @@ public void doWithPersistentProperty(PersistentProperty pp) { } } + if ((ass instanceof MybatisOneToManyAssociation)) { + if (basic) { + return; + } + + final MybatisOneToManyAssociation association = (MybatisOneToManyAssociation) ass; + MybatisPersistentEntity obversePersistentEntity = association.getObversePersistentEntity(); + if (null != obversePersistentEntity) { + obversePersistentEntity.doWithProperties(new SimplePropertyHandler() { + @Override + public void doWithPersistentProperty(PersistentProperty pp) { + MybatisPersistentProperty property = (MybatisPersistentProperty) pp; + builder.append(quota(persistentEntity.getEntityName() + "." + association.getInverse().getName()) + "." + dialect.wrapColumnName(property.getColumnName())) + .append(" as ").append(quota(association.getInverse().getName() + "." + property.getName())).append(","); + } + }); + obversePersistentEntity.doWithAssociations(new SimpleAssociationHandler() { + @Override + public void doWithAssociation(Association> ass) { + if ((ass instanceof MybatisEmbeddedAssociation)) { + final MybatisEmbeddedAssociation association1 = (MybatisEmbeddedAssociation) ass; + MybatisPersistentEntity obversePersistentEntity1 = association1.getObversePersistentEntity(); + if (null != obversePersistentEntity1) { + obversePersistentEntity1.doWithProperties(new SimplePropertyHandler() { + @Override + public void doWithPersistentProperty(PersistentProperty pp) { + MybatisPersistentProperty property = (MybatisPersistentProperty) pp; + builder.append(quota(persistentEntity.getEntityName() + "." + association.getInverse().getName()) + "." + dialect.wrapColumnName(property.getColumnName())) + .append(" as ").append(quota(association.getInverse().getName() + "." + association1.getInverse().getName() + "." + property.getName())).append(","); + } + }); + } + return; + } + + if ((ass instanceof MybatisManyToOneAssociation)) { + final MybatisManyToOneAssociation association1 = (MybatisManyToOneAssociation) ass; + builder.append(quota(persistentEntity.getEntityName() + "." + association.getInverse().getName()) + "." + dialect.wrapColumnName(association1.getJoinColumnName())) + .append(" as ").append(quota(association.getInverse().getName() + "." + association1.getInverse().getName() + "." + association1.getObverse().getName())).append(","); + + } + } + }); + } + + } } }); @@ -269,10 +312,50 @@ private String buildLeftOuterJoin() { public void doWithAssociation(Association> ass) { if ((ass instanceof MybatisManyToOneAssociation)) { final MybatisManyToOneAssociation association = (MybatisManyToOneAssociation) ass; - builder.append(" left outer join ").append(dialect.wrapTableName(association.getObversePersistentEntity().getTableName())).append(" ").append(quota(persistentEntity.getEntityName() + "." + association.getInverse().getName())) + builder.append(" left outer join ").append(dialect.wrapTableName(association.getObversePersistentEntity().getTableName())).append(" ") + .append(quota(persistentEntity.getEntityName() + "." + association.getInverse().getName())) .append(" on ").append(quota(persistentEntity.getEntityName())).append(".").append(dialect.wrapColumnName(association.getJoinColumnName())) .append("=").append(quota(persistentEntity.getEntityName() + "." + association.getInverse().getName())).append(".").append(dialect.wrapColumnName(association.getJoinReferencedColumnName())); + return; + } + + if ((ass instanceof MybatisOneToManyAssociation)) { + final MybatisOneToManyAssociation association = (MybatisOneToManyAssociation) ass; + + if (association.preferJoinTable()) { + // join table + builder.append(" left outer join ").append(dialect.wrapTableName(association.getJoinTableName())).append(" ") + .append(" on "); + String[] joinTableJoinColumnNames = association.getJoinTableJoinColumnNames(); + String[] joinTableJoinReferencedColumnNames = association.getJoinTableJoinReferencedColumnNames(); + for (int i = 0; i < joinTableJoinColumnNames.length; i++) { + if (i > 0) { + builder.append(" and "); + } + builder.append(dialect.wrapTableName(association.getJoinTableName())).append(".").append(joinTableJoinColumnNames[i]).append("=") + .append(quota(persistentEntity.getEntityName())).append(".").append(dialect.wrapColumnName(joinTableJoinReferencedColumnNames[i])); + } + builder.append(" left outer join ").append(dialect.wrapTableName(association.getObversePersistentEntity().getTableName())).append(" ") + .append(quota(persistentEntity.getEntityName() + "." + association.getInverse().getName())) + .append(" on "); + String[] joinTableInverseJoinColumnNames = association.getJoinTableInverseJoinColumnNames(); + String[] joinTableInverseJoinReferencedColumnNames = association.getJoinTableInverseJoinReferencedColumnNames(); + for (int i = 0; i < joinTableInverseJoinColumnNames.length; i++) { + if (i > 0) { + builder.append(" and "); + } + builder.append(dialect.wrapTableName(association.getJoinTableName())).append(".").append(joinTableInverseJoinColumnNames[i]).append("=") + .append(quota(persistentEntity.getEntityName() + "." + association.getInverse().getName())).append(".").append(dialect.wrapColumnName(joinTableInverseJoinReferencedColumnNames[i])); + } + } else { + // join column + builder.append(" left outer join ").append(dialect.wrapTableName(association.getObversePersistentEntity().getTableName())).append(" ") + .append(quota(persistentEntity.getEntityName() + "." + association.getInverse().getName())) + .append(" on ").append(quota(persistentEntity.getEntityName())).append(".").append(dialect.wrapColumnName(association.getJoinReferencedColumnName())) + .append("=").append(quota(persistentEntity.getEntityName() + "." + association.getInverse().getName())).append(".").append(dialect.wrapColumnName(association.getJoinColumnName())); + } } + } }); diff --git a/src/main/java/org/springframework/data/mybatis/repository/support/MybatisSimpleRepositoryMapperGenerator.java b/src/main/java/org/springframework/data/mybatis/repository/support/MybatisSimpleRepositoryMapperGenerator.java index 69be2a30..766323fd 100644 --- a/src/main/java/org/springframework/data/mybatis/repository/support/MybatisSimpleRepositoryMapperGenerator.java +++ b/src/main/java/org/springframework/data/mybatis/repository/support/MybatisSimpleRepositoryMapperGenerator.java @@ -787,17 +787,73 @@ public void doWithPersistentProperty(PersistentProperty pp) { private void buildInnerResultMap(final StringBuilder builder, final MybatisPersistentEntity persistentEntity, final String prefix) { + final StringBuilder constructorBuilder = new StringBuilder(); + final StringBuilder resultBuilder = new StringBuilder(); + + PreferredConstructor persistenceConstructor = persistentEntity.getPersistenceConstructor(); + if (null != persistenceConstructor && persistenceConstructor.hasParameters()) { + constructorBuilder.append(""); + + for (PreferredConstructor.Parameter parameter : persistenceConstructor.getParameters()) { + MybatisPersistentProperty property = persistentEntity.getPersistentProperty(parameter.getName()); + if (null != property) { + if (property.isIdProperty()) { + if (property.isCompositeId()) { + MybatisPersistentEntityImpl idEntity = context.getPersistentEntity(property.getActualType()); + if (null != idEntity) { + idEntity.doWithProperties(new SimplePropertyHandler() { + @Override + public void doWithPersistentProperty(PersistentProperty pp) { + MybatisPersistentProperty property = (MybatisPersistentProperty) pp; + constructorBuilder.append(String.format("", + alias(prefix + property.getName()), + property.getActualType().getName(), + property.getJdbcType() + )); + } + }); + } + } else { + constructorBuilder.append(String.format("", + alias(prefix + property.getName()), + property.getActualType().getName(), + property.getJdbcType() + )); + } + } else { + constructorBuilder.append(String.format("", + alias(prefix + property.getName()), + property.getActualType().getName(), + property.getJdbcType() + )); + } + }else{ + + + } + } + + + constructorBuilder.append(""); + } + + persistentEntity.doWithProperties(new SimplePropertyHandler() { @Override public void doWithPersistentProperty(PersistentProperty pp) { MybatisPersistentProperty property = (MybatisPersistentProperty) pp; + if (persistentEntity.isConstructorArgument(property)) { + return; + } + + if (property.isIdProperty()) { - buildInnerResultMapId(builder, property, prefix); + buildInnerResultMapId(resultBuilder, property, prefix); return; } - builder.append(String.format("", + resultBuilder.append(String.format("", property.getName(), alias(prefix + property.getName()), property.getActualType().getName(), @@ -805,6 +861,9 @@ public void doWithPersistentProperty(PersistentProperty pp) { )); } }); + + + builder.append(constructorBuilder).append(resultBuilder); } private void buildInnerToOneAssociationResultMap(final StringBuilder builder, final PersistentProperty> inverse) { @@ -880,6 +939,8 @@ private void buildInnerToManyAssociationResultMap(final StringBuilder builder, P MybatisPersistentEntityImpl inversePersistentEntity = context.getPersistentEntity(actualType); if (null != inversePersistentEntity) { buildInnerResultMap(builder, inversePersistentEntity, inverse.getName() + "."); + + } builder.append(""); } @@ -887,6 +948,7 @@ private void buildInnerToManyAssociationResultMap(final StringBuilder builder, P private void buildResultMap(final StringBuilder builder) { builder.append(""); + buildInnerResultMap(builder, persistentEntity, ""); persistentEntity.doWithAssociations(new AssociationHandler() { @@ -902,8 +964,10 @@ public void doWithAssociation(Association ass) { buildInnerToOneAssociationResultMap(builder, inverse); return; } - if (null != inverse.findAnnotation(OneToMany.class) || null != inverse.findAnnotation(ManyToMany.class)) { + + if (ass instanceof MybatisOneToManyAssociation) { buildInnerToManyAssociationResultMap(builder, inverse); + return; } } diff --git a/src/test/java/org/springframework/data/mybatis/domain/sample/Booking.java b/src/test/java/org/springframework/data/mybatis/domain/sample/Booking.java new file mode 100644 index 00000000..fcd783ca --- /dev/null +++ b/src/test/java/org/springframework/data/mybatis/domain/sample/Booking.java @@ -0,0 +1,48 @@ +package org.springframework.data.mybatis.domain.sample; + +import org.springframework.data.annotation.PersistenceConstructor; +import org.springframework.data.mybatis.annotations.Entity; +import org.springframework.data.mybatis.domains.LongId; + +/** + * @author Jarvis Song + */ +@Entity(table = "ds_booking") +public class Booking extends LongId { + + private Long userId; + private String serialNumber; + private Integer amount; + + public Booking() { + } + + @PersistenceConstructor + public Booking(Long userId) { + this.userId = userId; + } + + public Long getUserId() { + return userId; + } + + public void setUserId(Long userId) { + this.userId = userId; + } + + public String getSerialNumber() { + return serialNumber; + } + + public void setSerialNumber(String serialNumber) { + this.serialNumber = serialNumber; + } + + public Integer getAmount() { + return amount; + } + + public void setAmount(Integer amount) { + this.amount = amount; + } +} diff --git a/src/test/java/org/springframework/data/mybatis/domain/sample/Role.java b/src/test/java/org/springframework/data/mybatis/domain/sample/Role.java index e1168d0b..b7e29392 100644 --- a/src/test/java/org/springframework/data/mybatis/domain/sample/Role.java +++ b/src/test/java/org/springframework/data/mybatis/domain/sample/Role.java @@ -40,6 +40,7 @@ public class Role { private String name; @ManyToOne + @JoinColumn(name = "group_id") private Group group; /** diff --git a/src/test/java/org/springframework/data/mybatis/domain/sample/User.java b/src/test/java/org/springframework/data/mybatis/domain/sample/User.java index 9fdc9c5c..215bf2e9 100644 --- a/src/test/java/org/springframework/data/mybatis/domain/sample/User.java +++ b/src/test/java/org/springframework/data/mybatis/domain/sample/User.java @@ -20,11 +20,9 @@ import org.springframework.data.mybatis.annotations.*; -import java.util.Arrays; -import java.util.Date; -import java.util.HashSet; -import java.util.Set; +import java.util.*; +import static org.springframework.data.mybatis.annotations.Id.GenerationType.AUTO; import static org.springframework.data.repository.query.parser.Part.Type.LIKE; /** @@ -33,7 +31,7 @@ @Entity(table = "DS_USER") public class User { - @Id(strategy = Id.GenerationType.AUTO) + @Id(strategy = AUTO) private Integer id; @Condition @Column(name = "FIRSTNAME") @@ -70,6 +68,10 @@ public class User { private Date dateOfBirth; + @OneToMany + @JoinColumn(name = "user_id", referencedColumnName = "id") + private List bookings; + /** * Creates a new empty instance of {@code User}. */ @@ -77,14 +79,15 @@ public User() { this(null, null, null); } - /** - * Creates a new instance of {@code User} with preinitialized values for firstname, lastname, email address and roles. - * - * @param firstname - * @param lastname - * @param emailAddress - * @param roles - */ + + // @PersistenceConstructor + public User(String firstname, String lastname) { + + this.firstname = firstname; + this.lastname = lastname; + + } + public User(String firstname, String lastname, String emailAddress, Role... roles) { this.firstname = firstname; @@ -97,6 +100,21 @@ public User(String firstname, String lastname, String emailAddress, Role... role this.createdAt = new Date(); } + public void setColleagues(Set colleagues) { + this.colleagues = colleagues; + } + + public void setRoles(Set roles) { + this.roles = roles; + } + + public List getBookings() { + return bookings; + } + + public void setBookings(List bookings) { + this.bookings = bookings; + } public User getManager() { return manager; diff --git a/src/test/resources/logback.xml b/src/test/resources/logback.xml index b8bdec1a..2fb7ac58 100644 --- a/src/test/resources/logback.xml +++ b/src/test/resources/logback.xml @@ -22,7 +22,7 @@ ▶ %-5level %d{HH:mm:ss.SSS} [%thread] %logger{36}[%method:%line] - %msg%n - + diff --git a/src/test/resources/test-init-mssql.sql b/src/test/resources/test-init-mssql.sql index 2ea7f7ba..1d711f7d 100644 --- a/src/test/resources/test-init-mssql.sql +++ b/src/test/resources/test-init-mssql.sql @@ -42,3 +42,11 @@ CREATE TABLE DEPARTMENT ( modifier INT NULL, PRIMARY KEY (ID) ); + +CREATE TABLE ds_booking ( + ID INT IDENTITY, + serial_number VARCHAR(32) NULL, + amount INT(11) NULL, + user_id INT(11) NULL, + PRIMARY KEY (ID) +); \ No newline at end of file diff --git a/src/test/resources/test-init-mysql.sql b/src/test/resources/test-init-mysql.sql index 6d503084..09eae307 100644 --- a/src/test/resources/test-init-mysql.sql +++ b/src/test/resources/test-init-mysql.sql @@ -41,4 +41,12 @@ CREATE TABLE DEPARTMENT ( creator INT(11) NULL, modifier INT(11) NULL, PRIMARY KEY (ID) +); + +CREATE TABLE ds_booking ( + ID INT(11) NOT NULL AUTO_INCREMENT, + serial_number VARCHAR(32) NULL, + amount INT(11) NULL, + user_id INT(11) NULL, + PRIMARY KEY (ID) ); \ No newline at end of file diff --git a/src/test/resources/test-init-oracle.sql b/src/test/resources/test-init-oracle.sql index 28aa7841..a0e8efdb 100644 --- a/src/test/resources/test-init-oracle.sql +++ b/src/test/resources/test-init-oracle.sql @@ -53,3 +53,13 @@ CREATE TABLE DEPARTMENT ( PRIMARY KEY (ID) ); CREATE SEQUENCE SEQ_DEPARTMENT; + +CREATE TABLE ds_booking ( + ID NUMBER(11) NOT NULL, + serial_number VARCHAR(32) NULL, + amount NUMBER(11) NULL, + user_id NUMBER(11) NULL, + PRIMARY KEY (ID) +); + +CREATE SEQUENCE SEQ_ds_booking; diff --git a/src/test/resources/test-init-postgres.sql b/src/test/resources/test-init-postgres.sql index 27b9f7da..2a4a3ac4 100644 --- a/src/test/resources/test-init-postgres.sql +++ b/src/test/resources/test-init-postgres.sql @@ -41,4 +41,13 @@ CREATE TABLE "DEPARTMENT" ( creator INT NULL, "MODIFIER" INT NULL, PRIMARY KEY (ID) -); \ No newline at end of file +); + +CREATE TABLE "ds_booking" ( + ID BIGSERIAL NOT NULL, + serial_number VARCHAR(32) NULL, + amount INT NULL, + user_id INT NULL, + PRIMARY KEY (ID) +); + diff --git a/src/test/resources/test-init.sql b/src/test/resources/test-init.sql index b4a2b56d..b9f13f76 100644 --- a/src/test/resources/test-init.sql +++ b/src/test/resources/test-init.sql @@ -50,3 +50,11 @@ CREATE TABLE DS_USER_DS_ROLE ( DS_ROLE_ID INT(11) NOT NULL, PRIMARY KEY (DS_USER_ID, DS_ROLE_ID) ); + +CREATE TABLE ds_booking ( + ID INT(11) NOT NULL AUTO_INCREMENT, + serial_number VARCHAR(32) NULL, + amount INT(11) NULL, + user_id INT(11) NULL, + PRIMARY KEY (ID) +); \ No newline at end of file diff --git a/src/test/resources/test.xml b/src/test/resources/test.xml index e69de29b..c9eff735 100644 --- a/src/test/resources/test.xml +++ b/src/test/resources/test.xml @@ -0,0 +1,336 @@ + + + DS_USER + call next value for seq_DS_USER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + call + identity() + + + update DS_USER + + age=#{age,jdbcType=INTEGER}, + active=#{active,jdbcType=BIT}, + binary_data=#{binaryData,jdbcType=TINYINT}, + created_at=#{createdAt,jdbcType=TIMESTAMP}, + date_of_birth=#{dateOfBirth,jdbcType=TIMESTAMP}, + EMAIL_ADDRESS=#{emailAddress,jdbcType=VARCHAR}, + FIRSTNAME=#{firstname,jdbcType=VARCHAR}, + LASTNAME=#{lastname,jdbcType=VARCHAR}, + country=#{address.country}, + city=#{address.city}, + street_name=#{address.streetName}, + street_no=#{address.streetNo}, + MANAGER_ID=#{manager.id}, + + and id=#{id} + + + + + + delete from + DS_USER "user" + and id=#{id} + + truncate table DS_USER + + + + + + delete from DS_USER "user" + + + and + "user".FIRSTNAME=#{_condition.firstname} + + and "user".LASTNAME like + #{_condition.lastname} + + + + +