Added debug

This commit is contained in:
tastybento 2017-10-26 15:58:24 -07:00
parent 522675a823
commit 19b7d24ad4

View File

@ -324,9 +324,9 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
*/ */
@Override @Override
public void saveObject(T instance) throws SQLException, public void saveObject(T instance) throws SQLException,
SecurityException, IllegalArgumentException, SecurityException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InstantiationException, IllegalAccessException,
IntrospectionException, InvocationTargetException, NoSuchMethodException { IntrospectionException, InvocationTargetException, NoSuchMethodException {
Connection connection = null; Connection connection = null;
PreparedStatement preparedStatement = null; PreparedStatement preparedStatement = null;
@ -478,14 +478,14 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
// Serialize // Serialize
value = Util.getStringLocation(((Location)value)); value = Util.getStringLocation(((Location)value));
} else } else
if (clazz.equals(World.class)) { if (clazz.equals(World.class)) {
// Serialize - get the name // Serialize - get the name
value = ((World)value).getName(); value = ((World)value).getName();
} else } else
if (clazz.getSuperclass() != null && clazz.getSuperclass().equals(Enum.class)) { if (clazz.getSuperclass() != null && clazz.getSuperclass().equals(Enum.class)) {
//Custom enums are a child of the Enum class. Just get the names of each one. //Custom enums are a child of the Enum class. Just get the names of each one.
value = ((Enum<?>)value).name(); value = ((Enum<?>)value).name();
} }
if (value == null) { if (value == null) {
// The value could become null from the above checks // The value could become null from the above checks
return "null"; return "null";
@ -512,9 +512,9 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
*/ */
@Override @Override
public List<T> loadObjects() throws SQLException, public List<T> loadObjects() throws SQLException,
SecurityException, IllegalArgumentException, SecurityException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InstantiationException, IllegalAccessException,
IntrospectionException, InvocationTargetException, ClassNotFoundException { IntrospectionException, InvocationTargetException, ClassNotFoundException {
Connection connection = null; Connection connection = null;
Statement statement = null; Statement statement = null;
@ -541,8 +541,8 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
*/ */
@Override @Override
public T loadObject(String uniqueId) throws InstantiationException, public T loadObject(String uniqueId) throws InstantiationException,
IllegalAccessException, IllegalArgumentException, IllegalAccessException, IllegalArgumentException,
InvocationTargetException, IntrospectionException, SQLException, SecurityException, ClassNotFoundException { InvocationTargetException, IntrospectionException, SQLException, SecurityException, ClassNotFoundException {
Connection connection = null; Connection connection = null;
Statement statement = null; Statement statement = null;
ResultSet resultSet = null; ResultSet resultSet = null;
@ -660,7 +660,8 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
((Set<Object>) value).add(deserialize(collectionResultSet.getObject(1),Class.forName(setType.getTypeName()))); ((Set<Object>) value).add(deserialize(collectionResultSet.getObject(1),Class.forName(setType.getTypeName())));
} }
} else if (propertyDescriptor.getPropertyType().equals(ArrayList.class)) { } else if (propertyDescriptor.getPropertyType().equals(ArrayList.class)) {
//plugin.getLogger().info("DEBUG: Adding a list "); if (DEBUG)
plugin.getLogger().info("DEBUG: Adding a list ");
// Loop through the collection resultset // Loop through the collection resultset
// Note that we have no idea what type this is // Note that we have no idea what type this is
List<Type> collectionTypes = Util.getCollectionParameterTypes(method); List<Type> collectionTypes = Util.getCollectionParameterTypes(method);
@ -675,7 +676,8 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
} }
} else if (propertyDescriptor.getPropertyType().equals(Map.class) || } else if (propertyDescriptor.getPropertyType().equals(Map.class) ||
propertyDescriptor.getPropertyType().equals(HashMap.class)) { propertyDescriptor.getPropertyType().equals(HashMap.class)) {
//plugin.getLogger().info("DEBUG: Adding a map "); if (DEBUG)
plugin.getLogger().info("DEBUG: Adding a map ");
// Loop through the collection resultset // Loop through the collection resultset
// Note that we have no idea what type this is // Note that we have no idea what type this is
List<Type> collectionTypes = Util.getCollectionParameterTypes(method); List<Type> collectionTypes = Util.getCollectionParameterTypes(method);
@ -683,16 +685,20 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
Type keyType = collectionTypes.get(0); Type keyType = collectionTypes.get(0);
Type valueType = collectionTypes.get(1); Type valueType = collectionTypes.get(1);
value = new HashMap<Object, Object>(); value = new HashMap<Object, Object>();
//plugin.getLogger().info("DEBUG: collection type argument = " + collectionTypes); if (DEBUG)
plugin.getLogger().info("DEBUG: collection type argument = " + collectionTypes);
while (collectionResultSet.next()) { while (collectionResultSet.next()) {
//plugin.getLogger().info("DEBUG: adding to the map"); if (DEBUG)
plugin.getLogger().info("DEBUG: adding to the map");
//plugin.getLogger().info("DEBUG: collectionResultSet size = " + collectionResultSet.getFetchSize()); //plugin.getLogger().info("DEBUG: collectionResultSet size = " + collectionResultSet.getFetchSize());
// Work through the columns // Work through the columns
// Key // Key
Object key = deserialize(collectionResultSet.getObject(1),Class.forName(keyType.getTypeName())); Object key = deserialize(collectionResultSet.getObject(1),Class.forName(keyType.getTypeName()));
//plugin.getLogger().info("DEBUG: key = " + key); if (DEBUG)
plugin.getLogger().info("DEBUG: key = " + key);
Object mapValue = deserialize(collectionResultSet.getObject(2),Class.forName(valueType.getTypeName())); Object mapValue = deserialize(collectionResultSet.getObject(2),Class.forName(valueType.getTypeName()));
//plugin.getLogger().info("DEBUG: value = " + mapValue); if (DEBUG)
plugin.getLogger().info("DEBUG: value = " + mapValue);
((Map<Object,Object>) value).put(key,mapValue); ((Map<Object,Object>) value).put(key,mapValue);
} }
} else { } else {
@ -701,11 +707,18 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
value = true; value = true;
} }
} else { } else {
//plugin.getLogger().info("DEBUG: regular type"); if (DEBUG)
plugin.getLogger().info("DEBUG: regular type");
value = deserialize(value, propertyDescriptor.getPropertyType()); value = deserialize(value, propertyDescriptor.getPropertyType());
} }
//plugin.getLogger().info("DEBUG: invoking method " + method.getName()); if (DEBUG) {
//plugin.getLogger().info("DEBUG: value class = " + value.getClass().getName()); plugin.getLogger().info("DEBUG: invoking method " + method.getName());
if (value == null) {
plugin.getLogger().info("DEBUG: value = null");
} else {
plugin.getLogger().info("DEBUG: value class = " + value.getClass().getName());
}
}
// Write the value to the class // Write the value to the class
method.invoke(instance, value); method.invoke(instance, value);
} }
@ -724,7 +737,8 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
*/ */
@SuppressWarnings({ "unchecked", "rawtypes" }) @SuppressWarnings({ "unchecked", "rawtypes" })
private Object deserialize(Object value, Class<? extends Object> clazz) { private Object deserialize(Object value, Class<? extends Object> clazz) {
//plugin.getLogger().info("DEBUG: deserialize - class is " + clazz.getTypeName()); if (DEBUG)
plugin.getLogger().info("DEBUG: deserialize - class is " + clazz.getTypeName());
if (value instanceof String && value.equals("null")) { if (value instanceof String && value.equals("null")) {
// If the value is null as a string, return null // If the value is null as a string, return null
return null; return null;