use of ru.curs.celesta.CelestaException in project celesta by CourseOrchestra.
the class DdlAdaptor method createFk.
/**
* Creates foreign key in the DB.
*
* @param conn DB connection
* @param fk foreign key from score
*/
public void createFk(Connection conn, ForeignKey fk) {
try {
List<String> sqlList = ddlGenerator.createFk(conn, fk);
processSql(conn, sqlList);
} catch (CelestaException e) {
throw new CelestaException("Cannot create foreign key '%s': %s", fk.getConstraintName(), e.getMessage());
}
}
use of ru.curs.celesta.CelestaException in project celesta by CourseOrchestra.
the class DdlAdaptor method createTable.
/**
* Creates a table "from scratch" in the database.
*
* @param conn Connection
* @param te Table for creation (accepts also table in case if such table exists)
*/
public void createTable(Connection conn, TableElement te) {
String sql = ddlGenerator.createTable(te);
try {
processSql(conn, sql);
conn.commit();
List<String> sqlList;
sqlList = ddlGenerator.updateVersioningTrigger(conn, te);
processSql(conn, sqlList);
sqlList = ddlGenerator.afterCreateTable(conn, te);
processSql(conn, sqlList);
} catch (SQLException | CelestaException e) {
throw new CelestaException("Error on creating %s: %s", te.getName(), e.getMessage());
}
}
use of ru.curs.celesta.CelestaException in project celesta by CourseOrchestra.
the class DdlAdaptor method createIndex.
/**
* Creates a table index in the grain.
*
* @param conn DB connection
* @param index index description
*/
public void createIndex(Connection conn, Index index) {
List<String> sqlList = ddlGenerator.createIndex(index);
try {
processSql(conn, sqlList);
conn.commit();
} catch (Exception e) {
throw new CelestaException(String.format("Cannot create index '%s': %s", index.getName(), e.getMessage()), e);
}
}
use of ru.curs.celesta.CelestaException in project celesta by CourseOrchestra.
the class DdlGenerator method createView.
final String createView(View v) {
try {
SQLGenerator gen = getViewSQLGenerator();
StringWriter sw = new StringWriter();
PrintWriter bw = new PrintWriter(sw);
v.createViewScript(bw, gen);
bw.flush();
String sql = sw.toString();
return sql;
} catch (IOException e) {
throw new CelestaException(e);
}
}
use of ru.curs.celesta.CelestaException in project celesta by CourseOrchestra.
the class FirebirdDdlGenerator method updateVersioningTrigger.
@Override
List<String> updateVersioningTrigger(Connection conn, TableElement t) {
List<String> result = new ArrayList<>();
String triggerName = getVersionCheckTriggerName(t);
// First of all, we are about to check if trigger exists
try {
TriggerQuery query = new TriggerQuery().withSchema(t.getGrain().getName()).withName(triggerName).withTableName(t.getName());
boolean triggerExists = this.triggerExists(conn, query);
if (t instanceof VersionedElement) {
VersionedElement ve = (VersionedElement) t;
String sql;
if (ve.isVersioned()) {
if (!triggerExists) {
// CREATE TRIGGER
sql = "CREATE TRIGGER \"" + triggerName + "\" " + "for " + tableString(t.getGrain().getName(), t.getName()) + " BEFORE UPDATE \n" + " AS \n" + " BEGIN \n" + " IF (OLD.\"recversion\" = NEW.\"recversion\")\n" + " THEN NEW.\"recversion\" = NEW.\"recversion\" + 1;" + " ELSE " + " EXCEPTION VERSION_CHECK_ERROR;" + " END";
result.add(sql);
this.rememberTrigger(query);
}
} else {
if (triggerExists) {
// DROP TRIGGER
result.add(dropTrigger(query));
}
}
}
} catch (CelestaException e) {
throw new CelestaException("Could not update version check trigger on %s.%s: %s", t.getGrain().getName(), t.getName(), e.getMessage());
}
return result;
}
Aggregations