本文整理汇总了Java中org.postgresql.util.PGobject.setType方法的典型用法代码示例。如果您正苦于以下问题:Java PGobject.setType方法的具体用法?Java PGobject.setType怎么用?Java PGobject.setType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.postgresql.util.PGobject
的用法示例。
在下文中一共展示了PGobject.setType方法的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: 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);
}
}
示例3: 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);
}
示例4: 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 );
}
示例5: convertToDatabaseColumn
import org.postgresql.util.PGobject; //导入方法依赖的package包/类
@Override
public Object convertToDatabaseColumn( final T attribute )
{
if ( null == attribute )
{
final PGobject pgObject = new PGobject();
pgObject.setType( "geometry" );
return pgObject;
}
final String wkt = Wkt.newEncoder( Dialect.POSTGIS_EWKT_1 ).encode( attribute );
try
{
return new PGgeometry( wkt );
}
catch ( final SQLException se )
{
throw new IllegalStateException( "Failed converting geometry", se );
}
}
示例6: nullSafeSet
import org.postgresql.util.PGobject; //导入方法依赖的package包/类
@Override
public void nullSafeSet(PreparedStatement st, Object value, int index,
SessionImplementor session) throws HibernateException, SQLException {
try {
final String json = value == null
? null
: MAPPER.writeValueAsString(value);
// otherwise PostgreSQL won't recognize the type
PGobject pgo = new PGobject();
pgo.setType(JSONB_TYPE);
pgo.setValue(json);
st.setObject(index, pgo);
} catch (JsonProcessingException ex) {
throw new HibernateException(ex);
}
}
示例7: own
import org.postgresql.util.PGobject; //导入方法依赖的package包/类
public static Portal own(Portal portal, User owner) {
try (Connection connection = ConnectionFactory.getConnection()) {
try (PreparedStatement statement = connection
.prepareStatement("UPDATE osmg_portal SET owner_id = ?, slots = ? WHERE id = ?")) {
statement.setLong(1, owner.getId());
PGobject slotsJson = new PGobject();
slotsJson.setType("json");
slotsJson.setValue(new Gson().toJson(portal.getSlots()));
statement.setObject(2, slotsJson);
statement.setLong(3, portal.getId());
int count = statement.executeUpdate();
if (count == 0) {
throw new IllegalArgumentException("Could not own portal");
} else if (count > 1) {
throw new IllegalArgumentException(
"Owned more than one portal");
}
portal.setOwner(owner);
return portal;
}
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
示例8: doNullSafeSet
import org.postgresql.util.PGobject; //导入方法依赖的package包/类
@Override
public void doNullSafeSet(PreparedStatement preparedStatement, Map<String, String> value, int index,
SharedSessionContractImplementor session) throws SQLException {
if (value == null) {
preparedStatement.setNull(index, Types.NULL);
} else {
String identifier = toString(value);
;
PGobject jsonObject = new PGobject();
jsonObject.setType("json");
jsonObject.setValue(identifier);
preparedStatement.setObject(index, jsonObject);
}
}
示例9: bindParam
import org.postgresql.util.PGobject; //导入方法依赖的package包/类
void bindParam(PreparedStatement p, List<Object> args) throws SQLException
{
if (args == null)
return;
for (int ii = 0; ii < args.size(); ii++)
{
Object v = args.get(ii);
if (v == null) {
p.setNull(ii+1, java.sql.Types.NULL);
} else if (v instanceof Integer) {
p.setInt(ii+1, (Integer)v);
} else if (v instanceof Long) {
p.setLong(ii+1, (Long)v);
} else if (v instanceof Double) {
p.setDouble(ii+1, (Double)v);
} else if (v instanceof String) {
p.setString(ii+1, (String)v);
} else if (v instanceof Boolean) {
p.setBoolean(ii+1, (Boolean)v);
} else if (v instanceof UUID) {
p.setObject(ii+1, v);
} else if (v instanceof JSONObject) {
PGobject pgo = new PGobject();
pgo.setType("json");
pgo.setValue(((JSONObject)v).toJSONString());
p.setObject(ii+1, pgo);
} else if (v instanceof Timestamp) {
p.setTimestamp(ii+1, (Timestamp)v);
} else {
throw new SQLException("unexpected param type: " + v.getClass());
}
}
}
示例10: convertToDatabaseColumn
import org.postgresql.util.PGobject; //导入方法依赖的package包/类
@Override
public PGobject convertToDatabaseColumn(Map<String, Object> customBranding) {
PGobject dbCustomBranding = new PGobject();
dbCustomBranding.setType("json");
try {
dbCustomBranding.setValue(new ObjectMapper().writeValueAsString(customBranding));
} catch (SQLException | JsonProcessingException e) {
throw new RuntimeException(e);
}
return dbCustomBranding;
}
示例11: writePGObject
import org.postgresql.util.PGobject; //导入方法依赖的package包/类
private PGobject writePGObject(String key, String value) {
try {
PGobject json = new PGobject();
json.setType("jsonb");
json.setValue(objectMapper.writeValueAsString(ImmutableMap.of(key, value)));
return json;
} catch (SQLException | JsonProcessingException e) {
throw Throwables.propagate(e);
}
}
示例12: getContentAsJsonb
import org.postgresql.util.PGobject; //导入方法依赖的package包/类
@SuppressWarnings("unused, used by DAO")
public PGobject getContentAsJsonb() throws SQLException {
PGobject data = new PGobject();
data.setType("jsonb");
data.setValue(content.toString());
return data;
}
示例13: getJsonObject
import org.postgresql.util.PGobject; //导入方法依赖的package包/类
private PGobject getJsonObject(List<Cell> cells) {
List<String> parts = new ArrayList<String>();
for (Cell cell:cells) {
parts.add(cell.getJson());
}
PGobject pgobject = new PGobject();
pgobject.setType("jsonb");
try {
pgobject.setValue("{" + Joiner.on(", ").join(parts) + "}");
} catch (SQLException e) {
log.error("Error while setting JSONB of changed Objects into SQL PGobject type:", e);
}
return pgobject;
}
示例14: 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 );
}
示例15: nullSafeSet
import org.postgresql.util.PGobject; //导入方法依赖的package包/类
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException {
if (value == null) {
st.setObject(index, null);
return;
}
PGobject pg = new PGobject();
pg.setType(isBinary ? "jsonb" : "json");
pg.setValue(serialize(value));
st.setObject(index, pg);
}