IGNITE-2447: Moved all ODBC classes into org.apache.ignite.internal.processors.odbc package.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/2a756311 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/2a756311 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/2a756311 Branch: refs/heads/ignite-1786 Commit: 2a756311134e971fbfbc671f2b53090cae1085ad Parents: 9baf266 Author: isapego <[email protected]> Authored: Mon Jan 25 18:23:20 2016 +0300 Committer: isapego <[email protected]> Committed: Mon Jan 25 18:23:20 2016 +0300 ---------------------------------------------------------------------- .../processors/odbc/OdbcCommandHandler.java | 4 +- .../internal/processors/odbc/OdbcParser.java | 341 ++++++++++++++++++ .../internal/processors/odbc/OdbcProcessor.java | 3 - .../processors/odbc/OdbcProtocolHandler.java | 2 - .../processors/odbc/OdbcQueryCloseRequest.java | 47 +++ .../processors/odbc/OdbcQueryCloseResult.java | 39 +++ .../odbc/OdbcQueryExecuteRequest.java | 85 +++++ .../processors/odbc/OdbcQueryExecuteResult.java | 55 +++ .../processors/odbc/OdbcQueryFetchRequest.java | 66 ++++ .../processors/odbc/OdbcQueryFetchResult.java | 75 ++++ .../odbc/OdbcQueryGetColumnsMetaRequest.java | 84 +++++ .../odbc/OdbcQueryGetColumnsMetaResult.java | 43 +++ .../odbc/OdbcQueryGetTablesMetaRequest.java | 105 ++++++ .../odbc/OdbcQueryGetTablesMetaResult.java | 43 +++ .../internal/processors/odbc/OdbcRequest.java | 61 ++++ .../internal/processors/odbc/OdbcResponse.java | 107 ++++++ .../processors/odbc/OdbcTcpNioListener.java | 99 ++++++ .../internal/processors/odbc/OdbcTcpServer.java | 189 ++++++++++ .../processors/odbc/protocol/OdbcParser.java | 345 ------------------- .../odbc/protocol/OdbcTcpNioListener.java | 102 ------ .../processors/odbc/protocol/OdbcTcpServer.java | 191 ---------- .../odbc/request/OdbcQueryCloseRequest.java | 47 --- .../odbc/request/OdbcQueryExecuteRequest.java | 85 ----- .../odbc/request/OdbcQueryFetchRequest.java | 66 ---- .../request/OdbcQueryGetColumnsMetaRequest.java | 84 ----- .../request/OdbcQueryGetTablesMetaRequest.java | 105 ------ .../processors/odbc/request/OdbcRequest.java | 61 ---- .../odbc/response/OdbcQueryCloseResult.java | 39 --- .../odbc/response/OdbcQueryExecuteResult.java | 55 --- .../odbc/response/OdbcQueryFetchResult.java | 75 ---- .../response/OdbcQueryGetColumnsMetaResult.java | 43 --- .../response/OdbcQueryGetTablesMetaResult.java | 43 --- .../processors/odbc/response/OdbcResponse.java | 107 ------ 33 files changed, 1440 insertions(+), 1456 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/2a756311/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcCommandHandler.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcCommandHandler.java index d8a05f7..9e56888 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcCommandHandler.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcCommandHandler.java @@ -22,8 +22,6 @@ import org.apache.ignite.cache.query.QueryCursor; import org.apache.ignite.cache.query.SqlFieldsQuery; import org.apache.ignite.internal.GridKernalContext; import org.apache.ignite.internal.processors.cache.QueryCursorImpl; -import org.apache.ignite.internal.processors.odbc.request.*; -import org.apache.ignite.internal.processors.odbc.response.*; import org.apache.ignite.internal.processors.query.GridQueryFieldMetadata; import org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor; import org.apache.ignite.lang.IgniteBiTuple; @@ -32,7 +30,7 @@ import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicLong; -import static org.apache.ignite.internal.processors.odbc.request.OdbcRequest.*; +import static org.apache.ignite.internal.processors.odbc.OdbcRequest.*; /** * SQL query handler. http://git-wip-us.apache.org/repos/asf/ignite/blob/2a756311/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcParser.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcParser.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcParser.java new file mode 100644 index 0000000..ead6d3b --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcParser.java @@ -0,0 +1,341 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.ignite.internal.processors.odbc; + +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.GridKernalContext; +import org.apache.ignite.internal.binary.*; +import org.apache.ignite.internal.binary.streams.BinaryHeapInputStream; +import org.apache.ignite.internal.binary.streams.BinaryHeapOutputStream; +import org.apache.ignite.internal.binary.streams.BinaryInputStream; +import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl; +import org.apache.ignite.internal.util.nio.GridNioParser; +import org.apache.ignite.internal.util.nio.GridNioSession; +import org.jetbrains.annotations.Nullable; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.Collection; + + +/** + * ODBC protocol parser. + */ +public class OdbcParser implements GridNioParser { + /** Initial output stream capacity. */ + private static final int INIT_CAP = 1024; + + /** Length in bytes of the remaining message part. */ + int leftToReceive = 0; + + /** Already received bytes of current message. */ + ByteBuffer currentMessage = null; + + /** Context. */ + protected final GridKernalContext ctx; + + /** Marshaller. */ + private final GridBinaryMarshaller marsh; + + OdbcParser(GridKernalContext context) { + ctx = context; + + CacheObjectBinaryProcessorImpl cacheObjProc = (CacheObjectBinaryProcessorImpl)ctx.cacheObjects(); + + marsh = cacheObjProc.marshaller(); + } + + /** + * Process data chunk and try to construct new message using stored and freshly received data. + * @param buf Fresh data buffer. + * @return Instance of the {@link BinaryReaderExImpl} positioned to read from the beginning of the message on + * success and null otherwise. + */ + private BinaryRawReaderEx tryConstructMessage(ByteBuffer buf) { + if (leftToReceive != 0) { + // Still receiving message + int toConsume = Math.min(leftToReceive, buf.remaining()); + + currentMessage.put(buf.array(), buf.arrayOffset(), toConsume); + leftToReceive -= toConsume; + + buf.position(buf.position() + toConsume); + + if (leftToReceive != 0) + return null; + + BinaryInputStream stream = new BinaryHeapInputStream(currentMessage.array()); + + BinaryReaderExImpl reader = new BinaryReaderExImpl(null, stream, null); + + currentMessage = null; + + return reader; + } + + // Receiving new message + // Getting message length. It's in the first four bytes of the message. + BinaryInputStream stream = new BinaryHeapInputStream(buf.array()); + + BinaryReaderExImpl reader = new BinaryReaderExImpl(null, stream, null); + + int messageLen = reader.readInt(); + buf.getInt(); + + int remaining = buf.remaining(); + + if (messageLen > remaining) { + leftToReceive = messageLen - remaining; + + currentMessage = ByteBuffer.allocate(messageLen); + currentMessage.put(buf); + + return null; + } + + buf.position(buf.position() + messageLen); + + return reader; + } + + /** {@inheritDoc} */ + @Nullable @Override public OdbcRequest decode(GridNioSession ses, ByteBuffer buf) throws IOException, + IgniteCheckedException { + BinaryRawReaderEx messageReader = tryConstructMessage(buf); + + return messageReader == null ? null : readRequest(ses, messageReader); + } + + /** {@inheritDoc} */ + @Override public ByteBuffer encode(GridNioSession ses, Object msg) throws IOException, IgniteCheckedException { + assert msg != null; + assert msg instanceof OdbcResponse; + + System.out.println("Encoding query processing result"); + + BinaryRawWriterEx writer = marsh.writer(new BinaryHeapOutputStream(INIT_CAP)); + + // Reserving space for the message length. + int msgLenPos = writer.reserveInt(); + + writeResponse(ses, writer, (OdbcResponse)msg); + + int msgLenWithHdr = writer.out().position() - msgLenPos; + + int msgLen = msgLenWithHdr - 4; + + writer.writeInt(msgLenPos, msgLen); + + ByteBuffer buf = ByteBuffer.allocate(msgLenWithHdr); + + buf.put(writer.out().array(), msgLenPos, msgLenWithHdr); + + buf.flip(); + + return buf; + } + + /** + * Read ODBC request from the raw data using provided {@link BinaryReaderExImpl} instance. + * @param ses Current session. + * @param reader Reader positioned to read the request. + * @return Instance of the {@link OdbcRequest}. + * @throws IOException if the type of the request is unknown to the parser. + */ + private OdbcRequest readRequest(GridNioSession ses, BinaryRawReaderEx reader) throws IOException { + OdbcRequest res; + + byte cmd = reader.readByte(); + + switch (cmd) { + case OdbcRequest.EXECUTE_SQL_QUERY: { + String cache = reader.readString(); + String sql = reader.readString(); + int argsNum = reader.readInt(); + + System.out.println("Message EXECUTE_SQL_QUERY:"); + System.out.println("cache: " + cache); + System.out.println("query: " + sql); + System.out.println("argsNum: " + argsNum); + + Object[] params = new Object[argsNum]; + + for (int i = 0; i < argsNum; ++i) + params[i] = reader.readObjectDetached(); + + res = new OdbcQueryExecuteRequest(cache, sql, params); + break; + } + + case OdbcRequest.FETCH_SQL_QUERY: { + long queryId = reader.readLong(); + int pageSize = reader.readInt(); + + System.out.println("Message FETCH_SQL_QUERY:"); + System.out.println("queryId: " + queryId); + System.out.println("pageSize: " + pageSize); + + res = new OdbcQueryFetchRequest(queryId, pageSize); + break; + } + + case OdbcRequest.CLOSE_SQL_QUERY: { + long queryId = reader.readLong(); + + System.out.println("Message CLOSE_SQL_QUERY:"); + System.out.println("queryId: " + queryId); + + res = new OdbcQueryCloseRequest(queryId); + break; + } + + case OdbcRequest.GET_COLUMNS_META: { + String cache = reader.readString(); + String table = reader.readString(); + String column = reader.readString(); + + System.out.println("Message GET_COLUMNS_META:"); + System.out.println("cache: " + cache); + System.out.println("table: " + table); + System.out.println("column: " + column); + + res = new OdbcQueryGetColumnsMetaRequest(cache, table, column); + break; + } + + case OdbcRequest.GET_TABLES_META: { + String catalog = reader.readString(); + String schema = reader.readString(); + String table = reader.readString(); + String tableType = reader.readString(); + + System.out.println("Message GET_COLUMNS_META:"); + System.out.println("catalog: " + catalog); + System.out.println("schema: " + schema); + System.out.println("table: " + table); + System.out.println("tableType: " + tableType); + + res = new OdbcQueryGetTablesMetaRequest(catalog, schema, table, tableType); + break; + } + + default: + throw new IOException("Failed to parse incoming packet (unknown command type) [ses=" + ses + + ", cmd=[" + Byte.toString(cmd) + ']'); + } + + return res; + } + + /** + * Write ODBC response using provided {@link BinaryRawWriterEx} instance. + * @param ses Current session. + * @param writer Writer. + * @param rsp ODBC response that should be written. + * @throws IOException if the type of the response is unknown to the parser. + */ + private void writeResponse(GridNioSession ses, BinaryRawWriterEx writer, OdbcResponse rsp) throws IOException { + // Writing status + writer.writeByte((byte)rsp.getSuccessStatus()); + + if (rsp.getSuccessStatus() != OdbcResponse.STATUS_SUCCESS) { + writer.writeString(rsp.getError()); + + return; + } + + Object res0 = rsp.getResponse(); + + if (res0 instanceof OdbcQueryExecuteResult) { + OdbcQueryExecuteResult res = (OdbcQueryExecuteResult) res0; + + System.out.println("Resulting query ID: " + res.getQueryId()); + + writer.writeLong(res.getQueryId()); + + Collection<OdbcColumnMeta> metas = res.getColumnsMetadata(); + + assert metas != null; + + writer.writeInt(metas.size()); + + for (OdbcColumnMeta meta : metas) + meta.writeBinary(writer, marsh.context()); + + } else if (res0 instanceof OdbcQueryFetchResult) { + OdbcQueryFetchResult res = (OdbcQueryFetchResult) res0; + + System.out.println("Resulting query ID: " + res.getQueryId()); + + writer.writeLong(res.getQueryId()); + + Collection<?> items0 = res.getItems(); + + assert items0 != null; + + Collection<Collection<Object>> items = (Collection<Collection<Object>>)items0; + + writer.writeBoolean(res.getLast()); + + writer.writeInt(items.size()); + + for (Collection<Object> row : items) { + if (row != null) { + writer.writeInt(row.size()); + + for (Object obj : row) { + if (obj != null) + writer.writeObjectDetached(obj); + } + } + } + } else if (res0 instanceof OdbcQueryCloseResult) { + OdbcQueryCloseResult res = (OdbcQueryCloseResult) res0; + + System.out.println("Resulting query ID: " + res.getQueryId()); + + writer.writeLong(res.getQueryId()); + + } else if (res0 instanceof OdbcQueryGetColumnsMetaResult) { + OdbcQueryGetColumnsMetaResult res = (OdbcQueryGetColumnsMetaResult) res0; + + Collection<OdbcColumnMeta> columnsMeta = res.getMeta(); + + assert columnsMeta != null; + + writer.writeInt(columnsMeta.size()); + + for (OdbcColumnMeta columnMeta : columnsMeta) + columnMeta.writeBinary(writer, marsh.context()); + + } else if (res0 instanceof OdbcQueryGetTablesMetaResult) { + OdbcQueryGetTablesMetaResult res = (OdbcQueryGetTablesMetaResult) res0; + + Collection<OdbcTableMeta> tablesMeta = res.getMeta(); + + assert tablesMeta != null; + + writer.writeInt(tablesMeta.size()); + + for (OdbcTableMeta tableMeta : tablesMeta) + tableMeta.writeBinary(writer); + + } else { + throw new IOException("Failed to serialize response packet (unknown response type) [ses=" + ses + "]"); + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/2a756311/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcProcessor.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcProcessor.java index a3f0b94..91b24a4 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcProcessor.java @@ -21,9 +21,6 @@ import org.apache.ignite.internal.GridKernalContext; import org.apache.ignite.internal.IgniteInternalFuture; import org.apache.ignite.internal.binary.BinaryMarshaller; import org.apache.ignite.internal.processors.GridProcessorAdapter; -import org.apache.ignite.internal.processors.odbc.protocol.OdbcTcpServer; -import org.apache.ignite.internal.processors.odbc.request.OdbcRequest; -import org.apache.ignite.internal.processors.odbc.response.OdbcResponse; import org.apache.ignite.internal.util.GridSpinReadWriteLock; import org.apache.ignite.internal.util.future.GridFinishedFuture; import org.apache.ignite.marshaller.Marshaller; http://git-wip-us.apache.org/repos/asf/ignite/blob/2a756311/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcProtocolHandler.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcProtocolHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcProtocolHandler.java index 9af002d..e1957d7 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcProtocolHandler.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcProtocolHandler.java @@ -18,8 +18,6 @@ package org.apache.ignite.internal.processors.odbc; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.IgniteInternalFuture; -import org.apache.ignite.internal.processors.odbc.request.OdbcRequest; -import org.apache.ignite.internal.processors.odbc.response.OdbcResponse; /** * ODBC command protocol handler. http://git-wip-us.apache.org/repos/asf/ignite/blob/2a756311/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryCloseRequest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryCloseRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryCloseRequest.java new file mode 100644 index 0000000..e9b5698 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryCloseRequest.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.ignite.internal.processors.odbc; + +/** + * ODBC query close request. + */ +public class OdbcQueryCloseRequest extends OdbcRequest { + /** Query ID. */ + private long queryId; + + /** + * @param queryId Query ID. + */ + public OdbcQueryCloseRequest(long queryId) { + super(CLOSE_SQL_QUERY); + this.queryId = queryId; + } + + /** + * @param queryId Query ID. + */ + public void cacheName(long queryId) { + this.queryId = queryId; + } + + /** + * @return Query ID. + */ + public long queryId() { + return queryId; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/2a756311/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryCloseResult.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryCloseResult.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryCloseResult.java new file mode 100644 index 0000000..cbc23c8 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryCloseResult.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.ignite.internal.processors.odbc; + +/** + * Query result. + */ +public class OdbcQueryCloseResult { + /** Query ID. */ + private long queryId; + + /** + * @param queryId Query ID. + */ + public OdbcQueryCloseResult(long queryId){ + this.queryId = queryId; + } + + /** + * @return Query ID. + */ + public long getQueryId() { + return queryId; + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/2a756311/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryExecuteRequest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryExecuteRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryExecuteRequest.java new file mode 100644 index 0000000..4628b52 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryExecuteRequest.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.ignite.internal.processors.odbc; + +/** + * ODBC query execute request. + */ +public class OdbcQueryExecuteRequest extends OdbcRequest { + /** Cache name. */ + private String cacheName; + + /** Sql query. */ + private String sqlQry; + + /** Sql query arguments. */ + private Object[] args; + + /** + * @param cacheName Cache name. + * @param sqlQry SQL query. + * @param args Arguments list. + */ + public OdbcQueryExecuteRequest(String cacheName, String sqlQry, Object[] args) { + super(EXECUTE_SQL_QUERY); + this.cacheName = cacheName; + this.sqlQry = sqlQry; + this.args = args; + } + + /** + * @param sqlQry Sql query. + */ + public void sqlQuery(String sqlQry) { + this.sqlQry = sqlQry; + } + + /** + * @return Sql query. + */ + public String sqlQuery() { + return sqlQry; + } + + /** + * @param args Sql query arguments. + */ + public void arguments(Object[] args) { + this.args = args; + } + + /** + * @return Sql query arguments. + */ + public Object[] arguments() { + return args; + } + + /** + * @param cacheName Cache name. + */ + public void cacheName(String cacheName) { + this.cacheName = cacheName; + } + + /** + * @return Cache name. + */ + public String cacheName() { + return cacheName; + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/2a756311/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryExecuteResult.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryExecuteResult.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryExecuteResult.java new file mode 100644 index 0000000..a4dec54 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryExecuteResult.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.ignite.internal.processors.odbc; + +import org.apache.ignite.internal.processors.odbc.OdbcColumnMeta; + +import java.util.Collection; + +/** + * Query execute result. + */ +public class OdbcQueryExecuteResult { + /** Query ID. */ + private long queryId; + + /** Fields metadata. */ + private Collection<OdbcColumnMeta> columnsMeta; + + /** + * @param queryId Query ID. + * @param columnsMeta Columns metadata. + */ + public OdbcQueryExecuteResult(long queryId, Collection<OdbcColumnMeta> columnsMeta){ + this.queryId = queryId; + this.columnsMeta = columnsMeta; + } + + /** + * @return Query ID. + */ + public long getQueryId() { + return queryId; + } + + /** + * @return Columns metadata. + */ + public Collection<OdbcColumnMeta> getColumnsMetadata() { + return columnsMeta; + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/2a756311/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryFetchRequest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryFetchRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryFetchRequest.java new file mode 100644 index 0000000..7609649 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryFetchRequest.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.ignite.internal.processors.odbc; + +/** + * ODBC query fetch request. + */ +public class OdbcQueryFetchRequest extends OdbcRequest { + /** Query ID. */ + private long queryId; + + /** Page size - maximum number of rows to return. */ + private Integer pageSize; + + /** + * @param queryId Query ID. + * @param pageSize Page size. + */ + public OdbcQueryFetchRequest(long queryId, int pageSize) { + super(FETCH_SQL_QUERY); + this.queryId = queryId; + this.pageSize = pageSize; + } + + /** + * @param pageSize Page size. + */ + public void pageSize(Integer pageSize) { + this.pageSize = pageSize; + } + + /** + * @return Page size. + */ + public int pageSize() { + return pageSize; + } + + /** + * @param queryId Query ID. + */ + public void cacheName(long queryId) { + this.queryId = queryId; + } + + /** + * @return Query ID. + */ + public long queryId() { + return queryId; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/2a756311/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryFetchResult.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryFetchResult.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryFetchResult.java new file mode 100644 index 0000000..b103914 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryFetchResult.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.ignite.internal.processors.odbc; + +import java.util.Collection; + +/** + * Query fetch result. + */ +public class OdbcQueryFetchResult { + /** Query ID. */ + private long queryId; + + /** Query result rows. */ + private Collection<?> items = null; + + /** Flag indicating the query has no unfetched results. */ + private boolean last = false; + + /** + * @param queryId Query ID. + */ + public OdbcQueryFetchResult(long queryId){ + this.queryId = queryId; + } + + /** + * @return Query ID. + */ + public long getQueryId() { + return queryId; + } + + /** + * @param items Query result rows. + */ + public void setItems(Collection<?> items) { + this.items = items; + } + + /** + * @return Query result rows. + */ + public Collection<?> getItems() { + return items; + } + + /** + * @param last Flag indicating the query has no unfetched results. + */ + public void setLast(boolean last) { + this.last = last; + } + + /** + * @return Flag indicating the query has no unfetched results. + */ + public boolean getLast() { + return last; + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/2a756311/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryGetColumnsMetaRequest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryGetColumnsMetaRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryGetColumnsMetaRequest.java new file mode 100644 index 0000000..b0f1ba6 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryGetColumnsMetaRequest.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.ignite.internal.processors.odbc; + +/** + * ODBC query get columns meta request. + */ +public class OdbcQueryGetColumnsMetaRequest extends OdbcRequest { + /** Cache name. */ + private String cacheName; + + /** Table name. */ + private String tableName; + + /** Column name. */ + private String columnName; + + /** + * @param cacheName Cache name. + */ + public OdbcQueryGetColumnsMetaRequest(String cacheName, String tableName, String columnName) { + super(GET_COLUMNS_META); + + this.cacheName = cacheName; + this.tableName = tableName; + this.columnName = columnName; + } + + /** + * @param cacheName Cache name. + */ + public void cacheName(String cacheName) { + this.cacheName = cacheName; + } + + /** + * @return Cache name. + */ + public String cacheName() { + return cacheName; + } + + /** + * @param tableName Table name. + */ + public void tableName(String tableName) { + this.tableName = tableName; + } + + /** + * @return Table name. + */ + public String tableName() { + return tableName; + } + + /** + * @param columnName Column name. + */ + public void columnName(String columnName) { + this.columnName = columnName; + } + + /** + * @return Column name. + */ + public String columnName() { + return columnName; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/2a756311/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryGetColumnsMetaResult.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryGetColumnsMetaResult.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryGetColumnsMetaResult.java new file mode 100644 index 0000000..f00176c --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryGetColumnsMetaResult.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.ignite.internal.processors.odbc; + +import org.apache.ignite.internal.processors.odbc.OdbcColumnMeta; + +import java.util.Collection; + +/** + * Query get columns meta result. + */ +public class OdbcQueryGetColumnsMetaResult { + /** Query result rows. */ + private Collection<OdbcColumnMeta> meta; + + /** + * @param meta Column metadata. + */ + public OdbcQueryGetColumnsMetaResult(Collection<OdbcColumnMeta> meta) { + this.meta = meta; + } + + /** + * @return Query result rows. + */ + public Collection<OdbcColumnMeta> getMeta() { + return meta; + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/2a756311/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryGetTablesMetaRequest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryGetTablesMetaRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryGetTablesMetaRequest.java new file mode 100644 index 0000000..7d8194c --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryGetTablesMetaRequest.java @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.ignite.internal.processors.odbc; + +/** + * ODBC query get tables meta request. + */ +public class OdbcQueryGetTablesMetaRequest extends OdbcRequest { + /** Catalog search pattern. */ + private String catalog; + + /** Schema search pattern. */ + private String schema; + + /** Table search pattern. */ + private String table; + + /** Table type search pattern. */ + private String tableType; + + /** + * @param catalog Catalog search pattern. + * @param schema Schema search pattern. + * @param table Table search pattern. + * @param tableType Table type search pattern. + */ + public OdbcQueryGetTablesMetaRequest(String catalog, String schema, String table, String tableType) { + super(GET_TABLES_META); + + this.catalog = catalog; + this.schema = schema; + this.table = table; + this.tableType = tableType; + } + + /** + * @param catalog Catalog search pattern. + */ + public void catalog(String catalog) { + this.catalog = catalog; + } + + /** + * @return catalog search pattern. + */ + public String catalog() { + return catalog; + } + + /** + * @param schema Schema search pattern. + */ + public void schema(String schema) { + this.schema = schema; + } + + /** + * @return Schema search pattern. + */ + public String schema() { + return schema; + } + + /** + * @param table Schema search pattern. + */ + public void table(String table) { + this.table = table; + } + + /** + * @return Table search pattern. + */ + public String table() { + return table; + } + + /** + * @param tableType Table type search pattern. + */ + public void tableType(String tableType) { + this.tableType = tableType; + } + + /** + * @return Table type search pattern. + */ + public String tableType() { + return tableType; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/2a756311/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryGetTablesMetaResult.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryGetTablesMetaResult.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryGetTablesMetaResult.java new file mode 100644 index 0000000..e737772 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcQueryGetTablesMetaResult.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.ignite.internal.processors.odbc; + +import org.apache.ignite.internal.processors.odbc.OdbcTableMeta; + +import java.util.Collection; + +/** + * Query get columns meta result. + */ +public class OdbcQueryGetTablesMetaResult { + /** Query result rows. */ + private Collection<OdbcTableMeta> meta; + + /** + * @param meta Column metadata. + */ + public OdbcQueryGetTablesMetaResult(Collection<OdbcTableMeta> meta) { + this.meta = meta; + } + + /** + * @return Query result rows. + */ + public Collection<OdbcTableMeta> getMeta() { + return meta; + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/2a756311/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcRequest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcRequest.java new file mode 100644 index 0000000..1e8aecc --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcRequest.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.ignite.internal.processors.odbc; + +/** + * ODBC command request. + */ +public class OdbcRequest { + /** Execute sql query. */ + public static final int EXECUTE_SQL_QUERY = 1; + + /** Fetch query results. */ + public static final int FETCH_SQL_QUERY = 2; + + /** Close query. */ + public static final int CLOSE_SQL_QUERY = 3; + + /** Get columns meta query. */ + public static final int GET_COLUMNS_META = 4; + + /** Get columns meta query. */ + public static final int GET_TABLES_META = 5; + + /** Command. */ + private int cmd; + + /** + * @param cmd Command type. + */ + public OdbcRequest(int cmd) { + this.cmd = cmd; + } + + /** + * @return Command. + */ + public int command() { + return cmd; + } + + /** + * @param cmd Command. + */ + public void command(int cmd) { + this.cmd = cmd; + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/2a756311/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcResponse.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcResponse.java new file mode 100644 index 0000000..653e3f4 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcResponse.java @@ -0,0 +1,107 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.ignite.internal.processors.odbc; + +import org.apache.ignite.internal.util.tostring.GridToStringInclude; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.jetbrains.annotations.Nullable; + +/** + * ODBC protocol response. + */ +public class OdbcResponse { + + /** Command succeeded. */ + public static final int STATUS_SUCCESS = 0; + + /** Command failed. */ + public static final int STATUS_FAILED = 1; + + /** Success status. */ + @SuppressWarnings("RedundantFieldInitialization") + private int successStatus = STATUS_SUCCESS; + + /** Error. */ + private String err; + + /** Response object. */ + @GridToStringInclude + private Object obj; + + /** + * Constructs successful rest response. + * + * @param obj Response object. + */ + public OdbcResponse(Object obj) { + successStatus = STATUS_SUCCESS; + this.obj = obj; + } + + /** + * Constructs failed rest response. + * + * @param status Response status. + * @param err Error, {@code null} if success is {@code true}. + */ + public OdbcResponse(int status, @Nullable String err) { + assert status != STATUS_SUCCESS; + + successStatus = status; + this.err = err; + } + + /** + * @return Success flag. + */ + public int getSuccessStatus() { + return successStatus; + } + + /** + * @return Response object. + */ + public Object getResponse() { + return obj; + } + + /** + * @param obj Response object. + */ + public void setResponse(@Nullable Object obj) { + this.obj = obj; + } + + /** + * @return Error. + */ + public String getError() { + return err; + } + + /** + * @param err Error. + */ + public void setError(String err) { + this.err = err; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(OdbcResponse.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/2a756311/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcTcpNioListener.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcTcpNioListener.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcTcpNioListener.java new file mode 100644 index 0000000..c30daff --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcTcpNioListener.java @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.ignite.internal.processors.odbc; + +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.IgniteLogger; +import org.apache.ignite.internal.GridKernalContext; +import org.apache.ignite.internal.util.nio.GridNioFuture; +import org.apache.ignite.internal.util.nio.GridNioServerListenerAdapter; +import org.apache.ignite.internal.util.nio.GridNioSession; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.jetbrains.annotations.Nullable; + +/** + * Listener for ODBC driver connection. + */ +public class OdbcTcpNioListener extends GridNioServerListenerAdapter<OdbcRequest> { + /** Server. */ + private OdbcTcpServer srv; + + /** Logger. */ + protected final IgniteLogger log; + + /** Context. */ + protected final GridKernalContext ctx; + + /** Protocol handler. */ + private OdbcProtocolHandler hnd; + + OdbcTcpNioListener(IgniteLogger log, OdbcTcpServer srv, GridKernalContext ctx, OdbcProtocolHandler hnd) { + this.log = log; + this.srv = srv; + this.ctx = ctx; + this.hnd = hnd; + } + + @Override + public void onConnected(GridNioSession ses) { + System.out.println("Driver connected"); + } + + @Override + public void onDisconnected(GridNioSession ses, @Nullable Exception e) { + System.out.println("Driver disconnected"); + + if (e != null) { + if (e instanceof RuntimeException) + U.error(log, "Failed to process request from remote client: " + ses, e); + else + U.warn(log, "Closed client session due to exception [ses=" + ses + ", msg=" + e.getMessage() + ']'); + } + } + + @Override + public void onMessage(GridNioSession ses, OdbcRequest msg) { + assert msg != null; + + System.out.println("Query: " + msg.command()); + + OdbcResponse res; + + try { + res = hnd.handle(msg); + } + catch (IgniteCheckedException e) { + U.error(log, "Failed to process client request: " + msg, e); + + res = new OdbcResponse(OdbcResponse.STATUS_FAILED, + "Failed to process client request: " + e.getMessage()); + } + + System.out.println("Resulting success status: " + res.getSuccessStatus()); + + GridNioFuture<?> sf = ses.send(res); + + // Check if send failed. + if (sf.isDone()) { + try { + sf.get(); + } catch (Exception e) { + U.error(log, "Failed to process client request [ses=" + ses + ", msg=" + msg + ']', e); + } + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/2a756311/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcTcpServer.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcTcpServer.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcTcpServer.java new file mode 100644 index 0000000..83adb1b --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/OdbcTcpServer.java @@ -0,0 +1,189 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.ignite.internal.processors.odbc; + +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.IgniteLogger; +import org.apache.ignite.configuration.ConnectorConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.OdbcConfiguration; +import org.apache.ignite.internal.GridKernalContext; +import org.apache.ignite.internal.util.nio.*; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.spi.IgnitePortProtocol; + +import java.io.IOException; +import java.net.InetAddress; +import java.nio.ByteOrder; + +/** + * TCP server that handles communication with ODBC driver. + */ +public class OdbcTcpServer { + + /** Server. */ + private GridNioServer<OdbcRequest> srv; + + /** NIO server listener. */ + private GridNioServerListener<OdbcRequest> lsnr; + + /** Logger. */ + protected final IgniteLogger log; + + /** Context. */ + protected final GridKernalContext ctx; + + /** Host used by this protocol. */ + protected InetAddress host; + + /** Port used by this protocol. */ + protected int port; + + /** */ + public String name() { + return "ODBC server"; + } + + public OdbcTcpServer(GridKernalContext ctx) { + assert ctx != null; + assert ctx.config().getConnectorConfiguration() != null; + + this.ctx = ctx; + + log = ctx.log(getClass()); + } + + @SuppressWarnings("BusyWait") + public void start(final OdbcProtocolHandler hnd) throws IgniteCheckedException { + OdbcConfiguration cfg = ctx.config().getOdbcConfiguration(); + + assert cfg != null; + + lsnr = new OdbcTcpNioListener(log, this, ctx, hnd); + + GridNioParser parser = new OdbcParser(ctx); + + try { + host = resolveOdbcTcpHost(ctx.config()); + + int odbcPort = cfg.getPort(); + + if (startTcpServer(host, odbcPort, lsnr, parser, cfg)) { + port = odbcPort; + + System.out.println("ODBC Server has started on TCP port " + port); + + return; + } + + U.warn(log, "Failed to start " + name() + " (possibly all ports in range are in use) " + + "[odbcPort=" + odbcPort + ", host=" + host + ']'); + } + catch (IOException e) { + U.warn(log, "Failed to start " + name() + " on port " + port + ": " + e.getMessage(), + "Failed to start " + name() + " on port " + port + ". " + + "Check restTcpHost configuration property."); + } + } + + /** */ + public void onKernalStart() { + } + + /** */ + public void stop() { + if (srv != null) { + ctx.ports().deregisterPorts(getClass()); + + srv.stop(); + } + } + + /** + * Resolves host for server using grid configuration. + * + * @param cfg Grid configuration. + * @return Host address. + * @throws IOException If failed to resolve host. + */ + private InetAddress resolveOdbcTcpHost(IgniteConfiguration cfg) throws IOException { + String host = null; + + ConnectorConfiguration connectionCfg = cfg.getConnectorConfiguration(); + + if (connectionCfg != null) + host = connectionCfg.getHost(); + + if (host == null) + host = cfg.getLocalHost(); + + return U.resolveLocalHost(host); + } + + /** + * Tries to start server with given parameters. + * + * @param hostAddr Host on which server should be bound. + * @param port Port on which server should be bound. + * @param lsnr Server message listener. + * @param parser Server message parser. + * @param cfg Configuration for other parameters. + * @return {@code True} if server successfully started, {@code false} if port is used and + * server was unable to start. + */ + private boolean startTcpServer(InetAddress hostAddr, int port, GridNioServerListener<OdbcRequest> lsnr, + GridNioParser parser, OdbcConfiguration cfg) { + try { + GridNioFilter codec = new GridNioCodecFilter(parser, log, false); + + GridNioFilter[] filters; + + filters = new GridNioFilter[] { codec }; + + srv = GridNioServer.<OdbcRequest>builder() + .address(hostAddr) + .port(port) + .listener(lsnr) + .logger(log) + .selectorCount(cfg.getSelectorCount()) + .gridName(ctx.gridName()) + .tcpNoDelay(cfg.isNoDelay()) + .directBuffer(cfg.isDirectBuffer()) + .byteOrder(ByteOrder.nativeOrder()) + .socketSendBufferSize(cfg.getSendBufferSize()) + .socketReceiveBufferSize(cfg.getReceiveBufferSize()) + .sendQueueLimit(cfg.getSendQueueLimit()) + .filters(filters) + .directMode(false) + .build(); + + srv.idleTimeout(cfg.getIdleTimeout()); + + srv.start(); + + ctx.ports().registerPort(port, IgnitePortProtocol.TCP, getClass()); + + return true; + } + catch (IgniteCheckedException e) { + if (log.isDebugEnabled()) + log.debug("Failed to start " + name() + " on port " + port + ": " + e.getMessage()); + + return false; + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/2a756311/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/protocol/OdbcParser.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/protocol/OdbcParser.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/protocol/OdbcParser.java deleted file mode 100644 index 602f859..0000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/protocol/OdbcParser.java +++ /dev/null @@ -1,345 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ignite.internal.processors.odbc.protocol; - -import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.internal.GridKernalContext; -import org.apache.ignite.internal.binary.*; -import org.apache.ignite.internal.binary.streams.BinaryHeapInputStream; -import org.apache.ignite.internal.binary.streams.BinaryHeapOutputStream; -import org.apache.ignite.internal.binary.streams.BinaryInputStream; -import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl; -import org.apache.ignite.internal.processors.odbc.OdbcColumnMeta; -import org.apache.ignite.internal.processors.odbc.OdbcTableMeta; -import org.apache.ignite.internal.processors.odbc.request.*; -import org.apache.ignite.internal.processors.odbc.response.*; -import org.apache.ignite.internal.util.nio.GridNioParser; -import org.apache.ignite.internal.util.nio.GridNioSession; -import org.jetbrains.annotations.Nullable; - -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.Collection; - - -/** - * ODBC protocol parser. - */ -public class OdbcParser implements GridNioParser { - /** Initial output stream capacity. */ - private static final int INIT_CAP = 1024; - - /** Length in bytes of the remaining message part. */ - int leftToReceive = 0; - - /** Already received bytes of current message. */ - ByteBuffer currentMessage = null; - - /** Context. */ - protected final GridKernalContext ctx; - - /** Marshaller. */ - private final GridBinaryMarshaller marsh; - - OdbcParser(GridKernalContext context) { - ctx = context; - - CacheObjectBinaryProcessorImpl cacheObjProc = (CacheObjectBinaryProcessorImpl)ctx.cacheObjects(); - - marsh = cacheObjProc.marshaller(); - } - - /** - * Process data chunk and try to construct new message using stored and freshly received data. - * @param buf Fresh data buffer. - * @return Instance of the {@link BinaryReaderExImpl} positioned to read from the beginning of the message on - * success and null otherwise. - */ - private BinaryRawReaderEx tryConstructMessage(ByteBuffer buf) { - if (leftToReceive != 0) { - // Still receiving message - int toConsume = Math.min(leftToReceive, buf.remaining()); - - currentMessage.put(buf.array(), buf.arrayOffset(), toConsume); - leftToReceive -= toConsume; - - buf.position(buf.position() + toConsume); - - if (leftToReceive != 0) - return null; - - BinaryInputStream stream = new BinaryHeapInputStream(currentMessage.array()); - - BinaryReaderExImpl reader = new BinaryReaderExImpl(null, stream, null); - - currentMessage = null; - - return reader; - } - - // Receiving new message - // Getting message length. It's in the first four bytes of the message. - BinaryInputStream stream = new BinaryHeapInputStream(buf.array()); - - BinaryReaderExImpl reader = new BinaryReaderExImpl(null, stream, null); - - int messageLen = reader.readInt(); - buf.getInt(); - - int remaining = buf.remaining(); - - if (messageLen > remaining) { - leftToReceive = messageLen - remaining; - - currentMessage = ByteBuffer.allocate(messageLen); - currentMessage.put(buf); - - return null; - } - - buf.position(buf.position() + messageLen); - - return reader; - } - - /** {@inheritDoc} */ - @Nullable @Override public OdbcRequest decode(GridNioSession ses, ByteBuffer buf) throws IOException, - IgniteCheckedException { - BinaryRawReaderEx messageReader = tryConstructMessage(buf); - - return messageReader == null ? null : readRequest(ses, messageReader); - } - - /** {@inheritDoc} */ - @Override public ByteBuffer encode(GridNioSession ses, Object msg) throws IOException, IgniteCheckedException { - assert msg != null; - assert msg instanceof OdbcResponse; - - System.out.println("Encoding query processing result"); - - BinaryRawWriterEx writer = marsh.writer(new BinaryHeapOutputStream(INIT_CAP)); - - // Reserving space for the message length. - int msgLenPos = writer.reserveInt(); - - writeResponse(ses, writer, (OdbcResponse)msg); - - int msgLenWithHdr = writer.out().position() - msgLenPos; - - int msgLen = msgLenWithHdr - 4; - - writer.writeInt(msgLenPos, msgLen); - - ByteBuffer buf = ByteBuffer.allocate(msgLenWithHdr); - - buf.put(writer.out().array(), msgLenPos, msgLenWithHdr); - - buf.flip(); - - return buf; - } - - /** - * Read ODBC request from the raw data using provided {@link BinaryReaderExImpl} instance. - * @param ses Current session. - * @param reader Reader positioned to read the request. - * @return Instance of the {@link OdbcRequest}. - * @throws IOException if the type of the request is unknown to the parser. - */ - private OdbcRequest readRequest(GridNioSession ses, BinaryRawReaderEx reader) throws IOException { - OdbcRequest res; - - byte cmd = reader.readByte(); - - switch (cmd) { - case OdbcRequest.EXECUTE_SQL_QUERY: { - String cache = reader.readString(); - String sql = reader.readString(); - int argsNum = reader.readInt(); - - System.out.println("Message EXECUTE_SQL_QUERY:"); - System.out.println("cache: " + cache); - System.out.println("query: " + sql); - System.out.println("argsNum: " + argsNum); - - Object[] params = new Object[argsNum]; - - for (int i = 0; i < argsNum; ++i) - params[i] = reader.readObjectDetached(); - - res = new OdbcQueryExecuteRequest(cache, sql, params); - break; - } - - case OdbcRequest.FETCH_SQL_QUERY: { - long queryId = reader.readLong(); - int pageSize = reader.readInt(); - - System.out.println("Message FETCH_SQL_QUERY:"); - System.out.println("queryId: " + queryId); - System.out.println("pageSize: " + pageSize); - - res = new OdbcQueryFetchRequest(queryId, pageSize); - break; - } - - case OdbcRequest.CLOSE_SQL_QUERY: { - long queryId = reader.readLong(); - - System.out.println("Message CLOSE_SQL_QUERY:"); - System.out.println("queryId: " + queryId); - - res = new OdbcQueryCloseRequest(queryId); - break; - } - - case OdbcRequest.GET_COLUMNS_META: { - String cache = reader.readString(); - String table = reader.readString(); - String column = reader.readString(); - - System.out.println("Message GET_COLUMNS_META:"); - System.out.println("cache: " + cache); - System.out.println("table: " + table); - System.out.println("column: " + column); - - res = new OdbcQueryGetColumnsMetaRequest(cache, table, column); - break; - } - - case OdbcRequest.GET_TABLES_META: { - String catalog = reader.readString(); - String schema = reader.readString(); - String table = reader.readString(); - String tableType = reader.readString(); - - System.out.println("Message GET_COLUMNS_META:"); - System.out.println("catalog: " + catalog); - System.out.println("schema: " + schema); - System.out.println("table: " + table); - System.out.println("tableType: " + tableType); - - res = new OdbcQueryGetTablesMetaRequest(catalog, schema, table, tableType); - break; - } - - default: - throw new IOException("Failed to parse incoming packet (unknown command type) [ses=" + ses + - ", cmd=[" + Byte.toString(cmd) + ']'); - } - - return res; - } - - /** - * Write ODBC response using provided {@link BinaryRawWriterEx} instance. - * @param ses Current session. - * @param writer Writer. - * @param rsp ODBC response that should be written. - * @throws IOException if the type of the response is unknown to the parser. - */ - private void writeResponse(GridNioSession ses, BinaryRawWriterEx writer, OdbcResponse rsp) throws IOException { - // Writing status - writer.writeByte((byte)rsp.getSuccessStatus()); - - if (rsp.getSuccessStatus() != OdbcResponse.STATUS_SUCCESS) { - writer.writeString(rsp.getError()); - - return; - } - - Object res0 = rsp.getResponse(); - - if (res0 instanceof OdbcQueryExecuteResult) { - OdbcQueryExecuteResult res = (OdbcQueryExecuteResult) res0; - - System.out.println("Resulting query ID: " + res.getQueryId()); - - writer.writeLong(res.getQueryId()); - - Collection<OdbcColumnMeta> metas = res.getColumnsMetadata(); - - assert metas != null; - - writer.writeInt(metas.size()); - - for (OdbcColumnMeta meta : metas) - meta.writeBinary(writer, marsh.context()); - - } else if (res0 instanceof OdbcQueryFetchResult) { - OdbcQueryFetchResult res = (OdbcQueryFetchResult) res0; - - System.out.println("Resulting query ID: " + res.getQueryId()); - - writer.writeLong(res.getQueryId()); - - Collection<?> items0 = res.getItems(); - - assert items0 != null; - - Collection<Collection<Object>> items = (Collection<Collection<Object>>)items0; - - writer.writeBoolean(res.getLast()); - - writer.writeInt(items.size()); - - for (Collection<Object> row : items) { - if (row != null) { - writer.writeInt(row.size()); - - for (Object obj : row) { - if (obj != null) - writer.writeObjectDetached(obj); - } - } - } - } else if (res0 instanceof OdbcQueryCloseResult) { - OdbcQueryCloseResult res = (OdbcQueryCloseResult) res0; - - System.out.println("Resulting query ID: " + res.getQueryId()); - - writer.writeLong(res.getQueryId()); - - } else if (res0 instanceof OdbcQueryGetColumnsMetaResult) { - OdbcQueryGetColumnsMetaResult res = (OdbcQueryGetColumnsMetaResult) res0; - - Collection<OdbcColumnMeta> columnsMeta = res.getMeta(); - - assert columnsMeta != null; - - writer.writeInt(columnsMeta.size()); - - for (OdbcColumnMeta columnMeta : columnsMeta) - columnMeta.writeBinary(writer, marsh.context()); - - } else if (res0 instanceof OdbcQueryGetTablesMetaResult) { - OdbcQueryGetTablesMetaResult res = (OdbcQueryGetTablesMetaResult) res0; - - Collection<OdbcTableMeta> tablesMeta = res.getMeta(); - - assert tablesMeta != null; - - writer.writeInt(tablesMeta.size()); - - for (OdbcTableMeta tableMeta : tablesMeta) - tableMeta.writeBinary(writer); - - } else { - throw new IOException("Failed to serialize response packet (unknown response type) [ses=" + ses + "]"); - } - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/2a756311/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/protocol/OdbcTcpNioListener.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/protocol/OdbcTcpNioListener.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/protocol/OdbcTcpNioListener.java deleted file mode 100644 index 656a477..0000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/protocol/OdbcTcpNioListener.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ignite.internal.processors.odbc.protocol; - -import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.IgniteLogger; -import org.apache.ignite.internal.GridKernalContext; -import org.apache.ignite.internal.processors.odbc.OdbcProtocolHandler; -import org.apache.ignite.internal.processors.odbc.request.OdbcRequest; -import org.apache.ignite.internal.processors.odbc.response.OdbcResponse; -import org.apache.ignite.internal.util.nio.GridNioFuture; -import org.apache.ignite.internal.util.nio.GridNioServerListenerAdapter; -import org.apache.ignite.internal.util.nio.GridNioSession; -import org.apache.ignite.internal.util.typedef.internal.U; -import org.jetbrains.annotations.Nullable; - -/** - * Listener for ODBC driver connection. - */ -public class OdbcTcpNioListener extends GridNioServerListenerAdapter<OdbcRequest> { - /** Server. */ - private OdbcTcpServer srv; - - /** Logger. */ - protected final IgniteLogger log; - - /** Context. */ - protected final GridKernalContext ctx; - - /** Protocol handler. */ - private OdbcProtocolHandler hnd; - - OdbcTcpNioListener(IgniteLogger log, OdbcTcpServer srv, GridKernalContext ctx, OdbcProtocolHandler hnd) { - this.log = log; - this.srv = srv; - this.ctx = ctx; - this.hnd = hnd; - } - - @Override - public void onConnected(GridNioSession ses) { - System.out.println("Driver connected"); - } - - @Override - public void onDisconnected(GridNioSession ses, @Nullable Exception e) { - System.out.println("Driver disconnected"); - - if (e != null) { - if (e instanceof RuntimeException) - U.error(log, "Failed to process request from remote client: " + ses, e); - else - U.warn(log, "Closed client session due to exception [ses=" + ses + ", msg=" + e.getMessage() + ']'); - } - } - - @Override - public void onMessage(GridNioSession ses, OdbcRequest msg) { - assert msg != null; - - System.out.println("Query: " + msg.command()); - - OdbcResponse res; - - try { - res = hnd.handle(msg); - } - catch (IgniteCheckedException e) { - U.error(log, "Failed to process client request: " + msg, e); - - res = new OdbcResponse(OdbcResponse.STATUS_FAILED, - "Failed to process client request: " + e.getMessage()); - } - - System.out.println("Resulting success status: " + res.getSuccessStatus()); - - GridNioFuture<?> sf = ses.send(res); - - // Check if send failed. - if (sf.isDone()) { - try { - sf.get(); - } catch (Exception e) { - U.error(log, "Failed to process client request [ses=" + ses + ", msg=" + msg + ']', e); - } - } - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/2a756311/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/protocol/OdbcTcpServer.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/protocol/OdbcTcpServer.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/protocol/OdbcTcpServer.java deleted file mode 100644 index 4fbd326..0000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/protocol/OdbcTcpServer.java +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ignite.internal.processors.odbc.protocol; - -import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.IgniteLogger; -import org.apache.ignite.configuration.ConnectorConfiguration; -import org.apache.ignite.configuration.IgniteConfiguration; -import org.apache.ignite.configuration.OdbcConfiguration; -import org.apache.ignite.internal.GridKernalContext; -import org.apache.ignite.internal.processors.odbc.OdbcProtocolHandler; -import org.apache.ignite.internal.processors.odbc.request.OdbcRequest; -import org.apache.ignite.internal.util.nio.*; -import org.apache.ignite.internal.util.typedef.internal.U; -import org.apache.ignite.spi.IgnitePortProtocol; - -import java.io.IOException; -import java.net.InetAddress; -import java.nio.ByteOrder; - -/** - * TCP server that handles communication with ODBC driver. - */ -public class OdbcTcpServer { - - /** Server. */ - private GridNioServer<OdbcRequest> srv; - - /** NIO server listener. */ - private GridNioServerListener<OdbcRequest> lsnr; - - /** Logger. */ - protected final IgniteLogger log; - - /** Context. */ - protected final GridKernalContext ctx; - - /** Host used by this protocol. */ - protected InetAddress host; - - /** Port used by this protocol. */ - protected int port; - - /** */ - public String name() { - return "ODBC server"; - } - - public OdbcTcpServer(GridKernalContext ctx) { - assert ctx != null; - assert ctx.config().getConnectorConfiguration() != null; - - this.ctx = ctx; - - log = ctx.log(getClass()); - } - - @SuppressWarnings("BusyWait") - public void start(final OdbcProtocolHandler hnd) throws IgniteCheckedException { - OdbcConfiguration cfg = ctx.config().getOdbcConfiguration(); - - assert cfg != null; - - lsnr = new OdbcTcpNioListener(log, this, ctx, hnd); - - GridNioParser parser = new OdbcParser(ctx); - - try { - host = resolveOdbcTcpHost(ctx.config()); - - int odbcPort = cfg.getPort(); - - if (startTcpServer(host, odbcPort, lsnr, parser, cfg)) { - port = odbcPort; - - System.out.println("ODBC Server has started on TCP port " + port); - - return; - } - - U.warn(log, "Failed to start " + name() + " (possibly all ports in range are in use) " + - "[odbcPort=" + odbcPort + ", host=" + host + ']'); - } - catch (IOException e) { - U.warn(log, "Failed to start " + name() + " on port " + port + ": " + e.getMessage(), - "Failed to start " + name() + " on port " + port + ". " + - "Check restTcpHost configuration property."); - } - } - - /** */ - public void onKernalStart() { - } - - /** */ - public void stop() { - if (srv != null) { - ctx.ports().deregisterPorts(getClass()); - - srv.stop(); - } - } - - /** - * Resolves host for server using grid configuration. - * - * @param cfg Grid configuration. - * @return Host address. - * @throws IOException If failed to resolve host. - */ - private InetAddress resolveOdbcTcpHost(IgniteConfiguration cfg) throws IOException { - String host = null; - - ConnectorConfiguration connectionCfg = cfg.getConnectorConfiguration(); - - if (connectionCfg != null) - host = connectionCfg.getHost(); - - if (host == null) - host = cfg.getLocalHost(); - - return U.resolveLocalHost(host); - } - - /** - * Tries to start server with given parameters. - * - * @param hostAddr Host on which server should be bound. - * @param port Port on which server should be bound. - * @param lsnr Server message listener. - * @param parser Server message parser. - * @param cfg Configuration for other parameters. - * @return {@code True} if server successfully started, {@code false} if port is used and - * server was unable to start. - */ - private boolean startTcpServer(InetAddress hostAddr, int port, GridNioServerListener<OdbcRequest> lsnr, - GridNioParser parser, OdbcConfiguration cfg) { - try { - GridNioFilter codec = new GridNioCodecFilter(parser, log, false); - - GridNioFilter[] filters; - - filters = new GridNioFilter[] { codec }; - - srv = GridNioServer.<OdbcRequest>builder() - .address(hostAddr) - .port(port) - .listener(lsnr) - .logger(log) - .selectorCount(cfg.getSelectorCount()) - .gridName(ctx.gridName()) - .tcpNoDelay(cfg.isNoDelay()) - .directBuffer(cfg.isDirectBuffer()) - .byteOrder(ByteOrder.nativeOrder()) - .socketSendBufferSize(cfg.getSendBufferSize()) - .socketReceiveBufferSize(cfg.getReceiveBufferSize()) - .sendQueueLimit(cfg.getSendQueueLimit()) - .filters(filters) - .directMode(false) - .build(); - - srv.idleTimeout(cfg.getIdleTimeout()); - - srv.start(); - - ctx.ports().registerPort(port, IgnitePortProtocol.TCP, getClass()); - - return true; - } - catch (IgniteCheckedException e) { - if (log.isDebugEnabled()) - log.debug("Failed to start " + name() + " on port " + port + ": " + e.getMessage()); - - return false; - } - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/2a756311/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/request/OdbcQueryCloseRequest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/request/OdbcQueryCloseRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/request/OdbcQueryCloseRequest.java deleted file mode 100644 index 8ebcca1..0000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/request/OdbcQueryCloseRequest.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ignite.internal.processors.odbc.request; - -/** - * ODBC query close request. - */ -public class OdbcQueryCloseRequest extends OdbcRequest { - /** Query ID. */ - private long queryId; - - /** - * @param queryId Query ID. - */ - public OdbcQueryCloseRequest(long queryId) { - super(CLOSE_SQL_QUERY); - this.queryId = queryId; - } - - /** - * @param queryId Query ID. - */ - public void cacheName(long queryId) { - this.queryId = queryId; - } - - /** - * @return Query ID. - */ - public long queryId() { - return queryId; - } -} \ No newline at end of file
