SQLITest.java
/***************************************************************************
Copyright 2012 Emily Estes
Licensed 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 net.metanotion.sqlc;
import java.io.File;
import java.io.FileInputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.sql.Connection;
import java.sql.ResultSet;
import javax.sql.DataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.metanotion.io.JavaFileSystem;
import net.metanotion.scripting.StructManager;
import net.metanotion.sql.DbUtil;
import net.metanotion.sql.MockDataSource;
import net.metanotion.web.servlets.ServerUtil;
public final class SQLITest {
private static final Logger logger = LoggerFactory.getLogger(SQLITest.class);
public static void main(String[] args) {
try {
DataSource ds = DbUtil.startDBConnectionPool(args[1], args[2], args[3]);
StructManager sm = new StructManager();
logger.debug(new File(args[4]).toString() + File.separator + "sql");
JavaFileSystem sql = new JavaFileSystem(new File(args[4]).toString() + File.separator + "sql");
SQLObjectServer sqlObjects = new SQLObjectServer(sql, sm);
SQLClass q2 = sqlObjects.get("Queries");
Load loader = new Load();
SQLClass q = loader.load(new FileInputStream(args[0]), sm, new HashSet<String>());
Connection conn = ds.getConnection();
logger.debug(":reserveMapID");
Object ret = q.eval(Arrays.asList("reserveMapID", conn));
if(ret != null) { logger.debug("Return: " + ret.toString()); }
logger.debug(":addMap");
q.eval(Arrays.asList("addMap", conn, ret, ret, ret));
logger.debug(":getMaps");
ResultSet rs = (ResultSet) q.eval(Arrays.asList("getMaps", conn, 2));
while(rs.next()) {
logger.debug("row: " + rs.getInt("MapID"));
}
rs.close();
q.eval(Arrays.asList("addTest", conn, "meh", "A", "asdf", 5));
q.eval(Arrays.asList("addTest", conn, "qwerty", "C", "zxcv", 10));
q.eval(Arrays.asList("addTest", conn, "foo", "B", "bar", 1));
List list = (List) q.eval(Arrays.asList("getTest", conn));
for(Object o: list) {
logger.debug("Return: " + o.toString());
}
logger.debug("test 2");
list = (List) q.eval(Arrays.asList("getTest2", conn));
for(Object o: list) {
TestStruct ts = (TestStruct) o;
logger.debug("Return: " + ts.toString());
}
} catch (Exception e) { logger.debug("failed", e); }
}
}