Created
October 15, 2012 08:27
-
-
Save nakamura-to/3891437 to your computer and use it in GitHub Desktop.
Concept code of ExternalDomain in Doma
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
package org.seasar.doma.jdbc.domain; | |
public interface DomainConverter<D, V> { | |
// Java to DB | |
V fromDomainToValue(D domain); | |
// DB to Java | |
D fromValueToDomain(V value); | |
} |
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
// Marker Annotation | |
package org.seasar.doma; | |
import java.lang.annotation.ElementType; | |
import java.lang.annotation.Retention; | |
import java.lang.annotation.RetentionPolicy; | |
import java.lang.annotation.Target; | |
@Target(ElementType.TYPE) | |
@Retention(RetentionPolicy.RUNTIME) | |
public @interface ExternalDomain { | |
} |
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
public synchronized void init(ProcessingEnvironment processingEnv) { | |
super.init(processingEnv); | |
String csv = Options.getDomainConverters(processingEnv); | |
List<TypeElement> converterTypeElements = new ArrayList<TypeElement>(); | |
if (csv != null) { | |
for (String className : csv.split(",")) { | |
if (!className.isEmpty()) { | |
TypeElement typeElement = ElementUtil.getTypeElement( | |
className, processingEnv); | |
if (typeElement != null) { | |
converterTypeElements.add(typeElement); | |
} | |
} | |
} | |
} | |
this.converterTypeElements = converterTypeElements; | |
} |
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
package example; | |
import java.math.BigDecimal; | |
public class Salary { | |
public BigDecimal value; | |
public Salary(BigDecimal value) { | |
this.value = value; | |
} | |
} |
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
package example; | |
import java.math.BigDecimal; | |
import org.seasar.doma.ExternalDomain; | |
import org.seasar.doma.jdbc.domain.DomainConverter; | |
@ExternalDomain | |
public class SalaryConverter implements DomainConverter<Salary, BigDecimal> { | |
@Override | |
public BigDecimal fromDomainToValue(Salary domain) { | |
return domain.value; | |
} | |
@Override | |
public Salary fromValueToDomain(BigDecimal value) { | |
return new Salary(value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment