DataC 1.02
Component which supplies data control to Java applications
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.
usage
One of the quickest way to get started using this DataC interface is by using sql2class
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 class and can be used to
send changed or new data objects to the database:
Controller.getInstance().update(MyTable()); or Controller.getInstance().insert(MyTable()); Selects are about
as easy to define. Look at the javadocto see how to define queries with a Condition
object.
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 });
}
}
Note: You can do a lot more interesting things with DataC, look for instance at the Cursor 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
dependencies
references
- Sql2Class 1.01+
- Track 0.42+
- Oyama 0.12+
files
| Name | Version | Date | binary | tar | source |
|---|---|---|---|---|---|
| DataC | 1.02 | Apr 19, 2025 | DataC-1.02.zip | DataC-1.02.tar.gz | DataC-src-1.02.zip |
| DataC | 1.01 | Dec 2, 2018 | DataC-1.01.zip | DataC-1.01.tar.gz | DataC-src-1.01.zip |
changelog
1.02
- Skip null function for insert (psql)
- Re-implementation of CursorData to accomodate original type
- Trim Strings coming from CHAR fields
- Use SelectDescriptor Before and After
- Changes for code to work with try-with-resource
- Fix for DcDelegate loading next page in hasNextPage()
- Make pageable public
- Fix using cursors with additional query
- Allow for update on cursor data in pageable list
- added FileDC interface
- Implemented new PageableList for SqlCursor
- Changes for new PageableList implementation
- Fix for limit on different SQL databases (from master)
- Added generalized Filter options to Condition
1.01
- Waldorf code-review changes
- Changes to the naming of the interfaces to be less database specific
- Support for Blob,Clob and streaming data-types in both generated classes and cursor
0.30.1
- Speed up making cursor prototype for cursors not using parameters
0.30
- Added javadoc and test classes for all classes