datastax java驱动程序更新无提示失败

时间:2015-03-19 14:41:39

标签: java updates datastax

我有一个共享(与其他应用程序)Cassandra数据库,它集中在2个不同的节点中。我使用的是Cassandra Database 2.1.2和Java Datastax驱动程序2.1.4版。

我创建了一个与此类似的:

package com.me.name.data.model.cassandra;

@Table(name = "name")
public final class NameDo
{
/*
 * the unique identifier
 */
@PartitionKey
private UUID            id;

/*
 * The package name
 */
@Column(name = "name")
private String          name;

/*
 * the version number
 */
@Column(name = "version")
private String          version;

/*
 * the trial period configured.
 */
@Column(name = "period")
private Integer         period;

/*
 * The last update date
 */
@Column(name = "status_last_update")
private Date            statusLastUpdate;

/*
 * The trial start date
 */
@Column(name = "trial_start_date")
private Date            trialStartDate;

/*
 * The description
 */
@Column(name = "description")
private String           description;

我正在使用这样的群集:

public final class ClusterManagerServiceImpl implements ClusterManagerService
{
private @Value("${cassandra.contactpoints}") String clusterHost;
private Cluster                                     cluster;
private static final Logger                         LOGGER = Logger.getLogger(ClusterManagerServiceImpl.class);

@Autowired
private AuthProviderImpl authProvider;

public String getClusterHost()
{
    return clusterHost;
}

public void setClusterHost(String clusterHost)
{
    this.clusterHost = clusterHost;
}

public Cluster getCluster()
{
    if (cluster == null)
    {
        try
        {
            this.createCluster();
        }
        catch (UnknownHostException e)
        {
            LOGGER.error(e);
        }
    }
    return cluster;
}

public void setCluster(Cluster cluster)
{
    this.cluster = cluster;
}

public void createCluster() throws UnknownHostException
{
    try
    {
        if (cluster == null)
        {
            LOGGER.debug("opening new Cluster");
            setCluster(Cluster.builder().withAuthProvider(authProvider).addContactPoints(InetAddress.getByName(getClusterHost())).build());
        }
    }
    catch (UnknownHostException e)
    {
        LOGGER.error(e);
    }
}

因此,每次我想要进行更新或插入时,我都会这样做:

protected Session createSessionOnCluster(Session session) {
    LOGGER.debug("opening new session");
    session = clusterManagerServiceImpl.getCluster().connect(KEYSPACE_NAME);

    return (session);
}

private Mapper<NameDo> createPackageMapper(Session session) {
    MappingManager manager = new MappingManager(session);
    Mapper<NameDo> mapper = manager.mapper(NameDo.class);
    return mapper;
}

public NameDo updateName(NameDo nameDo)
        {
    Session session = null;

    nameDo.setStatusLastUpdate(new Date());
    session = createSessionOnCluster(session);

    Mapper<NameDo> mapper = createPackageMapper(session);
    mapper.save(nameDo);

    return nameDo;
}

所以......毕竟......我正在进行更新并且它根本不会引发任何错误,但在我检查数据库之后,我的名表没有更新。

  1. 有谁知道这可能导致什么?
  2. 是卡桑德拉吗?
  3. 是DataStax驱动程序吗?
  4. 有解决方法吗?

0 个答案:

没有答案