Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or .
*/
package org.hibernate.dialect;
import java.io.IOException;
import java.io.OutputStream;
import java.sql.SQLException;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import org.hibernate.Internal;
import org.hibernate.internal.util.CharSequenceHelper;
import org.hibernate.metamodel.mapping.AttributeMapping;
import org.hibernate.metamodel.mapping.EmbeddableMappingType;
import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.metamodel.mapping.SelectableMapping;
import org.hibernate.metamodel.mapping.internal.EmbeddedAttributeMapping;
import org.hibernate.sql.ast.spi.SqlAppender;
import org.hibernate.type.SqlTypes;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.JavaType;
import org.hibernate.type.descriptor.java.JdbcDateJavaType;
import org.hibernate.type.descriptor.java.JdbcTimeJavaType;
import org.hibernate.type.descriptor.java.JdbcTimestampJavaType;
import org.hibernate.type.descriptor.java.OffsetDateTimeJavaType;
import org.hibernate.type.descriptor.jdbc.AggregateJdbcType;
/**
* A Helper for serializing and deserializing XML, based on an {@link EmbeddableMappingType}.
*/
@Internal
public class XmlHelper {
/**
* The root tag under which values are placed as XML elements.
*/
public static final String ROOT_TAG = "e";
private static final String START_TAG = "<" + ROOT_TAG + ">";
private static final String END_TAG = "" + ROOT_TAG + ">";
private static Object fromEscapedString(
JdbcMapping jdbcMapping,
String string,
int start,
int end) {
final String unescaped = unescape( string, start, end );
return fromString( jdbcMapping, unescaped, 0, unescaped.length() );
}
private static Object fromString(
JdbcMapping jdbcMapping,
String string,
int start,
int end) {
return jdbcMapping.getJdbcJavaType().fromEncodedString(
string,
start,
end
);
}
private static Object fromRawObject(
JdbcMapping jdbcMapping,
Object raw,
WrapperOptions options) {
return jdbcMapping.getJdbcJavaType().wrap(
raw,
options
);
}
private static String unescape(String string, int start, int end) {
final StringBuilder sb = new StringBuilder( end - start );
for ( int i = start; i < end; i++ ) {
final char c = string.charAt( i );
OUTER: switch ( c ) {
case '<':
sb.append( "<" );
break;
case '&':
// It must be & or <
if ( i + 3 < end ) {
final char c1 = string.charAt( i + 1 );
switch ( c1 ) {
case 'l':
if ( string.charAt( i + 2 ) == 't' && string.charAt( i + 3 ) == ';' ) {
sb.append( '<' );
i += 3;
}
break OUTER;
case 'a':
if ( i + 4 < end
&& string.charAt( i + 2 ) == 'm'
&& string.charAt( i + 3 ) == 'p'
&& string.charAt( i + 4 ) == ';' ) {
sb.append( '&' );
i += 4;
}
break OUTER;
case 'g':
if ( string.charAt( i + 2 ) == 't' && string.charAt( i + 3 ) == ';' ) {
sb.append( '>' );
i += 3;
}
break OUTER;
}
}
throw new IllegalArgumentException( "Illegal XML content: " + string.substring( start, end ) );
default:
sb.append( c );
break;
}
}
return sb.toString();
}
private static Object fromString(
EmbeddableMappingType embeddableMappingType,
String string,
WrapperOptions options,
int selectableIndex,
int start,
int end) {
final JdbcMapping jdbcMapping = embeddableMappingType.getJdbcValueSelectable( selectableIndex ).getJdbcMapping();
switch ( jdbcMapping.getJdbcType().getDefaultSqlTypeCode() ) {
case SqlTypes.BOOLEAN:
case SqlTypes.BIT:
case SqlTypes.TINYINT:
case SqlTypes.SMALLINT:
case SqlTypes.INTEGER:
case SqlTypes.BIGINT:
case SqlTypes.FLOAT:
case SqlTypes.REAL:
case SqlTypes.DOUBLE:
case SqlTypes.DECIMAL:
case SqlTypes.NUMERIC:
return fromString(
jdbcMapping,
string,
start,
end
);
case SqlTypes.DATE:
return fromRawObject(
jdbcMapping,
JdbcDateJavaType.INSTANCE.fromEncodedString(
string,
start,
end
),
options
);
case SqlTypes.TIME:
case SqlTypes.TIME_WITH_TIMEZONE:
case SqlTypes.TIME_UTC:
return fromRawObject(
jdbcMapping,
JdbcTimeJavaType.INSTANCE.fromEncodedString(
string,
start,
end
),
options
);
case SqlTypes.TIMESTAMP:
return fromRawObject(
jdbcMapping,
JdbcTimestampJavaType.INSTANCE.fromEncodedString(
string,
start,
end
),
options
);
case SqlTypes.TIMESTAMP_WITH_TIMEZONE:
case SqlTypes.TIMESTAMP_UTC:
return fromRawObject(
jdbcMapping,
OffsetDateTimeJavaType.INSTANCE.fromEncodedString(
string,
start,
end
),
options
);
case SqlTypes.BINARY:
case SqlTypes.VARBINARY:
case SqlTypes.LONGVARBINARY:
case SqlTypes.LONG32VARBINARY:
case SqlTypes.UUID:
return fromRawObject(
jdbcMapping,
Base64.getDecoder().decode( string.substring( start, end ) ),
options
);
default:
return fromEscapedString(
jdbcMapping,
string,
start,
end
);
}
}
public static X fromString(
EmbeddableMappingType embeddableMappingType,
String string,
boolean returnEmbeddable,
WrapperOptions options) throws SQLException {
if ( !string.startsWith( START_TAG ) || !string.endsWith( END_TAG ) ) {
throw new IllegalArgumentException( "Illegal XML for struct: " + string );
}
int end;
final Object[] array;
if ( embeddableMappingType == null ) {
assert !returnEmbeddable;
final List