import jp.co.denso.fa.jcaosql.*;

public class Main {

	public static void main(String[] args) {

		CaoSQLEngine eng = null;
		CaoSQLController ctrl = null;
		CaoSQLItem item = null;

		try {
			eng = CaoSQLEngine.createInstance();
			System.out.println("created Engine...");
			Main mn = new Main();
			mn.sleep(1000);

			if (eng.count() < 1) {
				System.out.println(eng.count());
				throw new Exception("there is no controller settings.");
			}
			String[] ctrl_names = eng.getControllerNames();
			ctrl = eng.Controller(ctrl_names[0]);
			System.out.println("Getting Controller ["+ ctrl_names[0] + "]");

			if (ctrl.getCount() < 1) {
				throw new Exception("there is no item settings.");
			}
			String[] item_names = ctrl.getItemNames();
			item = ctrl.Item(item_names[0]);
			System.out.println("Getting Item ["+ item_names[0] + "]");

			Object value = new Integer(100);
			item.putValue(value);

			System.out.println("----- item info -----");
			System.out.println("VariableName: " + item.getSettingData(new Integer(0)));
			System.out.println("Value: " + item.getValue().toString());
			System.out.println("Updated: " + item.getDateTime().toString());

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (item != null) item.release();
			if (ctrl != null) ctrl.release();
			if (eng != null) eng.release();
		}
	}

	private synchronized void sleep(int time) {
		try {
			wait(time);
		} catch(InterruptedException e) {
		}
	}
}