|
| 1 | +package com.softwareverde.database.query; |
| 2 | + |
| 3 | +import com.softwareverde.constable.bytearray.ByteArray; |
| 4 | +import com.softwareverde.database.query.parameter.ParameterFactory; |
| 5 | +import com.softwareverde.database.query.parameter.TypedParameter; |
| 6 | +import com.softwareverde.util.type.identifier.Identifier; |
| 7 | + |
| 8 | +public class ParameterFactoryCore implements ParameterFactory { |
| 9 | + @Override |
| 10 | + public TypedParameter fromObject(final Object object) { |
| 11 | + if (object == null) { return TypedParameter.NULL; } |
| 12 | + |
| 13 | + if (object instanceof Boolean) { |
| 14 | + return new TypedParameter((Boolean) object); |
| 15 | + } |
| 16 | + else if (object instanceof Long) { |
| 17 | + return new TypedParameter((Long) object); |
| 18 | + } |
| 19 | + else if (object instanceof Integer) { |
| 20 | + return new TypedParameter((Integer) object); |
| 21 | + } |
| 22 | + else if (object instanceof Short) { |
| 23 | + return new TypedParameter((Short) object); |
| 24 | + } |
| 25 | + else if (object instanceof Double) { |
| 26 | + return new TypedParameter((Double) object); |
| 27 | + } |
| 28 | + else if (object instanceof Float) { |
| 29 | + return new TypedParameter((Float) object); |
| 30 | + } |
| 31 | + else if (object instanceof byte[]) { |
| 32 | + return new TypedParameter((byte[]) object); |
| 33 | + } |
| 34 | + else if (object instanceof ByteArray) { |
| 35 | + return new TypedParameter(((ByteArray) object).getBytes()); |
| 36 | + } |
| 37 | + else if (object instanceof Identifier) { |
| 38 | + return new TypedParameter(((Identifier) object).longValue()); |
| 39 | + } |
| 40 | + else if (object instanceof TypedParameter) { |
| 41 | + return (TypedParameter) object; |
| 42 | + } |
| 43 | + else if (object instanceof String) { |
| 44 | + return new TypedParameter((String) object); |
| 45 | + } |
| 46 | + |
| 47 | + // Warning is not logged to facilitate class extension. |
| 48 | + // final Class<?> objectClass = object.getClass(); |
| 49 | + // Logger.warn("Unknown Object for TypedParameter Factory: " + objectClass.getName()); |
| 50 | + |
| 51 | + return null; |
| 52 | + } |
| 53 | +} |
0 commit comments