当前位置: 首页>>代码示例>>Java>>正文


Java PGobject.setType方法代码示例

本文整理汇总了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);
		}
	}
}
 
开发者ID:finefuture,项目名称:data-migration,代码行数:18,代码来源:JsonbUserType.java

示例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);
    }
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:28,代码来源:PostgresDocHandler.java

示例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);
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:11,代码来源:PgIndexCreationTest.java

示例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 );
}
 
开发者ID:dhis2,项目名称:dhis2-core,代码行数:18,代码来源:JsonListBinaryType.java

示例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 );
  }
}
 
开发者ID:realityforge,项目名称:geolatte-geom-jpa,代码行数:20,代码来源:PostgisConverter.java

示例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);
  }
}
 
开发者ID:pires,项目名称:hibernate-postgres-jsonb,代码行数:17,代码来源:JSONBUserType.java

示例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);
	}
}
 
开发者ID:egore,项目名称:osmgress,代码行数:27,代码来源:PortalDao.java

示例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);
	}
}
 
开发者ID:JadiraOrg,项目名称:jadira,代码行数:19,代码来源:PersistentStringMapAsPostgreSQLJson.java

示例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());
        }
    }
}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:35,代码来源:PostgresqlDatabase.java

示例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;
}
 
开发者ID:alphagov,项目名称:pay-adminusers,代码行数:12,代码来源:CustomBrandingConverter.java

示例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);
    }
}
 
开发者ID:openregister,项目名称:openregister-java,代码行数:11,代码来源:IndexQueryDAO.java

示例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;
}
 
开发者ID:openregister,项目名称:openregister-java,代码行数:8,代码来源:Item.java

示例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;
}
 
开发者ID:sebastian-r-schmidt,项目名称:logicaldecoding,代码行数:15,代码来源:TrackTablePublisher.java

示例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 );
}
 
开发者ID:dhis2,项目名称:dhis2-core,代码行数:16,代码来源:JsonBinaryType.java

示例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);
}
 
开发者ID:datapublica,项目名称:hibernate-pg-json,代码行数:11,代码来源:RawJsonType.java


注:本文中的org.postgresql.util.PGobject.setType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。