Java Code Examples for org.eclipse.persistence.sessions.Session#getPlatform()

The following examples show how to use org.eclipse.persistence.sessions.Session#getPlatform() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UuidConverter.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
public Object convertDataValueToObjectValue(Object dataValue, Session session) {
    try {
        if (session.getPlatform() instanceof PostgreSQLPlatform) {
            return dataValue;
        } else if (session.getPlatform() instanceof OraclePlatform
                || session.getPlatform() instanceof MySQLPlatform) {
            if (dataValue instanceof String) {
                StringBuilder sb = new StringBuilder((String) dataValue);
                sb.insert(8, '-');
                sb.insert(13, '-');
                sb.insert(18, '-');
                sb.insert(23, '-');
                return UuidProvider.fromString(sb.toString());
            } else {
                return dataValue;
            }
        } else {
            return dataValue instanceof String ? UuidProvider.fromString((String) dataValue) : dataValue;
        }
    } catch (Exception e) {
        throw new RuntimeException("Error creating UUID from database value '" + dataValue + "'", e);
    }
}
 
Example 2
Source File: UuidMappingProcessor.java    From cuba with Apache License 2.0 6 votes vote down vote up
private void setDatabaseFieldParameters(Session session, DatabaseField field) {
    if (session.getPlatform() instanceof PostgreSQLPlatform) {
        field.setSqlType(Types.OTHER);
        field.setType(UUID.class);
        field.setColumnDefinition("UUID");
    } else if (session.getPlatform() instanceof MySQLPlatform) {
        field.setSqlType(Types.VARCHAR);
        field.setType(String.class);
        field.setColumnDefinition("varchar(32)");
    } else if (session.getPlatform() instanceof HSQLPlatform) {
        field.setSqlType(Types.VARCHAR);
        field.setType(String.class);
        field.setColumnDefinition("varchar(36)");
    } else if (session.getPlatform() instanceof SQLServerPlatform) {
        field.setSqlType(Types.VARCHAR);
        field.setType(String.class);
        field.setColumnDefinition("uniqueidentifier");
    } else if (session.getPlatform() instanceof OraclePlatform) {
        field.setSqlType(Types.VARCHAR);
        field.setType(String.class);
        field.setColumnDefinition("varchar2(32)");
    } else {
        field.setSqlType(Types.VARCHAR);
        field.setType(String.class);
    }
}
 
Example 3
Source File: StudioEclipseLinkSessionEventListener.java    From cuba with Apache License 2.0 5 votes vote down vote up
private void setDatabaseFieldParameters(Session session, DatabaseField field) {
    if (session.getPlatform() instanceof PostgreSQLPlatform) {
        field.setSqlType(Types.OTHER);
        field.setType(UUID.class);
    } else {
        field.setSqlType(Types.VARCHAR);
        field.setType(String.class);
    }
    field.setColumnDefinition("UUID");
}
 
Example 4
Source File: UuidConverter.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public Object convertObjectValueToDataValue(Object objectValue, Session session) {
    if (session.getPlatform() instanceof PostgreSQLPlatform) {
        return objectValue;
    } else if (session.getPlatform() instanceof SQLServerPlatform) {
        return objectValue != null ? objectValue.toString().toUpperCase() : null; // for correct binding of batch query results
    } else if (session.getPlatform() instanceof OraclePlatform
            || session.getPlatform() instanceof MySQLPlatform) {
        return objectValue != null ? objectValue.toString().replace("-", "") : null;
    } else {
        return objectValue != null ? objectValue.toString() : null;
    }
}
 
Example 5
Source File: MapToStringConverter.java    From gazpachoquest with GNU General Public License v3.0 4 votes vote down vote up
public boolean isPostgresProvider(Session session) {
    return (session.getPlatform() instanceof PostgreSQLPlatform);
}