本文整理匯總了Java中javax.persistence.AttributeConverter類的典型用法代碼示例。如果您正苦於以下問題:Java AttributeConverter類的具體用法?Java AttributeConverter怎麽用?Java AttributeConverter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
AttributeConverter類屬於javax.persistence包,在下文中一共展示了AttributeConverter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setExpectedType
import javax.persistence.AttributeConverter; //導入依賴的package包/類
@Override
public void setExpectedType(Type expectedType) {
if ( this.expectedType != null ) {
return;
}
if ( AttributeConverterTypeAdapter.class.isInstance( expectedType ) ) {
final AttributeConverterTypeAdapter adapterType = (AttributeConverterTypeAdapter) expectedType;
if ( getDataType().getReturnedClass().equals( adapterType.getModelType() ) ) {
// apply the converter
final AttributeConverter converter = ( (AttributeConverterTypeAdapter) expectedType ).getAttributeConverter();
final Object converted = converter.convertToDatabaseColumn( getLiteralValue() );
if ( isCharacterData( adapterType.sqlType() ) ) {
setText( "'" + converted.toString() + "'" );
}
else {
setText( converted.toString() );
}
}
this.expectedType = expectedType;
}
}
示例2: getConverter
import javax.persistence.AttributeConverter; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private AttributeConverter<Object, Object> getConverter(AccessibleObject accessible) {
Convert converter = accessible.getAnnotation(Convert.class);
if (converter != null) {
Class<?> converterClass = converter.converter();
if (!AttributeConverter.class.isAssignableFrom(converterClass)) {
throw new RuntimeException(
"Converter class must be AttributeConverter rather than " + converterClass.getName());
}
try {
Constructor<?> cs = converterClass.getDeclaredConstructor();
cs.setAccessible(true);
return (AttributeConverter<Object, Object>) cs.newInstance();
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | SecurityException
| InvocationTargetException e) {
throw new RuntimeException("Cannot instantiate Converter: " + converterClass.getName(), e);
}
}
return null;
}
示例3: getConverterType
import javax.persistence.AttributeConverter; //導入依賴的package包/類
private static Class<?> getConverterType(AttributeConverter<Object, Object> converter) {
if (converter != null) {
List<Type> types = ClassUtils.getGenericInterfacesIncludeHierarchy(converter.getClass());
for (Type type : types) {
if (type instanceof ParameterizedType) {
ParameterizedType pt = (ParameterizedType) type;
if (pt.getRawType() == AttributeConverter.class) {
Type dbType = pt.getActualTypeArguments()[1];
if (dbType instanceof Class) {
return (Class<?>) dbType;
}
}
}
}
}
return null;
}
示例4: append
import javax.persistence.AttributeConverter; //導入依賴的package包/類
Where<T> append(String type, String clause, Object... params) {
// check clause:
Mapper<T> mapper = this.criteria.mapper;
CompiledClause cc = CompiledClause.compile(mapper, clause);
if (cc.converters.length != params.length) {
throw new IllegalArgumentException("Arguments not match the placeholder.");
}
// convert params:
int n = 0;
for (AttributeConverter<Object, Object> converter : cc.converters) {
if (converter != null) {
params[n] = converter.convertToDatabaseColumn(params[n]);
}
n++;
}
// add:
if (type != null) {
this.criteria.where.add(type);
}
this.criteria.where.add(cc.clause);
for (Object param : params) {
this.criteria.whereParams.add(param);
}
return this;
}
示例5: createConverterClass
import javax.persistence.AttributeConverter; //導入依賴的package包/類
private void createConverterClass(Converter convert, ClassLoader classLoader) {
//create Java Class
Class<?> attributeConverter = new ByteBuddy()
// .subclass(TypeDescription.Generic.Builder.parameterizedType(AttributeConverter.class, String.class, Integer.class).build())
.subclass(AttributeConverter.class)
.name(convert.getClazz())
.annotateType(AnnotationDescription.Builder.ofType(javax.persistence.Converter.class).build())
.make()
.load(classLoader, ClassLoadingStrategy.Default.INJECTION)
.getLoaded();
//create MetadataClass
MetadataClass metadataClass = new MetadataClass(getMetadataFactory(), convert.getClazz());
metadataClass.addInterface(AttributeConverter.class.getName());
metadataClass.addGenericType("");
metadataClass.addGenericType("");
metadataClass.addGenericType(convert.getAttributeType());
metadataClass.addGenericType("");
metadataClass.addGenericType(convert.getFieldType());
getMetadataFactory().addMetadataClass(metadataClass);
}
示例6: instantiateAttributeConverter
import javax.persistence.AttributeConverter; //導入依賴的package包/類
private AttributeConverter instantiateAttributeConverter(Class<? extends AttributeConverter> attributeConverterClass) {
AttributeConverter attributeConverter;
try {
attributeConverter = attributeConverterClass.newInstance();
}
catch (Exception e) {
throw new AnnotationException(
"Unable to instantiate AttributeConverter [" + attributeConverterClass.getName() + "]",
e
);
}
return attributeConverter;
}
示例7: addAttributeConverter
import javax.persistence.AttributeConverter; //導入依賴的package包/類
/**
* Adds the AttributeConverter instance to this Configuration. This form is mainly intended for developers
* to programatically add their own AttributeConverter instance. HEM, instead, uses the
* {@link #addAttributeConverter(Class, boolean)} form
*
* @param attributeConverter The AttributeConverter instance.
*/
public void addAttributeConverter(AttributeConverter attributeConverter) {
boolean autoApply = false;
Converter converterAnnotation = attributeConverter.getClass().getAnnotation( Converter.class );
if ( converterAnnotation != null ) {
autoApply = converterAnnotation.autoApply();
}
addAttributeConverter( new AttributeConverterDefinition( attributeConverter, autoApply ) );
}
示例8: AttributeConversionInfo
import javax.persistence.AttributeConverter; //導入依賴的package包/類
public AttributeConversionInfo(
Class<? extends AttributeConverter> converterClass,
boolean conversionDisabled,
String attributeName,
XAnnotatedElement source) {
this.converterClass = converterClass;
this.conversionDisabled = conversionDisabled;
this.attributeName = attributeName;
this.source = source;
}
示例9: AttributeConverterDefinition
import javax.persistence.AttributeConverter; //導入依賴的package包/類
public AttributeConverterDefinition(AttributeConverter attributeConverter, boolean autoApply) {
this.attributeConverter = attributeConverter;
this.autoApply = autoApply;
final Class attributeConverterClass = attributeConverter.getClass();
final ParameterizedType attributeConverterSignature = extractAttributeConverterParameterizedType( attributeConverterClass );
if ( attributeConverterSignature.getActualTypeArguments().length < 2 ) {
throw new AnnotationException(
"AttributeConverter [" + attributeConverterClass.getName()
+ "] did not retain parameterized type information"
);
}
if ( attributeConverterSignature.getActualTypeArguments().length > 2 ) {
throw new AnnotationException(
"AttributeConverter [" + attributeConverterClass.getName()
+ "] specified more than 2 parameterized types"
);
}
entityAttributeType = (Class) attributeConverterSignature.getActualTypeArguments()[0];
if ( entityAttributeType == null ) {
throw new AnnotationException(
"Could not determine 'entity attribute' type from given AttributeConverter [" +
attributeConverterClass.getName() + "]"
);
}
databaseColumnType = (Class) attributeConverterSignature.getActualTypeArguments()[1];
if ( databaseColumnType == null ) {
throw new AnnotationException(
"Could not determine 'database column' type from given AttributeConverter [" +
attributeConverterClass.getName() + "]"
);
}
}
示例10: extractAttributeConverterParameterizedType
import javax.persistence.AttributeConverter; //導入依賴的package包/類
private ParameterizedType extractAttributeConverterParameterizedType(Class attributeConverterClass) {
for ( Type type : attributeConverterClass.getGenericInterfaces() ) {
if ( ParameterizedType.class.isInstance( type ) ) {
final ParameterizedType parameterizedType = (ParameterizedType) type;
if ( AttributeConverter.class.equals( parameterizedType.getRawType() ) ) {
return parameterizedType;
}
}
}
throw new AssertionFailure(
"Could not extract ParameterizedType representation of AttributeConverter definition " +
"from AttributeConverter implementation class [" + attributeConverterClass.getName() + "]"
);
}
示例11: AttributeConverterTypeAdapter
import javax.persistence.AttributeConverter; //導入依賴的package包/類
public AttributeConverterTypeAdapter(
String name,
AttributeConverter<? extends T,?> attributeConverter,
SqlTypeDescriptor sqlTypeDescriptorAdapter,
Class modelType,
Class jdbcType,
JavaTypeDescriptor<T> entityAttributeJavaTypeDescriptor) {
super( sqlTypeDescriptorAdapter, entityAttributeJavaTypeDescriptor );
this.name = name;
this.modelType = modelType;
this.jdbcType = jdbcType;
this.attributeConverter = attributeConverter;
log.debug( "Created AttributeConverterTypeAdapter -> " + name );
}
示例12: AttributeConverterSqlTypeDescriptorAdapter
import javax.persistence.AttributeConverter; //導入依賴的package包/類
public AttributeConverterSqlTypeDescriptorAdapter(
AttributeConverter converter,
SqlTypeDescriptor delegate,
JavaTypeDescriptor intermediateJavaTypeDescriptor) {
this.converter = converter;
this.delegate = delegate;
this.intermediateJavaTypeDescriptor = intermediateJavaTypeDescriptor;
}
示例13: checkPropertyType
import javax.persistence.AttributeConverter; //導入依賴的package包/類
private static Class<?> checkPropertyType(Class<?> typeClass, AttributeConverter<Object, Object> converter) {
Class<?> converterType = getConverterType(converter);
if (converterType != null) {
typeClass = converterType;
}
if (typeClass.isEnum() || DEFAULT_COLUMN_TYPES.containsKey(typeClass)) {
return typeClass;
}
throw new RuntimeException("Unsupported type: " + typeClass);
}
示例14: doCompile
import javax.persistence.AttributeConverter; //導入依賴的package包/類
@SuppressWarnings("unchecked")
static CompiledClause doCompile(Mapper<?> mapper, String clause) {
Map<String, AccessibleProperty> properties = mapper.allPropertiesMap;
StringBuilder sb = new StringBuilder(clause.length() + 10);
List<AttributeConverter<Object, Object>> list = new ArrayList<>();
int start = 0;
Matcher m = p.matcher(clause.toLowerCase());
while (m.find()) {
sb.append(clause.substring(start, m.start()));
String s = clause.substring(m.start(), m.end());
if (properties.containsKey(s.toLowerCase())) {
AccessibleProperty ap = properties.get(s.toLowerCase());
sb.append(ap.columnName);
list.add(ap.converter);
} else {
if (s.toLowerCase().equals("between")) {
list.add(list.get(list.size() - 1));
} else if (s.toLowerCase().equals("null")) {
list.remove(list.size() - 1);
} else {
if (!KEYWORDS.contains(s.toLowerCase())) {
throw new IllegalArgumentException("Invalid string \"" + s + "\" found in clause: " + clause);
}
}
sb.append(s);
}
start = m.end();
}
sb.append(clause.substring(start));
if (list.size() != numOfPlaceholder(clause)) {
throw new IllegalArgumentException("Invalid number of placeholder.");
}
return new CompiledClause(sb.toString(), list.toArray(new AttributeConverter[0]));
}
示例15: SingularAttributeBasic
import javax.persistence.AttributeConverter; //導入依賴的package包/類
public SingularAttributeBasic(
ManagedTypeImplementor declaringType,
String name,
PropertyAccess propertyAccess,
BasicType ormType,
Disposition disposition,
AttributeConverter attributeConverter,
List<Column> columns) {
super( declaringType, name, propertyAccess, ormType, disposition, true );
this.attributeConverter = attributeConverter;
this.columns = columns;
}