You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by Kenan Dalley <ke...@gm.com> on 2017/01/04 15:01:24 UTC

Re: Ignite with Cassandra questions / errors

This is what I remember reading in the docs as well.  However, I just ran the
DDLGenerator using my Cassandra-persistence-settings.xml file and the
following is what it generated.  So, either I don't have something set up
correctly for Ignite to recognize the Annotations, or there's a problem in
the DDLGenerator such that the Annotations are being ignored by it.  I'm
perfectly willing to accept that I've done something wrong.  


-------------------------------------------------------------
DDL for keyspace/table from file:
resources/cassandra-persistence-settings.xml
-------------------------------------------------------------

create keyspace if not exists "dev_qlty"
with replication = {'class' : 'SimpleStrategy', 'replication_factor' : 3}
and durable_writes = true;

create table if not exists "dev_qlty"."HistoryResult"
(
 "algorithmname" text,
 "sessionid" text,
 "vin" text,
 "createdby" text,
 "modifiedby" text,
 "results" text,
 primary key (("algorithmname", "sessionid", "vin"))
) 
with comment = 'Test table for Ignite/Cassandra connection' AND
read_repair_chance = 0.2;





--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Ignite-with-Cassandra-questions-errors-tp9607p9875.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Ignite with Cassandra questions / errors

Posted by Kenan Dalley <ke...@gm.com>.
Ah, now I understand.  

That worked.  Thanks!



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Ignite-with-Cassandra-questions-errors-tp9607p9913.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Ignite with Cassandra questions / errors

Posted by Igor Rudyak <ir...@gmail.com>.
Hi Kenan,

You missed the main point - getters or setters of your custom classes should
be annotated with *@QuerySqlField* instead of class private members. Here is
a slightly modified version of your custom classes which should work:

================================== 
import org.apache.ignite.cache.affinity.AffinityKeyMapped;
import org.apache.ignite.cache.query.annotations.QuerySqlField;

public class HistoryResultKey {
    private String vin;

    private String sessionId;

    private String histName;

    public HistoryResultKey() {
        // No op.
    }

    public HistoryResultKey(final String vin, final String sessionId, final
String histName) {
        this.vin = vin;
        this.sessionId = sessionId;
        this.histName= histName;
    }

    @AffinityKeyMapped
    @QuerySqlField(index=true, groups={"historyResultPK"})
    public String getVin() {
        return vin;
    }

    public void setVin(String vin) {
        this.vin = vin;
    }

    @QuerySqlField(index=true, groups={"historyResultPK"},
name="session_id")
    public String getSessionId() {
        return sessionId;
    }

    public void setSessionId(String sessionId) {
        this.sessionId = sessionId;
    }

    @QuerySqlField(index=true, groups={"historyResultPK"}, name="hist_name")
    public String getHistName() {
        return histName;
    }

    public void setHistName(String histName) {
        this.histName= histName;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o)
            return true;

        if (!(o instanceof HistoryResultKey))
            return false;

        HistoryResultKey that = (HistoryResultKey)o;

        if (vin != null ? !vin.equals(that.vin) : that.vin != null)
            return false;

        if (sessionId != null ? !sessionId.equals(that.sessionId) :
that.sessionId != null)
            return false;

        if (histName!= null ? !histName.equals(that.histName) :
that.histName!= null)
            return false;

        return true;
    }

    @Override
    public int hashCode() {
        int res = vin != null ? vin.hashCode() : 0;
        res = 31 * res + (sessionId != null ? sessionId.hashCode() : 0);
        res = 31 * res + (histName!= null ? histName.hashCode() : 0);
        return res;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("HistoryResultKey = [");
        sb.append("vin: ");
        sb.append(vin);
        sb.append(", sessionId: ");
        sb.append(sessionId);
        sb.append(", histName: ");
        sb.append(histName);
        sb.append("]");
        return sb.toString();
    }
}


================================== 
import org.apache.ignite.cache.query.annotations.QuerySqlField;
import org.apache.ignite.cache.query.annotations.QueryTextField;

import java.util.Date;

public class HistoryResult {
    private String vin;

    private String sessionId;

    private Date sessionTime;

    private String histName;

    private String results;

    private Date analysisTime;

    private Date createdDate;

    private String createdBy;

    private Date modifiedDate;

    private String modifiedBy;

    public HistoryResult() {
        // no op
    }

    public HistoryResult(final String vin, final String sessionId, final
Date sessionTime,
                         final String histName, final String results, final
Date analysisTime,
                         final Date createdDate, final String createdBy,
final Date modifiedDate,
                         final String modifiedBy) {
        this.vin = vin;
        this.sessionId = sessionId;
        this.sessionTime = sessionTime;
        this.histName= histName;
        this.results = results;
        this.analysisTime = analysisTime;
        this.createdDate = createdDate;
        this.createdBy = createdBy;
        this.modifiedDate = modifiedDate;
        this.modifiedBy = modifiedBy;
    }

    @QuerySqlField
    public String getVin() {
        return vin;
    }

    public void setVin(String vin) {
        this.vin = vin;
    }

    @QuerySqlField(name="session_id")
    public String getSessionId() {
        return sessionId;
    }

    public void setSessionId(String sessionId) {
        this.sessionId = sessionId;
    }

    @QuerySqlField(name="session_time")
    public Date getSessionTime() {
        return sessionTime;
    }

    public void setSessionTime(Date sessionTime) {
        this.sessionTime = sessionTime;
    }

    @QuerySqlField(name="hist_name")
    public String getHistName() {
        return histName;
    }

    public void setHistName(String histName) {
        this.histName= histName;
    }

    @QueryTextField
    public String getResults() {
        return results;
    }

    public void setResults(String results) {
        this.results = results;
    }

    @QuerySqlField(name="analysis_time")
    public Date getAnalysisTime() {
        return analysisTime;
    }

    public void setAnalysisTime(Date analysisTime) {
        this.analysisTime = analysisTime;
    }

    @QuerySqlField(name="created_dt")
    public Date getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Date createdDate) {
        this.createdDate = createdDate;
    }

    @QuerySqlField(name="created_by")
    public String getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(String createdBy) {
        this.createdBy = createdBy;
    }

    @QuerySqlField(name="modified_dt")
    public Date getModifiedDate() {
        return modifiedDate;
    }

    public void setModifiedDate(Date modifiedDate) {
        this.modifiedDate = modifiedDate;
    }

    @QuerySqlField(name="modified_by")
    public String getModifiedBy() {
        return modifiedBy;
    }

    public void setModifiedBy(String modifiedBy) {
        this.modifiedBy = modifiedBy;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o)
            return true;

        if (o == null)
            return false;

        if (!(o instanceof HistoryResult))
            return false;

        HistoryResult that = (HistoryResult)o;

        if (vin != null ? !vin.equals(that.vin) : that.vin != null)
            return false;

        if (sessionId != null ? !sessionId.equals(that.sessionId) :
that.sessionId != null)
            return false;

        if (sessionTime != null ? !sessionTime.equals(that.sessionTime) :
that.sessionTime != null)
            return false;

        if (histName!= null ? !histName.equals(that.histName) :
that.histName!= null)
            return false;

        if (results != null ? !results.equals(that.results) : that.results
!= null)
            return false;

        if (analysisTime != null ? !analysisTime.equals(that.analysisTime) :
that.analysisTime != null)
            return false;

        if (createdDate != null ? !createdDate.equals(that.createdDate) :
that.createdDate != null)
            return false;

        if (createdBy != null ? !createdBy.equals(that.createdBy) :
that.createdBy != null)
            return false;

        if (modifiedDate != null ? !modifiedDate.equals(that.modifiedDate) :
that.modifiedDate != null)
            return false;

        if (modifiedBy != null ? !modifiedBy.equals(that.modifiedBy) :
that.modifiedBy != null)
            return false;

        return true;
    }

    @Override
    public int hashCode() {
        int res = vin != null ? vin.hashCode() : 0;
        res = 31 * res + (sessionId != null ? sessionId.hashCode() : 0);
        res = 31 * res + (sessionTime != null ? sessionTime.hashCode() : 0);
        res = 31 * res + (histName!= null ? histName.hashCode() : 0);
        res = 31 * res + (results != null ? results.hashCode() : 0);
        res = 31 * res + (analysisTime != null ? analysisTime.hashCode() :
0);
        res = 31 * res + (createdDate != null ? createdDate.hashCode() : 0);
        res = 31 * res + (createdBy != null ? createdBy.hashCode() : 0);
        res = 31 * res + (modifiedDate != null ? modifiedDate.hashCode() :
0);
        res = 31 * res + (modifiedBy != null ? modifiedBy.hashCode() : 0);
        return res;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("HistoryResult = [");
        sb.append("vin: ");
        sb.append(vin);
        sb.append(", sessionId: ");
        sb.append(sessionId);
        sb.append(", sessionTime: ");
        sb.append(sessionTime);
        sb.append(", histName: ");
        sb.append(histName);
        sb.append(", results: ");
        sb.append(results);
        sb.append(", analysisTime: ");
        sb.append(analysisTime);
        sb.append(", createdDate: ");
        sb.append(createdDate);
        sb.append(", createdBy: ");
        sb.append(createdBy);
        sb.append(", modifiedDate: ");
        sb.append(modifiedDate);
        sb.append(", modifiedBy: ");
        sb.append(modifiedBy);
        sb.append("]");
        return sb.toString();
    }
}


For these two classes you Cassandra persistence descriptor could be as
simple as:

*<persistence keyspace="mykeyspace" table="HistoryResult" ttl="2592000">
    <tableOptions>
        comment = 'Test table for Ignite/Cassandra connection'
        AND read_repair_chance = 0.2
    </tableOptions>

    <keyPersistence class="com.gm.model.HistoryResultKey" strategy="POJO"/>
    <valuePersistence class="com.gm.model.HistoryResult" strategy="POJO"/>
</persistence>*



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Ignite-with-Cassandra-questions-errors-tp9607p9909.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Ignite with Cassandra questions / errors

Posted by Kenan Dalley <ke...@gm.com>.
That really wouldn't be the cause.  I didn't actually include the full bean
class implementations in the initial post in order to save space, but they
are actual fully-realized beans.

Here are their actual implementations.


==================================
import org.apache.ignite.cache.affinity.AffinityKeyMapped;
import org.apache.ignite.cache.query.annotations.QuerySqlField;

public class HistoryResultKey {
	@AffinityKeyMapped
	@QuerySqlField(index=true, groups={"historyResultPK"})
	private String vin;

	@QuerySqlField(index=true, groups={"historyResultPK"}, name="session_id")
	private String sessionId;
    
	@QuerySqlField(index=true, groups={"historyResultPK"}, name="hist_name")
	private String histName;

    public HistoryResultKey() {
        // No op.
    }

    public HistoryResultKey(final String vin, final String sessionId, final
String histName) {
        this.vin = vin;
        this.sessionId = sessionId;
        this.histName= histName;
    }

    public String getVin() {
        return vin;
    }

    public void setVin(String vin) {
        this.vin = vin;
    }

    public String getSessionId() {
        return sessionId;
    }

    public void setSessionId(String sessionId) {
        this.sessionId = sessionId;
    }

    public String getHistName() {
        return histName;
    }

    public void setHistName(String histName) {
        this.histName= histName;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o)
            return true;

        if (!(o instanceof HistoryResultKey))
            return false;

        HistoryResultKey that = (HistoryResultKey)o;

        if (vin != null ? !vin.equals(that.vin) : that.vin != null)
            return false;

        if (sessionId != null ? !sessionId.equals(that.sessionId) :
that.sessionId != null)
            return false;

        if (histName!= null ? !histName.equals(that.histName) :
that.histName!= null)
            return false;

        return true;
    }

    @Override
    public int hashCode() {
        int res = vin != null ? vin.hashCode() : 0;
        res = 31 * res + (sessionId != null ? sessionId.hashCode() : 0);
        res = 31 * res + (histName!= null ? histName.hashCode() : 0);
        return res;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("HistoryResultKey = [");
        sb.append("vin: ");
        sb.append(vin);
        sb.append(", sessionId: ");
        sb.append(sessionId);
        sb.append(", histName: ");
        sb.append(histName);
        sb.append("]");
        return sb.toString();
    }
}


===========================
import java.util.Date;

import org.apache.ignite.cache.query.annotations.QuerySqlField;
import org.apache.ignite.cache.query.annotations.QueryTextField;

public class HistoryResult {
	@QuerySqlField
    private String vin;

	@QuerySqlField(name="session_id")
	private String sessionId;

	@QuerySqlField(name="session_time")
	private Date sessionTime;

	@QuerySqlField(name="hist_name")
    private String histName;

	@QueryTextField
    private String results;

	@QuerySqlField(name="analysis_time")
    private Date analysisTime;

	@QuerySqlField(name="created_dt")
    private Date createdDate;

	@QuerySqlField(name="created_by")
    private String createdBy;

	@QuerySqlField(name="modified_dt")
    private Date modifiedDate;

	@QuerySqlField(name="modified_by")
    private String modifiedBy;

    public HistoryResult() {
        // no op
    }

    public HistoryResult(final String vin, final String sessionId, final
Date sessionTime,
                        final String histName, final String results, final
Date analysisTime,
                        final Date createdDate, final String createdBy,
final Date modifiedDate,
                        final String modifiedBy) {
    	this.vin = vin;
        this.sessionId = sessionId;
        this.sessionTime = sessionTime;
        this.histName= histName;
        this.results = results;
        this.analysisTime = analysisTime;
        this.createdDate = createdDate;
        this.createdBy = createdBy;
        this.modifiedDate = modifiedDate;
        this.modifiedBy = modifiedBy;
    }

	public String getVin() {
        return vin;
    }

    public void setVin(String vin) {
        this.vin = vin;
    }

    public String getSessionId() {
        return sessionId;
    }

    public void setSessionId(String sessionId) {
        this.sessionId = sessionId;
    }

    public Date getSessionTime() {
        return sessionTime;
    }

    public void setSessionTime(Date sessionTime) {
        this.sessionTime = sessionTime;
    }

    public String getHistName() {
        return histName;
    }

    public void setHistName(String histName) {
        this.histName= histName;
    }

    public String getResults() {
        return results;
    }

    public void setResults(String results) {
        this.results = results;
    }

    public Date getAnalysisTime() {
        return analysisTime;
    }

    public void setAnalysisTime(Date analysisTime) {
        this.analysisTime = analysisTime;
    }

    public Date getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Date createdDate) {
        this.createdDate = createdDate;
    }

    public String getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(String createdBy) {
        this.createdBy = createdBy;
    }

    public Date getModifiedDate() {
        return modifiedDate;
    }

    public void setModifiedDate(Date modifiedDate) {
        this.modifiedDate = modifiedDate;
    }

    public String getModifiedBy() {
        return modifiedBy;
    }

    public void setModifiedBy(String modifiedBy) {
        this.modifiedBy = modifiedBy;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o)
            return true;

        if (o == null)
        	return false;

        if (!(o instanceof HistoryResult))
            return false;

        HistoryResult that = (HistoryResult)o;

        if (vin != null ? !vin.equals(that.vin) : that.vin != null)
            return false;

        if (sessionId != null ? !sessionId.equals(that.sessionId) :
that.sessionId != null)
            return false;

        if (sessionTime != null ? !sessionTime.equals(that.sessionTime) :
that.sessionTime != null)
            return false;

        if (histName!= null ? !histName.equals(that.histName) :
that.histName!= null)
            return false;

        if (results != null ? !results.equals(that.results) : that.results
!= null)
            return false;

        if (analysisTime != null ? !analysisTime.equals(that.analysisTime) :
that.analysisTime != null)
            return false;

        if (createdDate != null ? !createdDate.equals(that.createdDate) :
that.createdDate != null)
            return false;

        if (createdBy != null ? !createdBy.equals(that.createdBy) :
that.createdBy != null)
            return false;

        if (modifiedDate != null ? !modifiedDate.equals(that.modifiedDate) :
that.modifiedDate != null)
            return false;

        if (modifiedBy != null ? !modifiedBy.equals(that.modifiedBy) :
that.modifiedBy != null)
            return false;

        return true;
    }

    @Override
    public int hashCode() {
        int res = vin != null ? vin.hashCode() : 0;
        res = 31 * res + (sessionId != null ? sessionId.hashCode() : 0);
        res = 31 * res + (sessionTime != null ? sessionTime.hashCode() : 0);
        res = 31 * res + (histName!= null ? histName.hashCode() : 0);
        res = 31 * res + (results != null ? results.hashCode() : 0);
        res = 31 * res + (analysisTime != null ? analysisTime.hashCode() :
0);
        res = 31 * res + (createdDate != null ? createdDate.hashCode() : 0);
        res = 31 * res + (createdBy != null ? createdBy.hashCode() : 0);
        res = 31 * res + (modifiedDate != null ? modifiedDate.hashCode() :
0);
        res = 31 * res + (modifiedBy != null ? modifiedBy.hashCode() : 0);
        return res;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("HistoryResult = [");
        sb.append("vin: ");
        sb.append(vin);
        sb.append(", sessionId: ");
        sb.append(sessionId);
        sb.append(", sessionTime: ");
        sb.append(sessionTime);
        sb.append(", histName: ");
        sb.append(histName);
        sb.append(", results: ");
        sb.append(results);
        sb.append(", analysisTime: ");
        sb.append(analysisTime);
        sb.append(", createdDate: ");
        sb.append(createdDate);
        sb.append(", createdBy: ");
        sb.append(createdBy);
        sb.append(", modifiedDate: ");
        sb.append(modifiedDate);
        sb.append(", modifiedBy: ");
        sb.append(modifiedBy);
        sb.append("]");
        return sb.toString();
    }
}





--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Ignite-with-Cassandra-questions-errors-tp9607p9900.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Ignite with Cassandra questions / errors

Posted by Igor Rudyak <ir...@gmail.com>.
Ok, 

I took a look at the *HistoryResult* implementation once again and found the
reason. Your java class should follow  JavaBeans Conventions
<http://docstore.mik.ua/orelly/java-ent/jnut/ch06_02.htm>  . The most
important here is that you class should implement getters/setters methods
for READ/WRITE properties or getters for READ-ONLY properties.

In your case you just have a class with *private* members annotated by
*@QuerySqlField* - this will not work. You should implement getters/setters
methods for these *private* fields and then annotate getter or setter with
*@QuerySqlField*



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Ignite-with-Cassandra-questions-errors-tp9607p9887.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Ignite with Cassandra questions / errors

Posted by Kenan Dalley <ke...@gm.com>.
Ok, so I got my code working reading/inserting/updating from/to C*, but I had
to manually set up the persistence.xml as below and change my
java.sql.Timestamp types in the class to java.util.Date types.


<persistence keyspace="mykeyspace" table="HistoryResult" ttl="2592000">
	<tableOptions>
		comment = 'Test table for Ignite/Cassandra connection'
		AND read_repair_chance = 0.2
	</tableOptions>

	<keyPersistence class="com.gm.model.HistoryResultKey" strategy="POJO">
	    <partitionKey>
	        <field name="vin"/>
	    </partitionKey>
	    <clusterKey>
	        <field name="sessionId" column="session_id"/>
	        <field name="algorithmName" column="algorithm_name"/>
	    </clusterKey>
	</keyPersistence>
	<valuePersistence class="com.gm.model.HistoryResult" strategy="POJO"
serializer="org.apache.ignite.cache.store.cassandra.serializer.KryoSerializer">
        <field name="vin"/>
        <field name="sessionId" column="session_id"/>
	    <field name="sessionTime" column="session_time"/>
        <field name="algorithmName" column="algorithm_name"/>
        <field name="results"/>
	    <field name="analysisTime" column="analysis_time"/>
        <field name="createdDate" column="created_dt"/>
        <field name="createdBy" column="created_by"/>
        <field name="modifiedDate" column="modified_dt"/>
	    <field name="modifiedBy" column="modified_by"/>
	</valuePersistence>
</persistence>




--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Ignite-with-Cassandra-questions-errors-tp9607p9877.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.