use of org.jooq.exception.DataAccessException in project jOOQ by jOOQ.
the class MySQLDatabase method getRoutines0.
@Override
protected List<RoutineDefinition> getRoutines0() throws SQLException {
List<RoutineDefinition> result = new ArrayList<RoutineDefinition>();
try {
create(true).fetchCount(PROC);
} catch (DataAccessException e) {
log.warn("Table unavailable", "The `mysql`.`proc` table is unavailable. Stored procedures cannot be loaded. Check if you have sufficient grants");
return result;
}
Result<Record6<String, String, String, byte[], byte[], ProcType>> records = create().select(Proc.DB, Proc.NAME, Proc.COMMENT, Proc.PARAM_LIST, Proc.RETURNS, Proc.TYPE).from(PROC).where(DB.in(getInputSchemata())).orderBy(DB, Proc.NAME).fetch();
Map<Record, Result<Record6<String, String, String, byte[], byte[], ProcType>>> groups = records.intoGroups(new Field[] { Proc.DB, Proc.NAME });
// procedures and functions with the same signature.
for (Entry<Record, Result<Record6<String, String, String, byte[], byte[], ProcType>>> entry : groups.entrySet()) {
Result<?> overloads = entry.getValue();
for (int i = 0; i < overloads.size(); i++) {
Record record = overloads.get(i);
SchemaDefinition schema = getSchema(record.get(DB));
String name = record.get(Proc.NAME);
String comment = record.get(Proc.COMMENT);
String params = new String(record.get(Proc.PARAM_LIST));
String returns = new String(record.get(Proc.RETURNS));
ProcType type = record.get(Proc.TYPE);
if (overloads.size() > 1) {
result.add(new MySQLRoutineDefinition(schema, name, comment, params, returns, type, "_" + type.name()));
} else {
result.add(new MySQLRoutineDefinition(schema, name, comment, params, returns, type, null));
}
}
}
return result;
}
use of org.jooq.exception.DataAccessException in project jOOQ by jOOQ.
the class LoaderImpl method executeSQL.
private void executeSQL(Iterator<? extends Object[]> iterator) throws SQLException {
Object[] row = null;
BatchBindStep bind = null;
InsertQuery<R> insert = null;
execution: {
rows: while (iterator.hasNext() && ((row = iterator.next()) != null)) {
try {
// [#5858] Work with non String[] types from here on (e.g. after CSV import)
if (row.getClass() != Object[].class)
row = Arrays.copyOf(row, row.length, Object[].class);
// in case LoaderFieldMapper was used.
if (fields == null)
fields0(row);
// [#2741] TODO: This logic will be externalised in new SPI
for (int i = 0; i < row.length; i++) if (StringUtils.equals(nullString, row[i]))
row[i] = null;
else if (i < fields.length && fields[i] != null)
if (fields[i].getType() == byte[].class && row[i] instanceof String)
row[i] = DatatypeConverter.parseBase64Binary((String) row[i]);
// TODO: In batch mode, we can probably optimise this by not creating
// new statements every time, just to convert bind values to their
// appropriate target types. But beware of SQL dialects that tend to
// need very explicit casting of bind values (e.g. Firebird)
processed++;
// in some dialects
if (onDuplicate == ON_DUPLICATE_KEY_IGNORE) {
SelectQuery<R> select = create.selectQuery(table);
for (int i = 0; i < row.length; i++) if (i < fields.length && primaryKey[i])
select.addConditions(getCondition(fields[i], row[i]));
try {
if (create.fetchExists(select)) {
ignored++;
continue rows;
}
} catch (DataAccessException e) {
errors.add(new LoaderErrorImpl(e, row, processed - 1, select));
}
}
buffered++;
if (insert == null)
insert = create.insertQuery(table);
for (int i = 0; i < row.length; i++) if (i < fields.length && fields[i] != null)
addValue0(insert, fields[i], row[i]);
// dialects execute a SELECT and then either an INSERT or UPDATE
if (onDuplicate == ON_DUPLICATE_KEY_UPDATE) {
insert.onDuplicateKeyUpdate(true);
for (int i = 0; i < row.length; i++) if (i < fields.length && fields[i] != null && !primaryKey[i])
addValueForUpdate0(insert, fields[i], row[i]);
} else // Don't do anything. Let the execution fail
if (onDuplicate == ON_DUPLICATE_KEY_ERROR) {
}
try {
if (bulk != BULK_NONE) {
if (bulk == BULK_ALL || processed % bulkAfter != 0) {
insert.newRecord();
continue rows;
}
}
if (batch != BATCH_NONE) {
if (bind == null)
bind = create.batch(insert);
bind.bind(insert.getBindValues().toArray());
insert = null;
if (batch == BATCH_ALL || processed % (bulkAfter * batchAfter) != 0)
continue rows;
}
if (bind != null)
bind.execute();
else if (insert != null)
insert.execute();
stored += buffered;
executed++;
buffered = 0;
bind = null;
insert = null;
if (commit == COMMIT_AFTER)
if ((processed % batchAfter == 0) && ((processed / batchAfter) % commitAfter == 0))
commit();
} catch (DataAccessException e) {
errors.add(new LoaderErrorImpl(e, row, processed - 1, insert));
ignored += buffered;
buffered = 0;
if (onError == ON_ERROR_ABORT)
break execution;
}
} finally {
if (listener != null)
listener.row(result);
}
// rows:
}
// Execute remaining batch
if (buffered != 0) {
try {
if (bind != null)
bind.execute();
if (insert != null)
insert.execute();
stored += buffered;
executed++;
buffered = 0;
} catch (DataAccessException e) {
errors.add(new LoaderErrorImpl(e, row, processed - 1, insert));
ignored += buffered;
buffered = 0;
}
if (onError == ON_ERROR_ABORT)
break execution;
}
// execution:
}
// Rollback on errors in COMMIT_ALL mode
try {
if (commit == COMMIT_ALL) {
if (!errors.isEmpty()) {
stored = 0;
rollback();
} else {
commit();
}
} else // Commit remaining elements in COMMIT_AFTER mode
if (commit == COMMIT_AFTER) {
commit();
}
} catch (DataAccessException e) {
errors.add(new LoaderErrorImpl(e, null, processed - 1, null));
}
}
use of org.jooq.exception.DataAccessException in project jOOQ by jOOQ.
the class DefaultConnectionProvider method setHoldability.
/**
* Convenience method to access {@link Connection#setHoldability(int)}.
*/
public final void setHoldability(int holdability) throws DataAccessException {
try {
log.debug("setting holdability", holdability);
connection.setHoldability(holdability);
} catch (Exception e) {
throw new DataAccessException("Cannot set holdability", e);
}
}
use of org.jooq.exception.DataAccessException in project jOOQ by jOOQ.
the class DefaultConnectionProvider method commit.
/**
* Convenience method to access {@link Connection#commit()}.
*/
public final void commit() throws DataAccessException {
try {
log.debug("commit");
connection.commit();
} catch (Exception e) {
throw new DataAccessException("Cannot commit transaction", e);
}
}
use of org.jooq.exception.DataAccessException in project jOOQ by jOOQ.
the class DefaultConnectionProvider method rollback.
/**
* Convenience method to access {@link Connection#rollback()}.
*/
public final void rollback() throws DataAccessException {
try {
log.debug("rollback");
connection.rollback();
} catch (Exception e) {
throw new DataAccessException("Cannot rollback transaction", e);
}
}
Aggregations