/** {@inheritDoc} */ @Override protected void alterTableChangePrimaryKey(Statement sth, String tn, String keys) { alterTableDropPrimaryKey(sth, tn); alterTableAddPrimaryKey(sth, tn, keys); }
/** {@inheritDoc} */ @Override protected void alterColumn(Statement sth,String tn, IConfig cfield) { String sql = "ALTER TABLE " + tn + " ALTER COLUMN " + getFieldConfigWithoutExtras(cfield); log().d("alter table",sql); try { sth.execute(sql); } catch (Exception e) { log().i(sql,e); } }
/** {@inheritDoc} */ @Override protected String getFieldConfig(IConfig f) { String type = getDbType(f); String ret = normalizeColumnName(f.getString("name",null)) + " " + type; String def = f.getExtracted("default"); if (def != null) { def = getDbDef(def); ret = ret + " DEFAULT " + def; } boolean notNull = f.getBoolean("notnull", false); if (notNull) ret = ret + " NOT NULL"; else ret = ret + " NULL"; return ret; }
/** * <p>getFieldConfigWithoutExtras.</p> * * @param f a {@link de.mhus.lib.core.directory.ResourceNode} object. * @return a {@link java.lang.String} object. */ protected String getFieldConfigWithoutExtras(IConfig f) { try { String type = getDbType(f); String ret = normalizeColumnName(f.getString("name")) + " " + type; // String def = f.getExtracted("default"); // if (def != null) { // def = getDbDef(def); // ret = ret + " DEFAULT " + def; // } // boolean notNull = f.getBoolean("notnull", false); // if (notNull) // ret = ret + " NOT NULL"; // else // ret = ret + " NULL"; return ret; } catch (MException e) { throw new MRuntimeException(e); } }
/** {@inheritDoc} */ @Override protected void createIndex(Statement sth, boolean unique, boolean btree, String iName, String table, String columns) { iName = table + iName; String sql = "CREATE " + (unique ? "UNIQUE" : "" ) + " INDEX " + iName + (btree ? " USING BTREE" : "") + " ON "+table+ "("+columns+")"; log().t(sql); try { sth.execute(sql.toString()); } catch (Exception e) { log().i(sql,e); } }
public static Dialect findDialect(String driver) { Dialect dialect = null; if (driver != null) { driver = driver.toLowerCase(); if (driver.indexOf("hsqldb") > -1) dialect = new DialectHsqldb(); else if (driver.indexOf("mysql") > -1 || driver.indexOf("mariadb") > -1) dialect = new DialectMysql(); else if (driver.indexOf("postgresql") > -1) dialect = new DialectPostgresql(); } if (dialect == null) { dialect = new DialectDefault(); } return dialect; }
/** {@inheritDoc} */ @Override protected void recreateIndex(Statement sth, boolean unique, boolean btree, String iName, String table, String columns) { iName = table + iName; String sql = "DROP INDEX " + iName; log().t(sql); try { sth.execute(sql.toString()); } catch (Exception e) { log().i(sql,e); } sql = "CREATE " + (unique ? "UNIQUE" : "" ) + " INDEX " + iName + (btree ? " USING BTREE" : "") +" ON "+table+ "("+columns+")"; log().t(sql); try { sth.execute(sql.toString()); } catch (Exception e) { log().i(sql,e); } }