/* * LifeSteal - Yet another lifecore smp core. * Copyright (C) 2022 Arcade Labs * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ package in.arcadelabs.lifesteal.api.datatypes; import com.j256.ormlite.field.FieldType; import com.j256.ormlite.field.SqlType; import com.j256.ormlite.field.types.BaseDataType; import com.j256.ormlite.support.DatabaseResults; import in.arcadelabs.lifesteal.api.profile.LifeState; import java.sql.SQLException; public class LifeStateDataType extends BaseDataType { private static final LifeStateDataType singleton = new LifeStateDataType(); private LifeStateDataType() { super(SqlType.STRING, new Class[]{LifeState.class}); } @Override public Object parseDefaultString(FieldType fieldType, String defaultStr) { return LifeState.valueOf(defaultStr); } @Override public Object resultToSqlArg(FieldType fieldType, DatabaseResults results, int columnPos) throws SQLException { String identifier = results.getString(columnPos); return LifeState.valueOf(identifier); } @Override public Object sqlArgToJava(FieldType fieldType, Object sqlArg, int columnPos) { String identifier = (String) sqlArg; return LifeState.valueOf(identifier); } @Override public Object javaToSqlArg(FieldType fieldType, Object javaObject) { LifeState lifeState = (LifeState) javaObject; return lifeState.identifier(); } public static LifeStateDataType getSingleton() { return singleton; } }