forked from eclipse-vertx/vertx-sql-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
oshai
committed
Oct 3, 2018
1 parent
bb85fd5
commit 1f84bb0
Showing
6 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/io/reactiverse/mysqlclient/MysqlIterator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.reactiverse.mysqlclient; | ||
|
||
import com.github.jasync.sql.db.RowData; | ||
import io.reactiverse.pgclient.PgIterator; | ||
import io.reactiverse.pgclient.Row; | ||
|
||
import java.util.Iterator; | ||
|
||
public class MysqlIterator implements PgIterator { | ||
private final Iterator<RowData> iterator; | ||
|
||
public MysqlIterator(Iterator<RowData> iterator) { | ||
this.iterator = iterator; | ||
} | ||
|
||
@Override | ||
public boolean hasNext() { | ||
return iterator.hasNext(); | ||
} | ||
|
||
@Override | ||
public Row next() { | ||
return new MysqlRow(iterator.next()); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/io/reactiverse/mysqlclient/MysqlQueryResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package io.reactiverse.mysqlclient; | ||
|
||
import com.github.jasync.sql.db.QueryResult; | ||
import io.reactiverse.pgclient.PgResult; | ||
|
||
import java.util.List; | ||
|
||
public class MysqlQueryResult implements PgResult<MysqlRowSet> { | ||
private final QueryResult queryResult; | ||
|
||
public MysqlQueryResult(QueryResult queryResult) { | ||
this.queryResult = queryResult; | ||
} | ||
|
||
@Override | ||
public int rowCount() { | ||
return (int) queryResult.getRowsAffected(); | ||
} | ||
|
||
@Override | ||
public List<String> columnsNames() { | ||
return queryResult.getRows().columnNames(); | ||
} | ||
|
||
@Override | ||
public int size() { | ||
return queryResult.getRows().size(); | ||
} | ||
|
||
@Override | ||
public MysqlRowSet value() { | ||
return new MysqlRowSet(queryResult.getRows()); | ||
} | ||
|
||
@Override | ||
public PgResult<MysqlRowSet> next() { | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package io.reactiverse.mysqlclient; | ||
|
||
import com.github.jasync.sql.db.RowData; | ||
import io.reactiverse.pgclient.Row; | ||
|
||
public class MysqlRow implements Row { | ||
public MysqlRow(RowData row) { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package io.reactiverse.mysqlclient; | ||
|
||
import com.github.jasync.sql.db.ResultSet; | ||
import io.reactiverse.pgclient.PgIterator; | ||
import io.reactiverse.pgclient.PgRowSet; | ||
|
||
import java.util.List; | ||
|
||
public class MysqlRowSet implements PgRowSet { | ||
|
||
|
||
private final com.github.jasync.sql.db.ResultSet resultSet; | ||
|
||
public MysqlRowSet(ResultSet resultSet) { | ||
this.resultSet = resultSet; | ||
} | ||
|
||
@Override | ||
public PgIterator iterator() { | ||
return new MysqlIterator(resultSet.iterator()); | ||
} | ||
|
||
@Override | ||
public int rowCount() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public List<String> columnsNames() { | ||
return resultSet.columnNames(); | ||
} | ||
|
||
@Override | ||
public int size() { | ||
return resultSet.size(); | ||
} | ||
|
||
@Override | ||
public PgRowSet value() { | ||
return this; | ||
} | ||
|
||
@Override | ||
public PgRowSet next() { | ||
return null; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/io/reactiverse/mysqlclient/MyssqlClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.reactiverse.mysqlclient; | ||
|
||
import com.github.jasync.sql.db.Connection; | ||
import io.reactiverse.pgclient.PgClient; | ||
import io.reactiverse.pgclient.PgRowSet; | ||
import io.vertx.core.AsyncResult; | ||
import io.vertx.core.Future; | ||
import io.vertx.core.Handler; | ||
import io.vertx.core.Vertx; | ||
|
||
public class MyssqlClient implements PgClient { | ||
|
||
private final Connection client; | ||
private final Vertx vertx; | ||
|
||
public MyssqlClient(Connection client, Vertx vertx) { | ||
this.client = client; | ||
this.vertx = vertx; | ||
} | ||
|
||
@Override | ||
public PgClient query(String sql, Handler<AsyncResult<PgRowSet>> handler) { | ||
client.sendQuery(sql).whenCompleteAsync((a, t) -> { | ||
if (t == null) { | ||
handler.handle(Future.succeededFuture(new MysqlQueryResult(a).value())); | ||
} else { | ||
handler.handle(Future.failedFuture(t)); | ||
} | ||
},vertx.nettyEventLoopGroup()); | ||
return this; | ||
} | ||
} |