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

org.molgenis.service.TextValueService Maven / Gradle / Ivy

package org.molgenis.service;

import java.util.List;
import java.util.ArrayList;

import org.apache.log4j.Logger;
import org.molgenis.framework.db.Database;
import org.molgenis.framework.db.DatabaseException;
import org.molgenis.framework.db.QueryRule;
import org.molgenis.framework.db.QueryRule.Operator;
import org.molgenis.omx.observ.value.TextValue;
import org.molgenis.model.elements.Entity;
import org.molgenis.util.EntityPager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

@Lazy
@Service
public class TextValueService
{
	private static final Logger logger = Logger.getLogger(TextValueService.class);

	@Autowired
	@Qualifier("database")
	private Database db;

	public TextValue create(TextValue textValue) throws DatabaseException
	{
		logger.debug("creating TextValue");
		db.add(textValue);
		return textValue;
	}

	public TextValue read(Integer id) throws DatabaseException
	{
		logger.debug("retrieving TextValue");
		return db.findById(TextValue.class, id);
	}

	public void update(TextValue textValue) throws DatabaseException
	{
		logger.debug("updating TextValue");
		db.update(textValue);
	}

	public boolean deleteById(Integer id) throws DatabaseException
	{
		logger.debug("deleting TextValue");
		TextValue textValue = db.findById(TextValue.class, id);
		return db.remove(textValue) == 1;
	}
	
	public Iterable readAll() throws DatabaseException
	{
		logger.debug("retrieving all TextValue instances");
		return db.find(TextValue.class);
	}
	
	public EntityPager readAll(int start, int num, List queryRules) throws DatabaseException
	{
		logger.debug("retrieving all TextValue instances");
		if (queryRules == null) queryRules = new ArrayList();
		queryRules.add(new QueryRule(Operator.OFFSET, start));
		queryRules.add(new QueryRule(Operator.LIMIT, num));
		int count = db.count(TextValue.class, queryRules.toArray(new QueryRule[0]));
		List textValueCollection = db.find(TextValue.class, queryRules.toArray(new QueryRule[0]));
		return new EntityPager(start, num, count, textValueCollection);
	}
	
	public Entity getEntity() throws DatabaseException
	{
		return db.getMetaData().getEntity("TextValue");
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy