package org.nutz.dao.impl.jdbc.h2;

import org.nutz.dao.DB;
import org.nutz.dao.entity.Entity;
import org.nutz.dao.entity.MappingField;
import org.nutz.dao.impl.entity.macro.SqlFieldMacro;
import org.nutz.dao.impl.jdbc.psql.PsqlJdbcExpert;
import org.nutz.dao.jdbc.JdbcExpertConfigFile;
import org.nutz.dao.sql.Pojo;

public class H2JdbcExpert extends PsqlJdbcExpert {

    public H2JdbcExpert(JdbcExpertConfigFile conf) {
        super(conf);
    }

    public String getDatabaseType() {
        return DB.H2.name();
    }

    public Pojo fetchPojoId(Entity<?> en, MappingField idField) {
        String autoSql = "SELECT IDENTITY() as $field from $view";
        Pojo autoInfo = new SqlFieldMacro(idField, autoSql);
        autoInfo.setEntity(en);
        return autoInfo;
    }
}

@@ -311,16 +311,188 @@
 .Pojo;%0A%0A
+import java.sql.Connection;%0Aimport java.sql.PreparedStatement;%0Aimport java.sql.ResultSet;%0Aimport java.sql.SQLException;%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0A
 public c
@@ -946,11 +946,799 @@
 o;%0A    %7D
+%0A%0A    /**%0A     * %E9%87%8D%E5%86%99%EF%BC%8C %E8%8E%B7%E5%BE%97H2 %E6%95%B0%E6%8D%AE%E5%BA%93%E6%8C%87%E5%AE%9A%E8%A1%A8%E7%9A%84%E7%B4%A2%E5%BC%95%0A     * H2 %E8%AF%AD%E6%B3%95 http://www.h2database.com/html/grammar.html%0A     * @param en%0A     * @param conn%0A     * @return%0A     * @throws SQLException%0A     */%0A    @Override%0A    public List%3CString%3E getIndexNames(Entity%3C?%3E en, Connection conn) throws SQLException %7B%0A        List%3CString%3E names = new ArrayList%3CString%3E();%0A        String showIndexs = %22SELECT * FROM INFORMATION_SCHEMA.INDEXES WHERE TABLE_NAME = ?%22;%0A        PreparedStatement preparedStatement = conn.prepareStatement(showIndexs);%0A        preparedStatement.setString(1, en.getTableName().toUpperCase());%0A        ResultSet rest = preparedStatement.executeQuery();%0A        while (rest.next()) %7B%0A            String index = rest.getString(5);%0A            names.add(index);%0A        %7D%0A        return names;%0A    %7D
 %0A%7D%0A

重写H2下获得表索引方法