Added Sql-Datatype conversion
-package org.streampipes.connect.adapter.specific.mysql;
-
-
-public class Column {
- /*private static final Map<String, Object> defaultObject;
+/*
+ * Copyright 2019 FZI Forschungszentrum Informatik
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
- static {
- Map<String, Object> aMap = new HashMap<>();
- aMap.put("one", new Integer(3));
- aMap.put("varchar", new String(""));
- defaultObject = Collections.unmodifiableMap(aMap);
- }*/
+package org.streampipes.connect.adapter.specific.mysql;
+import org.streampipes.sdk.utils.Datatypes;
+class Column {
private String name;
- private String type;
- private Object defaul;
+ private Datatypes type;
+ private Object def;
- public Column(String name, String type, Object defaul) {
+ Column(String name, String dataType, String columnType) {
this.name = name;
- this.type = type;
- this.defaul = defaul;
+ switch (dataType) {
+ case "tinyint":
+ case "smallint":
+ case "mediumint":
+ case "int":
+ case "bit":
+ this.type = Datatypes.Integer;
+ def = 0;
+ break;
+ case "bigint":
+ this.type = Datatypes.Long;
+ def = 0L;
+ break;
+ case "float":
+ case "decimal": // Watch out for loss of precision
+ case "double":
+ this.type = Datatypes.Float;
+ def = 0.0f;
+ break;
+ case "text":
+ case "varchar":
+ case "char":
+ this.type = Datatypes.String;
+ def = "";
+ break;
+ default:
+ // date, datetime, time, timestamp, year
+ throw new IllegalArgumentException("Type " + type + " not supported.");
}
- public String getName() {
- return name;
+ if (columnType.equals("tinyint(1)") || columnType.equals("bit(1)")) {
+ this.type = Datatypes.Boolean;
+ def = Boolean.FALSE;
+ }
+ System.out.println("Found column: " + name + ", type: " + this.type + " (sql-type: "
+ + dataType + ", column-tpye: " + columnType + ")");
}
- public String getType() {
- return type;
+ public String getName() {
+ return name;
}
- public Object getDefaul() {
- return defaul;
+ public Object getDefault() {
+ return def;
}
}
