org.pojava.persistence.adaptor.CharAdaptor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of persistence Show documentation
Show all versions of persistence Show documentation
POJava Persistence is a small library of tools used in the
persistence and retrieval of data to and from storage, such as to a
database or XML document. It contains an ORM (Object Relational
Mapping) tool that supports use of existing beans and POJO's rather
than requiring POJO's to be instrumented to support a tool.
The newest version!
package org.pojava.persistence.adaptor;
import org.pojava.lang.Binding;
import org.pojava.transformation.BindingAdaptor;
/**
* Adaptor for managing Java to JDBC for a Character value.
*
* @author John Pile
*/
public class CharAdaptor extends BindingAdaptor {
/**
* The type the translator will produce for the bean.
*/
public Class inboundType() {
return Character.class;
}
/**
* The type the translator will produce for the JDBC driver.
*/
public Class outboundType() {
return Character.class;
}
/**
* Translate the binding from the data source towards Java bean.
*/
public Binding inbound(Binding inBinding) {
// Prevent constructing a new object when you can.
if (inBinding == null || inBinding.getObj() == null
|| Character.class == inBinding.getObj().getClass()) {
return inBinding;
}
Binding outBinding = new Binding(Character.class, null);
// A single character array must be translated to a character.
String chars = inBinding.getObj().toString();
if (chars.length() == 0) {
return null;
} else {
outBinding.setObj(chars.charAt(0));
}
return outBinding;
}
/**
* Translate the binding from the java bean to the data source.
*/
public Binding outbound(Binding outBinding) {
return outBinding;
}
}