Skip to content

Commit

Permalink
0001064: Add interactive command line sql tool. dbsql
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Apr 29, 2013
1 parent 8c0b0b4 commit 3df1011
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 0 deletions.
6 changes: 6 additions & 0 deletions symmetric-assemble/src/assembly/assembly-server.xml
Expand Up @@ -23,6 +23,7 @@
<exclude>bin/dbexport</exclude>
<exclude>bin/dbimport</exclude>
<exclude>bin/dbfill</exclude>
<exclude>bin/dbsql</exclude>
<exclude>bin/sym_service</exclude>
<exclude>bin/sym_service.initd</exclude>
</excludes>
Expand Down Expand Up @@ -58,6 +59,11 @@
<outputDirectory>/bin</outputDirectory>
<fileMode>755</fileMode>
</file>
<file>
<source>../symmetric-server/src/main/deploy/bin/dbsql</source>
<outputDirectory>/bin</outputDirectory>
<fileMode>755</fileMode>
</file>
<file>
<source>../symmetric-server/src/main/deploy/bin/sym_service.initd</source>
<outputDirectory>/bin</outputDirectory>
Expand Down
@@ -0,0 +1,60 @@
/*
* Licensed to JumpMind Inc under one or more contributor
* license agreements. See the NOTICE file distributed
* with this work for additional information regarding
* copyright ownership. JumpMind Inc licenses this file
* to you under the GNU Lesser General Public License (the
* "License"); you may not use this file except in compliance
* with the License.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see
* <http://www.gnu.org/licenses/>.
*
* 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.jumpmind.symmetric;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.dbcp.BasicDataSource;
import org.h2.tools.Shell;

public class DbSqlCommand extends AbstractCommandLauncher {

public DbSqlCommand() {
super("dbsql", "", "DbSqlShell.Option.");
}

public static void main(String[] args) {
new DbSqlCommand().execute(args);
}

@Override
protected boolean printHelpIfNoOptionsAreProvided() {
return false;
}

@Override
protected boolean requiresPropertiesFile() {
return true;
}

@Override
protected boolean executeWithOptions(CommandLine line) throws Exception {
BasicDataSource basicDataSource = getDatabasePlatform(false).getDataSource();
String url = basicDataSource.getUrl();
String user = basicDataSource.getUsername();
String password = basicDataSource.getPassword();
String driver = basicDataSource.getDriverClassName();
Shell shell = new Shell();
shell.runTool("-url", url, "-user", user, "-password", password, "-driver", driver);
return true;
}


}
50 changes: 50 additions & 0 deletions symmetric-server/src/main/deploy/bin/dbsql
@@ -0,0 +1,50 @@
#!/bin/sh
#
# Run commandline support through DbDump
#

PRGDIR=`dirname "$0"`
if [ "$PRGDIR" = "" ]
then
PRGDIR=`echo $0 | sed 's/\/sym//g'`
fi
if [ "$PRGDIR" = "" ]
then
PRGDIR="."
fi
LIBDIR=$PRGDIR/../lib
WEBLIBDIR=$PRGDIR/../web/WEB-INF/lib
LOG4JXML="file:$PRGDIR/../conf/log4j.xml"
RUNJAVA=java

if [ -n "log4j.xml" -a -f "log4j.xml" ]
then
LOG4JXML="file:$PRGDIR/log4j.xml"
fi

if [ -x "$JAVA_HOME/bin/java" ]
then
RUNJAVA="$JAVA_HOME/bin/java"
fi

CLASSPATH=../patches
SEP=:

if uname | grep -i cygwin > /dev/null
then
SEP=";"
fi

for jar in $LIBDIR/*
do
CLASSPATH=${CLASSPATH}${SEP}${jar}
done

for jar in $WEBLIBDIR/*
do
CLASSPATH=${CLASSPATH}${SEP}${jar}
done

#echo $CLASSPATH

exec "$RUNJAVA" -Duser.language=en -Djava.io.tmpdir=../tmp -Dsym.keystore.file="$PRGDIR/../security/keystore" -Djavax.net.ssl.trustStore="$PRGDIR/../security/cacerts" -Dsun.net.client.defaultReadTimeout=1800000 -Dsun.net.client.defaultConnectTimeout=1800000 -Dlog4j.configuration=$LOG4JXML -cp $CLASSPATH org.jumpmind.symmetric.DbSqlCommand "$@"
14 changes: 14 additions & 0 deletions symmetric-server/src/main/deploy/bin/dbsql.bat
@@ -0,0 +1,14 @@
@echo off

set PRGDIR=%~dp0
set HOMEDIR=%PRGDIR%..
set CONFDIR=%HOMEDIR%\conf
set CLASSPATH=%HOMEDIR%\patches

for %%i in ("%HOMEDIR%\lib\*.jar") do call "%PRGDIR%cpappend.bat" %%i

for %%i in ("%HOMEDIR%\web\WEB-INF\lib\*.jar") do call "%PRGDIR%cpappend.bat" %%i

rem echo CLASSPATH=%CLASSPATH%

java -Duser.language=en -Djava.io.tmpdir=../tmp -Dsym.keystore.file="%HOMEDIR%\security\keystore" -Djavax.net.ssl.trustStore="%HOMEDIR%\security\cacerts" -Dlog4j.configuration="file:%CONFDIR%\log4j.xml" -Dsun.net.client.defaultReadTimeout=1800000 -Dsun.net.client.defaultConnectTimeout=1800000 org.jumpmind.symmetric.DbSqlCommand %1 %2 %3 %4 %5 %6 %7 %8 %9

0 comments on commit 3df1011

Please sign in to comment.