本文整理汇总了Java中org.postgresql.util.PGobject类的典型用法代码示例。如果您正苦于以下问题:Java PGobject类的具体用法?Java PGobject怎么用?Java PGobject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PGobject类属于org.postgresql.util包,在下文中一共展示了PGobject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: nullSafeSet
import org.postgresql.util.PGobject; //导入依赖的package包/类
@Override
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session)
throws HibernateException, SQLException {
if (value == null) {
st.setNull(index, Types.OTHER);
} else {
Object obj = JSON.toJSONString(value);
if (obj == null) {
st.setNull(index, Types.OTHER);
} else {
PGobject pgObject = new PGobject();
pgObject.setType(JSONB_TYPE);
pgObject.setValue(obj.toString());
st.setObject(index, pgObject, Types.OTHER);
}
}
}
示例2: parseValueObj
import org.postgresql.util.PGobject; //导入依赖的package包/类
/**
* 解析json值
*
* @param field
* @param pGobject
* @return
*/
private Object parseValueObj(Field field, PGobject pGobject) {
String value = pGobject.getValue();
if (value == null) {
return null;
}
Object obj;
if (field.getType().equals(List.class)) { // List类型
Class<?>[] genericTypes = GenericTypeUtils.getGenericType(field.getGenericType());
obj = JSON.parseArray(value, genericTypes[0]);
} else if (field.getType().equals(Map.class)) { // Map类型
obj = JSON.parseObject(value, field.getGenericType());
} else {
obj = JSON.parseObject(value, field.getType());
}
return obj;
}
示例3: safeSetPoint
import org.postgresql.util.PGobject; //导入依赖的package包/类
/**
* Store point value of an spoint column.
*
* @param sb
* @param ps
* @param col
* @param val
* @throws SQLException
*/
@Override
protected void safeSetPoint(StringBuilder sb, PreparedStatement ps, int col, Point val)
throws SQLException {
if (val == null) {
ps.setObject(col, null);
if (sb != null) {
sb.append("null,");
}
} else {
log.debug("[safeSetPoint] in: " + val);
PgSpoint pgs = new PgSpoint();
PGobject pgo = pgs.generatePoint(new ca.nrc.cadc.dali.Point(val.cval1, val.cval2));
ps.setObject(col, pgo);
if (sb != null) {
sb.append(pgo.getValue());
sb.append(",");
}
}
}
示例4: safeSetPositionBounds
import org.postgresql.util.PGobject; //导入依赖的package包/类
/**
* Store polygon value in an spoly column.
*
* @param sb
* @param ps
* @param col
* @param val
* @throws SQLException
*/
@Override
protected void safeSetPositionBounds(StringBuilder sb, PreparedStatement ps, int col, Polygon val)
throws SQLException {
if (val == null) {
ps.setObject(col, null);
if (sb != null) {
sb.append("null,");
}
} else {
log.debug("[safeSetPositionBounds] in: " + val);
ca.nrc.cadc.dali.Polygon poly = new ca.nrc.cadc.dali.Polygon();
for (Point p : val.getPoints()) {
poly.getVertices().add(new ca.nrc.cadc.dali.Point(p.cval1, p.cval2));
}
PgSpoly pgs = new PgSpoly();
PGobject pgo = pgs.generatePolygon(poly);
ps.setObject(col, pgo);
if (sb != null) {
sb.append(pgo.getValue());
sb.append(",");
}
}
}
示例5: shouldSaveAService_withoutCustomisations
import org.postgresql.util.PGobject; //导入依赖的package包/类
@Test
public void shouldSaveAService_withoutCustomisations() throws Exception {
ServiceEntity serviceEntity = new ServiceEntity();
String serviceExternalId = randomUuid();
serviceEntity.setExternalId(serviceExternalId);
serviceEntity.setName("random name");
serviceDao.persist(serviceEntity);
List<Map<String, Object>> savedService = databaseHelper.findServiceByExternalId(serviceExternalId);
assertThat(savedService.size(), is(1));
assertThat(savedService.get(0).get("external_id"), is(serviceExternalId));
Map<String, Object> storedBranding = new CustomBrandingConverter().convertToEntityAttribute((PGobject) savedService.get(0).get("custom_branding"));
assertNull(storedBranding);
}
示例6: convert
import org.postgresql.util.PGobject; //导入依赖的package包/类
public JsonElement convert(Object val) throws ConverterException {
if (val == null) return null;
if (val instanceof JsonElement) return (JsonElement) val;
String jsonString;
if (val instanceof String) {
jsonString = (String) val;
} else if (val instanceof PGobject) {
// at one side this is just a demo
// the better way is to unwrap PGObject to String
// with type==json in Quirks.getRSVal
jsonString = ((PGobject) val).getValue();
} else {
jsonString = stringConverterHolder.converter.convert(val);
}
return parserHolder.parser.parse(jsonString);
}
示例7: put
import org.postgresql.util.PGobject; //导入依赖的package包/类
/**
* Put a key/value pair in the database
*
* @param key
* @param value
*/
public void put(String key, String value) {
String sql = String.format("select rap_insert_%s(:key, :content);", tableName);
PGobject valueJson = new PGobject();
valueJson.setType("jsonb");
try {
valueJson.setValue(value);
} catch (SQLException e) {
log.error(ExceptionToString.format(e));
valueJson = null;
}
if (valueJson != null) {
SqlParameterSource paramSource = new MapSqlParameterSource("key", key).addValue("content", valueJson);
RowMapper<Boolean> rowMapper = new RowMapper<Boolean>() {
@Override
public Boolean mapRow(ResultSet rs, int rowNum) throws SQLException {
return true;
}
};
namedJdbcTemplate.query(sql, paramSource, rowMapper);
}
}
示例8: insertValue
import org.postgresql.util.PGobject; //导入依赖的package包/类
private void insertValue(NamedParameterJdbcTemplate jdbcTemplate, int i) throws SQLException {
String value = String.format("{\"id\": "
+ "\"%s\", \"max\": 2, \"message\": \"what upz\", \"lastSeen\": 12345, \"progress\": 1}", i);
PGobject valueJson = new PGobject();
valueJson.setType("jsonb");
valueJson.setValue(value);
SqlParameterSource params = new MapSqlParameterSource().addValue("keyIn", "key" + i).addValue("contentIn", valueJson);
jdbcTemplate.update("INSERT INTO activity\n"
+ "VALUES(:keyIn, :contentIn, now());\n", params);
}
示例9: getFeature
import org.postgresql.util.PGobject; //导入依赖的package包/类
@Override
public double getFeature(User user, DBpediaResource resource) {
PGobject userVectorRaw = DSL.using(source, SQLDialect.POSTGRES)
.select(USER_TEXT.LSA)
.from(USER_TEXT)
.where(USER_TEXT.UID.eq(user.getId()))
.fetchOne(USER_TEXT.LSA, PGobject.class);
if (userVectorRaw == null) {
if (verbose) {
LOGGER.debug("Can't find LSA for user: @"+user.getScreenName()+" ("+user.getId()+")");
}
return 0.0d;
}
return process(cubeToFloat(userVectorRaw), resource);
}
示例10: nullSafeSet
import org.postgresql.util.PGobject; //导入依赖的package包/类
@Override
public void nullSafeSet( PreparedStatement ps, Object value, int idx, SharedSessionContractImplementor session )
throws HibernateException,
SQLException
{
if ( value == null )
{
ps.setObject( idx, null );
return;
}
PGobject pg = new PGobject();
pg.setType( "jsonb" );
pg.setValue( convertObjectToJson( value ) );
ps.setObject( idx, pg );
}
示例11: valueToSqlType
import org.postgresql.util.PGobject; //导入依赖的package包/类
private static int valueToSqlType(final Object value) {
if ( value == null ) {
return Types.NULL;
}
if ( value instanceof String ) {
return Types.LONGVARCHAR;
} else if ( value instanceof Integer ) {
return Types.INTEGER;
} else if ( value instanceof Long ) {
return Types.BIGINT;
} else if ( value instanceof PGobject ) {
return Types.OTHER;
} else if ( value instanceof Timestamp || value instanceof Date ) {
return Types.TIMESTAMP;
} //FIXME: COMPLETE This
throw new RuntimeException("Type not supported: " + value);
}
示例12: nullSafeGet
import org.postgresql.util.PGobject; //导入依赖的package包/类
@Override
public Object nullSafeGet(final ResultSet rs, final String[] names,
final SessionImplementor session, final Object owner)
throws HibernateException, SQLException {
Object object = rs.getObject(names[0]);
if (rs.wasNull()) {
return null;
}
// Notice how Object is mapped to PGobject. This makes this implementation Postgres specific
if (object instanceof PGobject) {
PGobject pg = (PGobject) object;
return Enum.valueOf(enumClass, pg.getValue());
}
return null;
}
示例13: testNullSafeGet
import org.postgresql.util.PGobject; //导入依赖的package包/类
@Test
public void testNullSafeGet() throws Exception {
// Given
String[] names = { "status" };
PGobject value = new PGobject();
value.setValue("ACTIVE");
// When
when(rs.wasNull()).thenReturn(false);
when(rs.getObject(anyString())).thenReturn(value );
Object actual = unit.nullSafeGet(rs, names, session, owner);
// Then
assertEquals(RowStatus.ACTIVE, actual);
}
示例14: testNullSafeGetWhenRsWasNull
import org.postgresql.util.PGobject; //导入依赖的package包/类
@Test
public void testNullSafeGetWhenRsWasNull() throws Exception {
// Given
String[] names = { "status" };
PGobject value = new PGobject();
value.setValue("ACTIVE");
// When
when(rs.wasNull()).thenReturn(true);
when(rs.getObject(anyString())).thenReturn(value );
Object actual = unit.nullSafeGet(rs, names, session, owner);
// Then
assertEquals(null, actual);
}
示例15: nullSafeGet
import org.postgresql.util.PGobject; //导入依赖的package包/类
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException {
final Object result = rs.getObject(names[0]);
if (!rs.wasNull()) {
String content;
if (result instanceof String) {
content = (String) result;
} else if (result instanceof PGobject) {
// If we get directly the PGobject for some reason (more exactly, if a DB like H2 does the serialization directly)
content = ((PGobject) result).getValue();
} else {
throw new IllegalArgumentException("Unknown object type (excepted pgobject or json string)");
}
if (content != null) {
return deserialize(content);
}
}
return null;
}