diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java index 5df913196..d167851c0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java @@ -41,7 +41,10 @@ public class BuiltInMappingMethods { new StringToXmlGregorianCalendar( typeFactory ), new XmlGregorianCalendarToString( typeFactory ), new CalendarToXmlGregorianCalendar( typeFactory ), - new XmlGregorianCalendarToCalendar( typeFactory ) + new XmlGregorianCalendarToCalendar( typeFactory ), + new DateToSqlDate( typeFactory ), + new DateToSqlTime( typeFactory ), + new DateToSqlTimestamp( typeFactory ) ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/DateToSqlDate.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/DateToSqlDate.java new file mode 100644 index 000000000..7062b8516 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/DateToSqlDate.java @@ -0,0 +1,69 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed 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.mapstruct.ap.internal.model.source.builtin; + +import static org.mapstruct.ap.internal.util.Collections.asSet; + +import java.util.Date; +import java.util.Set; + +import org.mapstruct.ap.internal.model.common.Parameter; +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.model.common.TypeFactory; + +/** + * @author Filip Hrisafov + */ +public class DateToSqlDate extends BuiltInMethod { + + private final Parameter parameter; + private final Type returnType; + private final Set importTypes; + + public DateToSqlDate(TypeFactory typeFactory) { + this.parameter = new Parameter( "date", typeFactory.getType( Date.class ) ); + this.returnType = typeFactory.getType( java.sql.Date.class ); + + this.importTypes = asSet( + parameter.getType() + ); + } + + @Override + public boolean doTypeVarsMatch(Type parameter, Type returnType) { + //We must make sure that there is only a match when the types are equal. The reason for this is to avoid + //ambiguous problems, when the return type is java.util.Date + return getReturnType().equals( returnType ); + } + + @Override + public Set getImportTypes() { + return importTypes; + } + + @Override + public Parameter getParameter() { + return parameter; + } + + @Override + public Type getReturnType() { + return returnType; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/DateToSqlTime.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/DateToSqlTime.java new file mode 100644 index 000000000..e05166e76 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/DateToSqlTime.java @@ -0,0 +1,72 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed 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.mapstruct.ap.internal.model.source.builtin; + +import static org.mapstruct.ap.internal.util.Collections.asSet; + +import java.sql.Time; +import java.util.Date; +import java.util.Set; + +import org.mapstruct.ap.internal.model.common.Parameter; +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.model.common.TypeFactory; + + +/** + * @author Filip Hrisafov + */ +public class DateToSqlTime extends BuiltInMethod { + + private final Parameter parameter; + private final Type returnType; + private final Set importTypes; + + public DateToSqlTime(TypeFactory typeFactory) { + this.parameter = new Parameter( "date", typeFactory.getType( Date.class ) ); + this.returnType = typeFactory.getType( Time.class ); + + this.importTypes = asSet( + parameter.getType(), + returnType + ); + } + + @Override + public boolean doTypeVarsMatch(Type parameter, Type returnType) { + //We must make sure that there is only a match when the types are equal. The reason for this is to avoid + //ambiguous problems, when the return type is java.util.Date + return getReturnType().equals( returnType ); + } + + @Override + public Set getImportTypes() { + return importTypes; + } + + @Override + public Parameter getParameter() { + return parameter; + } + + @Override + public Type getReturnType() { + return returnType; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/DateToSqlTimestamp.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/DateToSqlTimestamp.java new file mode 100644 index 000000000..a94252550 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/DateToSqlTimestamp.java @@ -0,0 +1,73 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed 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.mapstruct.ap.internal.model.source.builtin; + +import static org.mapstruct.ap.internal.util.Collections.asSet; + +import java.sql.Timestamp; +import java.util.Date; +import java.util.Set; + +import org.mapstruct.ap.internal.model.common.Parameter; +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.model.common.TypeFactory; + + +/** + * @author Filip Hrisafov + */ +public class DateToSqlTimestamp extends BuiltInMethod { + + private final Parameter parameter; + private final Type returnType; + private final Set importTypes; + + public DateToSqlTimestamp(TypeFactory typeFactory) { + this.parameter = new Parameter( "date", typeFactory.getType( Date.class ) ); + this.returnType = typeFactory.getType( Timestamp.class ); + + this.importTypes = asSet( + parameter.getType(), + returnType + ); + } + + @Override + public boolean doTypeVarsMatch(Type parameter, Type returnType) { + //We must make sure that there is only a match when the types are equal. The reason for this is to avoid + //ambiguous problems, when the return type is java.util.Date + return getReturnType().equals( returnType ); + } + + @Override + public Set getImportTypes() { + return importTypes; + } + + @Override + public Parameter getParameter() { + return parameter; + } + + @Override + public Type getReturnType() { + return returnType; + } +} diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/DateToSqlDate.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/DateToSqlDate.ftl new file mode 100644 index 000000000..c5b8255eb --- /dev/null +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/DateToSqlDate.ftl @@ -0,0 +1,27 @@ +<#-- + + Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + and/or other contributors as indicated by the @authors tag. See the + copyright.txt file in the distribution for a full listing of all + contributors. + + Licensed 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. + +--> +private java.sql.Date ${name}( Date date ) { + if ( date == null ) { + return null; + } + + return new java.sql.Date(date.getTime()); +} \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/DateToSqlTime.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/DateToSqlTime.ftl new file mode 100644 index 000000000..a31ad02a0 --- /dev/null +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/DateToSqlTime.ftl @@ -0,0 +1,27 @@ +<#-- + + Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + and/or other contributors as indicated by the @authors tag. See the + copyright.txt file in the distribution for a full listing of all + contributors. + + Licensed 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. + +--> +private Time ${name}( Date date ) { + if ( date == null ) { + return null; + } + + return new Time(date.getTime()); +} \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/DateToSqlTimestamp.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/DateToSqlTimestamp.ftl new file mode 100644 index 000000000..a8e691b3b --- /dev/null +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/DateToSqlTimestamp.ftl @@ -0,0 +1,27 @@ +<#-- + + Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + and/or other contributors as indicated by the @authors tag. See the + copyright.txt file in the distribution for a full listing of all + contributors. + + Licensed 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. + +--> +private Timestamp ${name}( Date date ) { + if ( date == null ) { + return null; + } + + return new Timestamp(date.getTime()); +} \ No newline at end of file diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/BuiltInTest.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/BuiltInTest.java index 2c43a5c2a..c6b09c0e3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/BuiltInTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/BuiltInTest.java @@ -20,6 +20,8 @@ package org.mapstruct.ap.test.builtin; import static org.assertj.core.api.Assertions.assertThat; +import java.sql.Time; +import java.sql.Timestamp; import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.ZoneId; @@ -52,6 +54,8 @@ import org.mapstruct.ap.test.builtin.bean.DateProperty; import org.mapstruct.ap.test.builtin.bean.JaxbElementListProperty; import org.mapstruct.ap.test.builtin.bean.JaxbElementProperty; import org.mapstruct.ap.test.builtin.bean.SqlDateProperty; +import org.mapstruct.ap.test.builtin.bean.SqlTimeProperty; +import org.mapstruct.ap.test.builtin.bean.SqlTimestampProperty; import org.mapstruct.ap.test.builtin.bean.StringListProperty; import org.mapstruct.ap.test.builtin.bean.StringProperty; import org.mapstruct.ap.test.builtin.bean.XmlGregorianCalendarProperty; @@ -62,12 +66,14 @@ import org.mapstruct.ap.test.builtin.mapper.CalendarToDateMapper; import org.mapstruct.ap.test.builtin.mapper.CalendarToStringMapper; import org.mapstruct.ap.test.builtin.mapper.CalendarToXmlGregCalMapper; import org.mapstruct.ap.test.builtin.mapper.DateToCalendarMapper; +import org.mapstruct.ap.test.builtin.mapper.DateToSqlDateMapper; import org.mapstruct.ap.test.builtin.mapper.DateToXmlGregCalMapper; -import org.mapstruct.ap.test.builtin.mapper.ErroneousSourceTargetWithSqlDateMapper; import org.mapstruct.ap.test.builtin.mapper.IterableSourceTargetMapper; import org.mapstruct.ap.test.builtin.mapper.JaxbListMapper; import org.mapstruct.ap.test.builtin.mapper.JaxbMapper; import org.mapstruct.ap.test.builtin.mapper.MapSourceTargetMapper; +import org.mapstruct.ap.test.builtin.mapper.SqlTimeMapper; +import org.mapstruct.ap.test.builtin.mapper.SqlTimestampMapper; import org.mapstruct.ap.test.builtin.mapper.StringToCalendarMapper; import org.mapstruct.ap.test.builtin.mapper.StringToXmlGregCalMapper; import org.mapstruct.ap.test.builtin.mapper.XmlGregCalToCalendarMapper; @@ -77,9 +83,6 @@ import org.mapstruct.ap.test.builtin.source.IterableSource; import org.mapstruct.ap.test.builtin.source.MapSource; import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; -import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; -import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** @@ -91,6 +94,8 @@ import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; IterableTarget.class, MapTarget.class, SqlDateProperty.class, + SqlTimeProperty.class, + SqlTimestampProperty.class, CalendarProperty.class, DateProperty.class, JaxbElementListProperty.class, @@ -106,6 +111,9 @@ import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; CalendarToXmlGregCalMapper.class, DateToCalendarMapper.class, DateToXmlGregCalMapper.class, + DateToSqlDateMapper.class, + SqlTimeMapper.class, + SqlTimestampMapper.class, IterableSourceTargetMapper.class, JaxbListMapper.class, JaxbMapper.class, @@ -262,7 +270,7 @@ public class BuiltInTest { DateProperty target = CalendarToDateMapper.INSTANCE.map( source ); assertThat( target ).isNotNull(); - assertThat( target.getProp() ).isNotNull(); + assertThat( target.getProp() ).isNotNull().isInstanceOf( Date.class ); assertThat( target.getProp() ).isEqualTo( createCalendar( "02.03.1999" ).getTime() ); } @@ -354,22 +362,88 @@ public class BuiltInTest { } @Test - @IssueKey( "277" ) - @WithClasses({ - ErroneousSourceTargetWithSqlDateMapper.class }) - @ExpectedCompilationOutcome( - value = CompilationResult.FAILED, - diagnostics = { - @Diagnostic( type = ErroneousSourceTargetWithSqlDateMapper.class, - kind = javax.tools.Diagnostic.Kind.ERROR, - line = 35, - messageRegExp = "Can't map property \"java\\.util\\.Date prop\" to " - + "\"java\\.sql\\.Date prop\"" ) - } - ) - public void shouldNotMapJavaUtilDateToJavaSqlDate() { + public void shouldApplyBuiltInOnDateToSqlDate() throws ParseException { + assertThat( DateToSqlDateMapper.INSTANCE.toTargetWithSqlDate( null ) ).isNull(); + DateProperty source = new DateProperty(); + source.setProp( createDate( "31-08-1982 10:20:56" ) ); + + SqlDateProperty target = DateToSqlDateMapper.INSTANCE.toTargetWithSqlDate( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getProp() ).isNotNull().isInstanceOf( java.sql.Date.class ); + assertThat( target.getProp().toString() ).isEqualTo( "1982-08-31" ); } + @Test + public void shouldUseSqlDateWhenMappingToDate() throws ParseException { + assertThat( DateToSqlDateMapper.INSTANCE.fromSqlDate( null ) ).isNull(); + + SqlDateProperty source = new SqlDateProperty(); + source.setProp( new java.sql.Date( createDate( "31-08-1982 10:20:56" ).getTime() ) ); + + DateProperty target = DateToSqlDateMapper.INSTANCE.fromSqlDate( source ); + assertThat( target ).isNotNull(); + assertThat( target.getProp() ).isNotNull(); + assertThat( target.getProp().toString() ).isEqualTo( "1982-08-31" ); + } + + @Test + public void shouldApplyBuiltInOnDateToSqlTime() throws ParseException { + SqlTimeMapper mapper = SqlTimeMapper.INSTANCE; + assertThat( mapper.map( null ) ).isNull(); + DateProperty source = new DateProperty(); + source.setProp( createDate( "31-08-1982 10:20:56" ) ); + + SqlTimeProperty target = mapper.map( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getProp() ).isNotNull(); + assertThat( target.getProp().toString() ).isEqualTo( "10:20:56" ); + } + + @Test + public void shouldUseSqlTimeWhenMappingToDate() throws ParseException { + SqlTimeMapper mapper = SqlTimeMapper.INSTANCE; + assertThat( mapper.fromTime( null ) ).isNull(); + + SqlTimeProperty source = new SqlTimeProperty(); + source.setProp( new Time( createDate( "31-08-1982 10:20:56" ).getTime() ) ); + + DateProperty target = mapper.fromTime( source ); + assertThat( target ).isNotNull(); + assertThat( target.getProp() ).isNotNull(); + assertThat( target.getProp().toString() ).isEqualTo( "10:20:56" ); + } + + @Test + public void shouldApplyBuiltInOnDateToSqlTimestamp() throws ParseException { + SqlTimestampMapper mapper = SqlTimestampMapper.INSTANCE; + assertThat( mapper.map( null ) ).isNull(); + DateProperty source = new DateProperty(); + source.setProp( createDate( "31-08-1982 10:20:56" ) ); + + SqlTimestampProperty target = mapper.map( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getProp() ).isNotNull(); + assertThat( target.getProp().toString() ).isEqualTo( "1982-08-31 10:20:56.0" ); + } + + @Test + public void shouldUseSqlTimestampWhenMappingToDate() throws ParseException { + SqlTimestampMapper mapper = SqlTimestampMapper.INSTANCE; + assertThat( mapper.fromTimestamp( null ) ).isNull(); + + SqlTimestampProperty source = new SqlTimestampProperty(); + source.setProp( new Timestamp( createDate( "31-08-1982 10:20:56" ).getTime() ) ); + + DateProperty target = mapper.fromTimestamp( source ); + assertThat( target ).isNotNull(); + assertThat( target.getProp() ).isNotNull(); + assertThat( target.getProp().toString() ).isEqualTo( "1982-08-31 10:20:56.0" ); + } + + private JAXBElement createJaxb(String test) { return new JAXBElement( new QName( "www.mapstruct.org", "test" ), String.class, test ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/SqlTimeProperty.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/SqlTimeProperty.java new file mode 100644 index 000000000..358f8ca2e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/SqlTimeProperty.java @@ -0,0 +1,37 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed 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.mapstruct.ap.test.builtin.bean; + +import java.sql.Time; + +/** + * @author Filip Hrisafov + */ +public class SqlTimeProperty { + + private Time prop; + + public Time getProp() { + return prop; + } + + public void setProp(Time prop) { + this.prop = prop; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/SqlTimestampProperty.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/SqlTimestampProperty.java new file mode 100644 index 000000000..3c68b4e9d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/SqlTimestampProperty.java @@ -0,0 +1,37 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed 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.mapstruct.ap.test.builtin.bean; + +import java.sql.Timestamp; + +/** + * @author Filip Hrisafov + */ +public class SqlTimestampProperty { + + private Timestamp prop; + + public Timestamp getProp() { + return prop; + } + + public void setProp(Timestamp prop) { + this.prop = prop; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/ErroneousSourceTargetWithSqlDateMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/DateToSqlDateMapper.java similarity index 86% rename from processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/ErroneousSourceTargetWithSqlDateMapper.java rename to processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/DateToSqlDateMapper.java index bb9c10b7d..dc0f18e3d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/ErroneousSourceTargetWithSqlDateMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/DateToSqlDateMapper.java @@ -28,9 +28,11 @@ import org.mapstruct.factory.Mappers; * */ @Mapper -public interface ErroneousSourceTargetWithSqlDateMapper { +public interface DateToSqlDateMapper { - ErroneousSourceTargetWithSqlDateMapper INSTANCE = Mappers.getMapper( ErroneousSourceTargetWithSqlDateMapper.class ); + DateToSqlDateMapper INSTANCE = Mappers.getMapper( DateToSqlDateMapper.class ); SqlDateProperty toTargetWithSqlDate(DateProperty source); + + DateProperty fromSqlDate(SqlDateProperty source); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/SqlTimeMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/SqlTimeMapper.java new file mode 100644 index 000000000..45f496c1c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/SqlTimeMapper.java @@ -0,0 +1,38 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed 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.mapstruct.ap.test.builtin.mapper; + +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.builtin.bean.DateProperty; +import org.mapstruct.ap.test.builtin.bean.SqlTimeProperty; +import org.mapstruct.factory.Mappers; + +/** + * @author Andreas Gudian + * + */ +@Mapper +public interface SqlTimeMapper { + + SqlTimeMapper INSTANCE = Mappers.getMapper( SqlTimeMapper.class ); + + SqlTimeProperty map(DateProperty source); + + DateProperty fromTime(SqlTimeProperty source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/SqlTimestampMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/SqlTimestampMapper.java new file mode 100644 index 000000000..b6bc11d61 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/SqlTimestampMapper.java @@ -0,0 +1,38 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed 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.mapstruct.ap.test.builtin.mapper; + +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.builtin.bean.DateProperty; +import org.mapstruct.ap.test.builtin.bean.SqlTimestampProperty; +import org.mapstruct.factory.Mappers; + +/** + * @author Andreas Gudian + * + */ +@Mapper +public interface SqlTimestampMapper { + + SqlTimestampMapper INSTANCE = Mappers.getMapper( SqlTimestampMapper.class ); + + SqlTimestampProperty map(DateProperty source); + + DateProperty fromTimestamp(SqlTimestampProperty source); +}