You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nlpcraft.apache.org by se...@apache.org on 2020/05/29 07:24:36 UTC
[incubator-nlpcraft] branch master updated: H2 SQL Server
(examples) files location fixed.
This is an automated email from the ASF dual-hosted git repository.
sergeykamov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/master by this push:
new 048334b H2 SQL Server (examples) files location fixed.
048334b is described below
commit 048334b5f47b8d0cda9eb062b0a3fa57271a5034
Author: Sergey Kamov <se...@apache.org>
AuthorDate: Fri May 29 10:24:29 2020 +0300
H2 SQL Server (examples) files location fixed.
---
.../scala/org/apache/nlpcraft/examples/sql/db/SqlServer.scala | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/main/scala/org/apache/nlpcraft/examples/sql/db/SqlServer.scala b/src/main/scala/org/apache/nlpcraft/examples/sql/db/SqlServer.scala
index 4640ed1..f527ed4 100644
--- a/src/main/scala/org/apache/nlpcraft/examples/sql/db/SqlServer.scala
+++ b/src/main/scala/org/apache/nlpcraft/examples/sql/db/SqlServer.scala
@@ -18,9 +18,11 @@
package org.apache.nlpcraft.examples.sql.db
import java.io.File
+import java.nio.file.Paths
import java.sql.SQLException
import com.typesafe.scalalogging.LazyLogging
+import org.apache.commons.io.FilenameUtils
import org.h2.jdbcx.JdbcDataSource
import org.h2.tools.Server
@@ -29,13 +31,14 @@ import org.h2.tools.Server
*/
object SqlServer extends LazyLogging {
private final val H2_PORT: Int = 9092
- private final val H2_BASEDIR = "~/nlpcraft-examples/h2"
+ private final val H2_BASEDIR = new File(System.getProperty("user.home"), "nlpcraft-examples/h2").getAbsolutePath
private final val SRV_PARAMS = Seq(
"-baseDir", H2_BASEDIR,
"-tcpPort", H2_PORT.toString,
"-tcpAllowOthers"
)
+
private final val INIT_FILE = "src/main/scala/org/apache/nlpcraft/examples/sql/db/northwind.sql"
final val H2_URL: String = s"jdbc:h2:tcp://localhost:$H2_PORT/nlp2sql"
@@ -57,7 +60,8 @@ object SqlServer extends LazyLogging {
val ds = new JdbcDataSource()
- ds.setUrl(s"$H2_URL;INIT=RUNSCRIPT FROM '${new File(INIT_FILE).getAbsolutePath}'")
+ // Unix format used to avoid escape files separator for windows.
+ ds.setUrl(s"$H2_URL;INIT=RUNSCRIPT FROM '${FilenameUtils.separatorsToUnix(new File(INIT_FILE).getAbsolutePath)}'")
try {
ds.getConnection