All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.smartloli.common.map.JSqlMapData Maven / Gradle / Ivy

Go to download

Intermediate DataSet use sql to query , Through the jsql-client , we can use sql to get results .

There is a newer version: 1.0.2
Show newest version
/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.
 */
package org.smartloli.common.map;

import java.sql.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.apache.calcite.sql.type.SqlTypeName;

import com.alibaba.fastjson.JSONObject;

/**
 * Created by Mar 25, 2016
 *
 * @author smartloli
 * 
 */
public class JSqlMapData {

	public static final Map MAP = new HashMap();
	public static Map SQLTYPE_MAPPING = new HashMap();
	@SuppressWarnings("rawtypes")
	public static Map JAVATYPE_MAPPING = new HashMap();

	static {
		loadDatabaseType();
	}

	private static void loadDatabaseType() {
		SQLTYPE_MAPPING.put("char", SqlTypeName.CHAR);
		JAVATYPE_MAPPING.put("char", Character.class);
		SQLTYPE_MAPPING.put("varchar", SqlTypeName.VARCHAR);
		JAVATYPE_MAPPING.put("varchar", String.class);
		SQLTYPE_MAPPING.put("boolean", SqlTypeName.BOOLEAN);
		SQLTYPE_MAPPING.put("integer", SqlTypeName.INTEGER);
		JAVATYPE_MAPPING.put("integer", Integer.class);
		SQLTYPE_MAPPING.put("tinyint", SqlTypeName.TINYINT);
		SQLTYPE_MAPPING.put("smallint", SqlTypeName.SMALLINT);
		SQLTYPE_MAPPING.put("bigint", SqlTypeName.BIGINT);
		SQLTYPE_MAPPING.put("decimal", SqlTypeName.DECIMAL);
		SQLTYPE_MAPPING.put("numeric", SqlTypeName.DECIMAL);
		SQLTYPE_MAPPING.put("float", SqlTypeName.FLOAT);
		SQLTYPE_MAPPING.put("real", SqlTypeName.REAL);
		SQLTYPE_MAPPING.put("double", SqlTypeName.DOUBLE);
		SQLTYPE_MAPPING.put("date", SqlTypeName.DATE);
		JAVATYPE_MAPPING.put("date", Date.class);
		SQLTYPE_MAPPING.put("time", SqlTypeName.TIME);
		SQLTYPE_MAPPING.put("timestamp", SqlTypeName.TIMESTAMP);
		SQLTYPE_MAPPING.put("any", SqlTypeName.ANY);
	}

	public static void loadSchema(JSONObject cols, String tableName, List> datas) {
		Database db = new Database();
		Table table = new Table();
		table.tableName = tableName;
		for (String key : cols.keySet()) {
			Column _col = new Column();
			_col.name = key;
			_col.type = cols.getString(key);
			table.columns.add(_col);
		}
		table.data = datas;
		db.tables.add(table);
		MAP.put("db", db);
	}

	public static class Database {
		public List tables = new LinkedList
(); } public static class Table { public String tableName; public List columns = new LinkedList(); public List> data = new LinkedList>(); } public static class Column { public String name; public String type; } }