*/
protected List<String> createUpdateQueryForCounter(EntityMetadata entityMetadata, Object entity,
Cassandra.Client cassandra_client, List<RelationHolder> rlHolders) {
Map<String, String> builders = new HashMap<String, String>();
CQLTranslator translator = new CQLTranslator();
Object rowId = PropertyAccessorHelper.getId(entity, entityMetadata);
MetamodelImpl metaModel =
(MetamodelImpl) kunderaMetadata.getApplicationMetadata().getMetamodel(entityMetadata.getPersistenceUnit());
EntityType entityType = metaModel.entity(entityMetadata.getEntityClazz());
Set<Attribute> attributes = entityType.getAttributes();
for (Attribute attrib : attributes) {
if (!entityMetadata.getIdAttribute().getName().equals(attrib.getName())
&& !metaModel.isEmbeddable(attrib.getJavaType()) && !attrib.isAssociation()) {
String tableName =
((AbstractAttribute) attrib).getTableName() != null ? ((AbstractAttribute) attrib).getTableName()
: entityMetadata.getTableName();
String queryString = builders.get(tableName);
StringBuilder builder;
if (queryString == null) {
builder = new StringBuilder();
} else {
builder = new StringBuilder(queryString);
}
translator.buildSetClauseForCounters(builder, ((AbstractAttribute) attrib).getJPAColumnName(),
PropertyAccessorHelper.getObject(entity, attrib.getName()));
builders.put(tableName, builder.toString());
}
}
for (RelationHolder rl : rlHolders) {
translator.buildSetClauseForCounters(new StringBuilder(builders.get(entityMetadata.getTableName())),
rl.getRelationName(), rl.getRelationValue());
}
for (String tableName : builders.keySet()) {
StringBuilder builder = new StringBuilder(builders.get(tableName));
String update_Query = translator.UPDATE_QUERY;
update_Query =
StringUtils.replace(update_Query, CQLTranslator.COLUMN_FAMILY,
translator.ensureCase(new StringBuilder(), tableName, false).toString());
// strip last "," clause.
builder.delete(builder.lastIndexOf(CQLTranslator.COMMA_STR), builder.length());
builder.append(CQLTranslator.ADD_WHERE_CLAUSE);