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

com.j256.ormlite.field.types.LongObjectType Maven / Gradle / Ivy

Go to download

Lightweight Object Relational Model (ORM) for persisting objects to SQL databases.

There is a newer version: 6.1
Show newest version
package com.j256.ormlite.field.types;

import java.sql.SQLException;

import com.j256.ormlite.field.FieldType;
import com.j256.ormlite.field.SqlType;
import com.j256.ormlite.support.DatabaseResults;

/**
 * Type that persists a Long object.
 * 
 * @author graywatson
 */
public class LongObjectType extends BaseDataType {

	private static final LongObjectType singleTon = new LongObjectType();

	public static LongObjectType getSingleton() {
		return singleTon;
	}

	private LongObjectType() {
		super(SqlType.LONG, new Class[] { Long.class });
	}

	protected LongObjectType(SqlType sqlType, Class[] classes) {
		super(sqlType, classes);
	}

	@Override
	public Object parseDefaultString(FieldType fieldType, String defaultStr) {
		return Long.parseLong(defaultStr);
	}

	@Override
	public Object resultToSqlArg(FieldType fieldType, DatabaseResults results, int columnPos) throws SQLException {
		return (Long) results.getLong(columnPos);
	}

	@Override
	public Object convertIdNumber(Number number) {
		return (Long) number.longValue();
	}

	@Override
	public boolean isEscapedValue() {
		return false;
	}

	@Override
	public boolean isValidGeneratedType() {
		return true;
	}

	@Override
	public boolean isValidForVersion() {
		return true;
	}

	@Override
	public Object moveToNextValue(Object currentValue) {
		if (currentValue == null) {
			return (Long) 1L;
		} else {
			return ((Long) currentValue) + 1L;
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy