package com.alibaba.cobar.client.sequence.support;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

import org.springframework.beans.factory.InitializingBean;

public class MYSQLPartitionSequenceGenerator extends AbstractDBPartitionSequenceGenerator implements InitializingBean {

	@Override
	public void afterPropertiesSet() throws Exception {
		String sql = "select count(1) from INFORMATION_SCHEMA.TABLES where TABLE_NAME='" + sequenceTable + "' and TABLE_SCHEMA='"+dataSource.getConnection().getSchema()+"'";

		try {
			Connection conn = dataSource.getConnection();
			Statement st = conn.createStatement();
			ResultSet rs = st.executeQuery(sql);
			if (rs.next() && 0 == rs.getInt(1)) {
				sql = "CREATE TABLE " + sequenceTable + "(" 
						+ sequenceColumn + " varchar(128) NOT NULL,"
						+ maxValueColumn + " decimal(10,0) DEFAULT NULL," + modifyTimeColumn + " datetime DEFAULT NULL,"
						+ nodeNameColumn + " varchar(128) DEFAULT NULL," + "PRIMARY KEY (name)" + ")";
				boolean result = st.execute(sql);
				logger.info("create " + sequenceTable + " result:" + result);
			}
		} catch (Exception e) {
			logger.error(e);
		}
	}

}

@@ -375,16 +375,18 @@
 ion %7B%0A%09%09
+//
 String s
@@ -543,16 +543,123 @@
 ()+%22'%22;%0A
+%09%09String sql = %22select count(1) from INFORMATION_SCHEMA.TABLES where TABLE_NAME='%22 + sequenceTable + %22'%22;%0A%0A
 %0A%09%09try %7B

fix a bug