use of org.firebirdsql.encodings.EncodingDefinition in project jaybird by FirebirdSQL.
the class EncodingSpecificDatatypeCoderTest method withEncodingDefinition_differentEncodingDefinitionDelegatesToParent.
@Test
public void withEncodingDefinition_differentEncodingDefinitionDelegatesToParent() {
final DatatypeCoder newCoder = context.mock(DatatypeCoder.class, "newCoder");
final EncodingDefinition otherEncodingDefinition = context.mock(EncodingDefinition.class, "otherEncodingDefinition");
context.checking(new Expectations() {
{
oneOf(parentCoder).forEncodingDefinition(otherEncodingDefinition);
will(returnValue(newCoder));
}
});
DatatypeCoder result = coder.forEncodingDefinition(otherEncodingDefinition);
assertSame(newCoder, result);
}
use of org.firebirdsql.encodings.EncodingDefinition in project jaybird by FirebirdSQL.
the class FieldDescriptorTest method shouldUseEncodingSpecificDatatypeCoder_blobTextType_notDefaultCharset.
@Test
public void shouldUseEncodingSpecificDatatypeCoder_blobTextType_notDefaultCharset() {
FieldDescriptor descriptor = createFieldDescriptor(ISCConstants.SQL_BLOB, 1, CHARSET_ID_WIN1252);
EncodingDefinition win1252EncodingDefinition = encodingFactory.getEncodingDefinitionByCharacterSetId(CHARSET_ID_WIN1252);
DatatypeCoder datatypeCoder = descriptor.getDatatypeCoder();
assertThat(datatypeCoder, instanceOf(EncodingSpecificDatatypeCoder.class));
assertEquals(win1252EncodingDefinition, datatypeCoder.getEncodingDefinition());
assertEquals(-1, descriptor.getCharacterLength());
}
use of org.firebirdsql.encodings.EncodingDefinition in project jaybird by FirebirdSQL.
the class FBConnectionProperties method setCharSet.
public void setCharSet(String charSet) {
if (charSet == null) {
return;
}
// Normalize the name of the encoding
final EncodingDefinition encodingDefinition = EncodingFactory.getPlatformDefault().getEncodingDefinitionByCharsetAlias(charSet);
if (encodingDefinition == null) {
return;
}
setStringProperty(LOCAL_ENCODING_PROPERTY, encodingDefinition.getJavaEncodingName());
if (getStringProperty(ENCODING_PROPERTY) != null) {
return;
}
String encoding = encodingDefinition.getFirebirdEncodingName();
if (encoding != null) {
setStringProperty(ENCODING_PROPERTY, encoding);
}
}
use of org.firebirdsql.encodings.EncodingDefinition in project jaybird by FirebirdSQL.
the class FBConnectionProperties method setEncoding.
public void setEncoding(String encoding) {
if (encoding == null) {
return;
}
setStringProperty(ENCODING_PROPERTY, encoding);
if (getStringProperty(LOCAL_ENCODING_PROPERTY) != null) {
return;
}
final EncodingDefinition encodingDefinition = EncodingFactory.getPlatformDefault().getEncodingDefinitionByFirebirdName(encoding);
if (encodingDefinition != null && !encodingDefinition.isInformationOnly()) {
setStringProperty(LOCAL_ENCODING_PROPERTY, encodingDefinition.getJavaEncodingName());
}
}
use of org.firebirdsql.encodings.EncodingDefinition in project jaybird by FirebirdSQL.
the class FieldDescriptor method datatypeCoderForType.
/**
* Returns a type-specific coder for this datatype.
* <p>
* Primary intent is to handle character set conversion for char, varchar and blob sub_type text.
* </p>
*
* @param datatypeCoder
* Datatype coder to use for obtaining the type-specific variant
* @param type
* Firebird type code
* @param subType
* Firebird sub type code
* @param scale
* Scale
* @return type-specific datatype coder
*/
private static DatatypeCoder datatypeCoderForType(DatatypeCoder datatypeCoder, int type, int subType, int scale) {
int characterSetId = getCharacterSetId(type, subType, scale);
EncodingDefinition encodingDefinition = datatypeCoder.getEncodingFactory().getEncodingDefinitionByCharacterSetId(characterSetId);
return datatypeCoder.forEncodingDefinition(encodingDefinition);
}
Aggregations