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

com.github.javaclub.cdl.client.util.GroupHintParser Maven / Gradle / Ivy

There is a newer version: 2.3.9
Show newest version
package com.github.javaclub.cdl.client.util;

import com.github.javaclub.cdl.client.group.DBSelector;

public class GroupHintParser {
	public static Integer convertHint2Index(String sql) {
		String groupIndexHint = extractCDLGroupHintString(sql);
		if (null != groupIndexHint && !groupIndexHint.equals("")) {
			String[] piece = groupIndexHint.split(":");
			return Integer.valueOf(piece[1]);
		} else {
			return DBSelector.NOT_EXIST_USER_SPECIFIED_INDEX;
		}
	}

	private static String extractCDLGroupHintString(String sql) {
		return TStringUtil.getBetween(sql.toLowerCase(), "/*+cdl_group({", "})*/");
	}

	public static String removeCdlGroupHint(String sql) {
		String tddlHint = extractCDLGroupHintString(sql);
		if (null == tddlHint || "".endsWith(tddlHint)) {
			return sql;
		}

		sql = TStringUtil.removeBetweenWithSplitor(sql.toLowerCase(), "/*+cdl_group({", "})*/");
		return sql;
	}

	public static void main(String[] args) {
		String sql = "/*+CDL_GROUP({groupIndex:12})*/select * from tab";

		System.out.println(convertHint2Index(sql));
		System.out.println(removeCdlGroupHint(sql));
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy