<?xml version = "1.0" encoding = "UTF-8"?>
<!DOCTYPE project PUBLIC "-//Brains2b.org//Project v0.31" "http://www.brains2b.org/project/v0.31/project.dtd">
<?xml-stylesheet type="text/xsl" href="http://www.brains2b.org/project/v0.31/project.xsl"?>

<project trackerid="10">
	<name>DataC</name>
	<version>1.02</version>
	<status>stable</status>
	<startdate>21-03-2008</startdate>
	<description>Component which supplies data control to Java applications </description>
	<longdescription>
	DataC is just a bunch of interfaces and abstract classes, which don't look very exciting. Their job is defining
	a standard Data Modification interface for use in applications. The purpose in design was to have my applications
	deal with the data objects only and not bother about how, why or when these data objects where actually stored.
	</longdescription>
	<type>Component</type>
	<image>component.png</image>
	<language name="java" version="1.4+" /> 
	<usage>
	One of the quickest way to get started using this DataC interface is by using <a href="../sql2class/project.html">sql2class</a>
	to generate the data classes from your database and implement a data controller as in the example underneath. This DataController
	is a singleton used for client-server applications. It uses reflection to find the appropriate DataControl calss and can be used to 
	send changed or new data objects to the database:<BR/>
	<code>Controller.getInstance().update(MyTable());</code> or <code>Controller.getInstance().insert(MyTable());</code> Selects are about
	as easy to define. Look at the <a href="javadoc/org/brains2b/data/Condition.html">javadoc</a> to see how to define queries with a <code>Condition</code> 
	object.
<code><pre>
import java.io.FileInputStream;
import java.lang.reflect.Constructor;
import java.sql.Connection;
import java.util.Properties;
import java.util.Vector;

import org.brains2b.data.Condition;
import org.brains2b.data.DataControl;
import org.brains2b.data.DataController;
import org.brains2b.sql.Connector;

public class Controller extends Connector implements DataController {

	private static Controller m_instance;
	
	protected Controller() {
		super();
		try {
			Properties prop = new Properties();
			prop.load(new FileInputStream("conf/connect.properties"));
			init(
				prop.getProperty("driver"),
				prop.getProperty("url"),
				prop.getProperty("user"),
				prop.getProperty("password"));
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	public static Controller getInstance() {
		if (m_instance == null) {
			m_instance = new Controller();
		}
		return m_instance;
	}
	
	public int update(Object o) throws Exception {
		DataControl dc = getControlObject(o);
		return dc.update();
	}

	public int insert(Object o) throws Exception {
		DataControl dc = getControlObject(o);
		return dc.insert();
	}

	public int delete(Object o) throws Exception {
		DataControl dc = getControlObject(o);
		return dc.delete();
	}

	public Object retrieve(Object o, Object condition) throws Exception {
		DataControl dc = getControlObject(o);
		Vector v = dc.retrieveList((Condition) condition);
		if (v==null) return null;
		return v.get(0);
	}
	

	public List retrieveList(Object o, Condition condition) throws Exception {
		DataControl dc = getControlObject(o);
		return dc.retrieveList((Condition) condition);
	}

	protected DataControl getControlObject(Object o) throws Exception {
		Class c = o.getClass();
		String dcName =
			c.getPackage().getName()
				+ "."
				+ c.getName().substring(c.getName().lastIndexOf(".") + 1)
				+ "DC";

		Class dcClass = c.getClassLoader().loadClass(dcName);
		Constructor[] cons = dcClass.getConstructors();
		Constructor con =
			dcClass.getConstructor(
				new Class[] { Connection.class, Object.class });
		return (DataControl) con.newInstance(
			new Object[] { getConnection(), o });
	}

}
</pre></code>
<p><i>Note:</i> You can do a lot more interesting things with DataC, look for instance at the <a href="javadoc/Cursor.html">Cursor</a> class,
I haven't had time to write proper HOW-TO's or examples for it, but on the other hand, you might be able to figure it out looking at the
javadoc and provided Unit tests</p>
	</usage>
	<references>
		<component name="Sql2Class" version="1.04+"/>
		<component name="Track" version="0.42+" offline="true" />
		<component name="Oyama" version="0.12+" offline="true" />
	</references>
	<dependencies>
			<component name="TwelBox" version="1.04+" />
			<component name="Squeler" version="1.02+" />
	</dependencies>
	<files>
		<file>
			<name>DataC 1.01</name>
			<date>21-03-2008</date>
			<zip>DataC-1.01.zip</zip>
			<zip-src>DataC-src-1.01.zip</zip-src>
			<tar>DataC-1.01.tar.gz</tar>
			<tar-src>DataC-src-1.01.tar.gz</tar-src>
		</file>
		<file>
			<name>DataC 0.30.1</name>
			<date>01-09-2004</date>
			<zip>DataC-0.30.1.zip</zip>
			<zip-src/>
			<tar>DataC-0.30.1.tar.gz</tar>
		</file>
		<file>
			<name>DataC 0.30</name>
			<date>17-04-2004</date>
			<zip>DataC-0.30.zip</zip>
			<zip-src/>
			<tar>DataC-0.30.tar.gz</tar>
		</file>
	</files>
	<releases>
		<new version="1.01">
			<item>Waldorf code-review changes</item>
			<item>Changes to the naming of the interfaces to be less database specific</item>
			<item>Support for Blob,Clob and streaming data-types in both generated classes and cursor</item>
		</new>
		<new version="0.30.1">
			<item>Speed up making cursor prototype for cursors not using parameters</item>
		</new>
		<new version="0.30">
			<item>Added javadoc and testclasses for all classes</item>
		</new>
	</releases>
</project>