use of com.mysql.cj.result.Row in project ABC by RuiPinto96274.
the class ResultsetRowsCursor method next.
@Override
public Row next() {
if (this.fetchedRows == null && this.currentPositionInEntireResult != BEFORE_START_OF_ROWS) {
throw ExceptionFactory.createException(Messages.getString("ResultSet.Operation_not_allowed_after_ResultSet_closed_144"), this.protocol.getExceptionInterceptor());
}
if (!hasNext()) {
return null;
}
this.currentPositionInEntireResult++;
this.currentPositionInFetchedRows++;
// Catch the forced scroll-passed-end
if (this.fetchedRows != null && this.fetchedRows.size() == 0) {
return null;
}
if ((this.fetchedRows == null) || (this.currentPositionInFetchedRows > (this.fetchedRows.size() - 1))) {
fetchMoreRows();
this.currentPositionInFetchedRows = 0;
}
Row row = this.fetchedRows.get(this.currentPositionInFetchedRows);
row.setMetadata(this.metadata);
return row;
}
use of com.mysql.cj.result.Row in project ABC by RuiPinto96274.
the class ResultsetRowsCursor method fetchMoreRows.
private void fetchMoreRows() {
if (this.lastRowFetched) {
this.fetchedRows = new ArrayList<>(0);
return;
}
synchronized (this.owner.getSyncMutex()) {
try {
boolean oldFirstFetchCompleted = this.firstFetchCompleted;
if (!this.firstFetchCompleted) {
this.firstFetchCompleted = true;
}
int numRowsToFetch = this.owner.getOwnerFetchSize();
if (numRowsToFetch == 0) {
numRowsToFetch = this.owner.getOwningStatementFetchSize();
}
if (numRowsToFetch == Integer.MIN_VALUE) {
// Handle the case where the user used 'old' streaming result sets
numRowsToFetch = 1;
}
if (this.fetchedRows == null) {
this.fetchedRows = new ArrayList<>(numRowsToFetch);
} else {
this.fetchedRows.clear();
}
// TODO this is not the right place for this code, should be in protocol
this.protocol.sendCommand(this.commandBuilder.buildComStmtFetch(this.protocol.getSharedSendPacket(), this.owner.getOwningStatementServerId(), numRowsToFetch), true, 0);
Row row = null;
while ((row = this.protocol.read(ResultsetRow.class, this.rowFactory)) != null) {
this.fetchedRows.add(row);
}
this.currentPositionInFetchedRows = BEFORE_START_OF_ROWS;
if (this.protocol.getServerSession().isLastRowSent()) {
this.lastRowFetched = true;
if (!oldFirstFetchCompleted && this.fetchedRows.size() == 0) {
this.wasEmpty = true;
}
}
} catch (Exception ex) {
throw ExceptionFactory.createException(ex.getMessage(), ex);
}
}
}
use of com.mysql.cj.result.Row in project ABC by RuiPinto96274.
the class SessionImpl method getSchemas.
public List<Schema> getSchemas() {
Function<Row, String> rowToName = r -> r.getValue(0, new StringValueFactory(this.session.getPropertySet()));
Function<Row, Schema> rowToSchema = rowToName.andThen(n -> new SchemaImpl(this.session, this, n));
return this.session.query(this.xbuilder.buildSqlStatement("select schema_name from information_schema.schemata"), null, rowToSchema, Collectors.toList());
}
use of com.mysql.cj.result.Row in project ABC by RuiPinto96274.
the class SqlResultBuilder method addProtocolEntity.
@Override
public boolean addProtocolEntity(ProtocolEntity entity) {
if (entity instanceof Field) {
this.fields.add((Field) entity);
if (!this.isRowResult) {
this.isRowResult = true;
}
this.prevEntity = entity;
return false;
} else if (entity instanceof Notice) {
this.statementExecuteOkBuilder.addProtocolEntity(entity);
return false;
}
if (this.isRowResult && this.metadata == null) {
this.metadata = new DefaultColumnDefinition(this.fields.toArray(new Field[] {}));
}
if (entity instanceof Row) {
this.rows.add(((Row) entity).setMetadata(this.metadata));
} else if (entity instanceof FetchDoneMoreResults) {
this.resultSets.add(new SqlSingleResult(this.metadata, this.defaultTimeZone, new BufferedRowList(this.rows), () -> this.statementExecuteOkBuilder.build(), this.pset));
// clear variables to accept next result set
this.fields = new ArrayList<>();
this.metadata = null;
this.rows = new ArrayList<>();
this.statementExecuteOkBuilder = new StatementExecuteOkBuilder();
} else if (entity instanceof FetchDoneEntity) {
if (this.prevEntity instanceof FetchDoneMoreResults) {
// no-op, possibly bug in xplugin sending FetchDone immediately following FetchDoneMoreResultsets
} else {
this.resultSets.add(new SqlSingleResult(this.metadata, this.defaultTimeZone, new BufferedRowList(this.rows), () -> this.statementExecuteOkBuilder.build(), this.pset));
}
} else if (entity instanceof StatementExecuteOk) {
return true;
}
this.prevEntity = entity;
return false;
}
use of com.mysql.cj.result.Row in project ABC by RuiPinto96274.
the class DatabaseMetaData method getCrossReference.
@Override
public java.sql.ResultSet getCrossReference(final String primaryCatalog, final String primarySchema, final String primaryTable, final String foreignCatalog, final String foreignSchema, final String foreignTable) throws SQLException {
if (primaryTable == null) {
throw SQLError.createSQLException(Messages.getString("DatabaseMetaData.2"), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, getExceptionInterceptor());
}
// String primaryDb = getDatabase(primaryCatalog, primarySchema); // TODO not needed?
String foreignDb = getDatabase(foreignCatalog, foreignSchema);
Field[] fields = createFkMetadataFields();
final ArrayList<Row> tuples = new ArrayList<>();
final Statement stmt = this.conn.getMetadataSafeStatement();
final boolean dbMapsToSchema = DatabaseMetaData.this.databaseTerm.getValue() == DatabaseTerm.SCHEMA;
try {
new IterateBlock<String>(getDatabaseIterator(foreignDb)) {
@Override
void forEach(String dbStr) throws SQLException {
ResultSet fkresults = null;
try {
/*
* Get foreign key information for table
*/
fkresults = extractForeignKeyFromCreateTable(dbStr, null);
String foreignTableWithCase = getTableNameWithCase(foreignTable);
String primaryTableWithCase = getTableNameWithCase(primaryTable);
/*
* Parse imported foreign key information
*/
String dummy;
while (fkresults.next()) {
String tableType = fkresults.getString("Type");
if ((tableType != null) && (tableType.equalsIgnoreCase("innodb") || tableType.equalsIgnoreCase(SUPPORTS_FK))) {
String comment = fkresults.getString("Comment").trim();
if (comment != null) {
StringTokenizer commentTokens = new StringTokenizer(comment, ";", false);
if (commentTokens.hasMoreTokens()) {
dummy = commentTokens.nextToken();
// Skip InnoDB comment
}
while (commentTokens.hasMoreTokens()) {
String keys = commentTokens.nextToken();
LocalAndReferencedColumns parsedInfo = parseTableStatusIntoLocalAndReferencedColumns(keys);
int keySeq = 1;
Iterator<String> referencingColumns = parsedInfo.localColumnsList.iterator();
Iterator<String> referencedColumns = parsedInfo.referencedColumnsList.iterator();
while (referencingColumns.hasNext()) {
String referencingColumn = StringUtils.unQuoteIdentifier(referencingColumns.next(), DatabaseMetaData.this.quotedId);
dummy = fkresults.getString("Name");
if (dummy.compareTo(foreignTableWithCase) != 0) {
continue;
}
// Skip foreign key if it doesn't refer to the right table
if (parsedInfo.referencedTable.compareTo(primaryTableWithCase) != 0) {
continue;
}
// one tuple for each table between parenthesis
byte[][] tuple = new byte[14][];
// PKTABLE_CAT
tuple[0] = dbMapsToSchema ? s2b("def") : s2b(parsedInfo.referencedDatabase);
// PKTABLE_SCHEM
tuple[1] = dbMapsToSchema ? s2b(parsedInfo.referencedDatabase) : null;
// PKTABLE_NAME
tuple[2] = s2b(parsedInfo.referencedTable);
// PKCOLUMN_NAME
tuple[3] = s2b(StringUtils.unQuoteIdentifier(referencedColumns.next(), DatabaseMetaData.this.quotedId));
// FKTABLE_CAT
tuple[4] = dbMapsToSchema ? s2b("def") : s2b(dbStr);
// FKTABLE_SCHEM
tuple[5] = dbMapsToSchema ? s2b(dbStr) : null;
// FKTABLE_NAME
tuple[6] = s2b(dummy);
// FKCOLUMN_NAME
tuple[7] = s2b(referencingColumn);
// KEY_SEQ
tuple[8] = Integer.toString(keySeq).getBytes();
int[] actions = getForeignKeyActions(keys);
// UPDATE_RULE
tuple[9] = Integer.toString(actions[1]).getBytes();
// DELETE_RULE
tuple[10] = Integer.toString(actions[0]).getBytes();
// FK_NAME
tuple[11] = s2b(parsedInfo.constraintName);
// PK_NAME
tuple[12] = null;
// DEFERRABILITY
tuple[13] = Integer.toString(java.sql.DatabaseMetaData.importedKeyNotDeferrable).getBytes();
tuples.add(new ByteArrayRow(tuple, getExceptionInterceptor()));
keySeq++;
}
}
}
}
}
} finally {
if (fkresults != null) {
try {
fkresults.close();
} catch (Exception sqlEx) {
AssertionFailedException.shouldNotHappen(sqlEx);
}
fkresults = null;
}
}
}
}.doForAll();
} finally {
if (stmt != null) {
stmt.close();
}
}
java.sql.ResultSet results = this.resultSetFactory.createFromResultsetRows(ResultSet.CONCUR_READ_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, new ResultsetRowsStatic(tuples, new DefaultColumnDefinition(fields)));
return results;
}
Aggregations