Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new database serializer options #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.iridium.iridiumteams.database.types;

import com.iridium.iridiumcore.dependencies.xseries.XBiome;
import com.j256.ormlite.field.FieldType;
import com.j256.ormlite.field.SqlType;
import com.j256.ormlite.field.types.StringType;

import java.sql.SQLException;
import java.util.Optional;

public class XBiomeType extends StringType {

private static final XBiomeType instance = new XBiomeType();

public static XBiomeType getSingleton() {
return instance;
}

protected XBiomeType() {
super(SqlType.STRING, new Class<?>[] { XBiome.class });
}

@Override
public Object sqlArgToJava(FieldType fieldType, Object sqlArg, int columnPos) throws SQLException {
String value = (String) super.sqlArgToJava(fieldType, sqlArg, columnPos);
Optional<XBiome> biome = XBiome.matchXBiome(value);
return biome.orElse(null);
}

@Override
public Object javaToSqlArg(FieldType fieldType, Object object) throws SQLException {
XBiome biome = (XBiome) object;
return super.javaToSqlArg(fieldType, biome.toString());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.iridium.iridiumteams.database.types;

import com.iridium.iridiumcore.dependencies.xseries.XEnchantment;
import com.j256.ormlite.field.FieldType;
import com.j256.ormlite.field.SqlType;
import com.j256.ormlite.field.types.StringType;

import java.sql.SQLException;
import java.util.Optional;

public class XEnchantmentType extends StringType {

private static final XEnchantmentType instance = new XEnchantmentType();

public static XEnchantmentType getSingleton() {
return instance;
}

protected XEnchantmentType() {
super(SqlType.STRING, new Class<?>[] { XEnchantment.class });
}

@Override
public Object sqlArgToJava(FieldType fieldType, Object sqlArg, int columnPos) throws SQLException {
String value = (String) super.sqlArgToJava(fieldType, sqlArg, columnPos);
Optional<XEnchantment> enchantment = XEnchantment.matchXEnchantment(value);
return enchantment.orElse(null);
}

@Override
public Object javaToSqlArg(FieldType fieldType, Object object) throws SQLException {
XEnchantment enchant = (XEnchantment) object;
return super.javaToSqlArg(fieldType, enchant.toString());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.iridium.iridiumteams.database.types;

import com.iridium.iridiumcore.dependencies.xseries.XEntityType;
import com.j256.ormlite.field.FieldType;
import com.j256.ormlite.field.SqlType;
import com.j256.ormlite.field.types.StringType;

import java.sql.SQLException;
import java.util.Optional;

public class XEntityTypeType extends StringType {

private static final XEntityTypeType instance = new XEntityTypeType();

public static XEntityTypeType getSingleton() {
return instance;
}

protected XEntityTypeType() {
super(SqlType.STRING, new Class<?>[] { XEntityType.class });
}

@Override
public Object sqlArgToJava(FieldType fieldType, Object sqlArg, int columnPos) throws SQLException {
String value = (String) super.sqlArgToJava(fieldType, sqlArg, columnPos);
Optional<XEntityType> entity = Optional.ofNullable(XEntityType.of(value));
return entity.orElse(null);
}

@Override
public Object javaToSqlArg(FieldType fieldType, Object object) throws SQLException {
XEntityType entityType = (XEntityType) object;
return super.javaToSqlArg(fieldType, entityType.toString());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.iridium.iridiumteams.database.types;

import com.iridium.iridiumcore.dependencies.xseries.XPotion;
import com.j256.ormlite.field.FieldType;
import com.j256.ormlite.field.SqlType;
import com.j256.ormlite.field.types.StringType;

import java.sql.SQLException;
import java.util.Optional;

public class XPotionType extends StringType {

private static final XPotionType instance = new XPotionType();

public static XPotionType getSingleton() {
return instance;
}

protected XPotionType() {
super(SqlType.STRING, new Class<?>[] { XPotion.class });
}

@Override
public Object sqlArgToJava(FieldType fieldType, Object sqlArg, int columnPos) throws SQLException {
String value = (String) super.sqlArgToJava(fieldType, sqlArg, columnPos);
Optional<XPotion> potion = XPotion.matchXPotion(value);
return potion.orElse(null);
}

@Override
public Object javaToSqlArg(FieldType fieldType, Object object) throws SQLException {
XPotion potion = (XPotion) object;
return super.javaToSqlArg(fieldType, potion.toString());
}

}
Loading