tp.java
· 2.1 KiB · Java
Bruto
/*
* 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 <https://www.gnu.org/licenses/>.
*/
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;
}
}
1 | /* |
2 | * LifeSteal - Yet another lifecore smp core. |
3 | * Copyright (C) 2022 Arcade Labs |
4 | * |
5 | * This program is free software: you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published by |
7 | * the Free Software Foundation, either version 3 of the License, or |
8 | * (at your option) any later version. |
9 | * |
10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU General Public License |
16 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
17 | */ |
18 | |
19 | package in.arcadelabs.lifesteal.api.datatypes; |
20 | |
21 | import com.j256.ormlite.field.FieldType; |
22 | import com.j256.ormlite.field.SqlType; |
23 | import com.j256.ormlite.field.types.BaseDataType; |
24 | import com.j256.ormlite.support.DatabaseResults; |
25 | import in.arcadelabs.lifesteal.api.profile.LifeState; |
26 | |
27 | import java.sql.SQLException; |
28 | |
29 | public class LifeStateDataType extends BaseDataType { |
30 | |
31 | private static final LifeStateDataType singleton = new LifeStateDataType(); |
32 | |
33 | private LifeStateDataType() { |
34 | super(SqlType.STRING, new Class<?>[]{LifeState.class}); |
35 | } |
36 | |
37 | @Override |
38 | public Object parseDefaultString(FieldType fieldType, String defaultStr) { |
39 | return LifeState.valueOf(defaultStr); |
40 | } |
41 | |
42 | @Override |
43 | public Object resultToSqlArg(FieldType fieldType, DatabaseResults results, int columnPos) throws SQLException { |
44 | String identifier = results.getString(columnPos); |
45 | return LifeState.valueOf(identifier); |
46 | } |
47 | |
48 | @Override |
49 | public Object sqlArgToJava(FieldType fieldType, Object sqlArg, int columnPos) { |
50 | String identifier = (String) sqlArg; |
51 | return LifeState.valueOf(identifier); |
52 | } |
53 | |
54 | @Override |
55 | public Object javaToSqlArg(FieldType fieldType, Object javaObject) { |
56 | LifeState lifeState = (LifeState) javaObject; |
57 | return lifeState.identifier(); |
58 | } |
59 | |
60 | public static LifeStateDataType getSingleton() { |
61 | return singleton; |
62 | } |
63 | } |
64 |