All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.amattioli.dominate.morphia.MorphiaStringSpecification Maven / Gradle / Ivy

There is a newer version: 1.0.7
Show newest version
package it.amattioli.dominate.morphia;

import com.google.code.morphia.query.CriteriaContainerImpl;
import com.google.code.morphia.query.FieldEnd;

import it.amattioli.dominate.Entity;
import it.amattioli.dominate.specifications.Assembler;
import it.amattioli.dominate.specifications.StringSpecification;

public class MorphiaStringSpecification > extends StringSpecification {

	public MorphiaStringSpecification() {
		
	}
	
	public MorphiaStringSpecification(String propertyName) {
		super(propertyName);
	}
	
	@Override
	public void itselfAssembleQuery(Assembler assembler) {
		if (wasSet()) {
			MorphiaAssembler mAsm = (MorphiaAssembler)assembler;
			FieldEnd criteriaField = mAsm.getQuery().criteria(getPropertyName());
			CriteriaContainerImpl criteria = null;
			switch(getComparisonType()) {
			case CONTAINS: 
				criteria = criteriaField.containsIgnoreCase(getValue());
				break;
			case EXACT:
				criteria = criteriaField.equal(getValue());
				break;
			case STARTS:
				criteria = criteriaField.startsWithIgnoreCase(getValue());
				break;
			}
			mAsm.addCriteria(criteria);
		}
	}

	@Override
	public boolean itselfSupportsAssembler(Assembler assembler) {
		return assembler instanceof MorphiaAssembler;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy