diff --git a/.classpath b/.classpath deleted file mode 100644 index 6f66079..0000000 --- a/.classpath +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 7b22260..0000000 --- a/.gitignore +++ /dev/null @@ -1,30 +0,0 @@ -.DS_Store -*~ - -local.properties -/BezierSQLib - -# ant-javac build directory -/bin/ - -# hide some results -documentation/* -distribution/* - -# XCode -build/ -*.mode1 -*.mode1v3 -*.mode2v3 -*.perspective -*.perspectivev3 -*.pbxuser - -# old stuff i can't seem to be able to delete -releases/ - -website/BezierSQLib/* -web-export/* -*/web-export/* -web-export -.idea/ diff --git a/.project b/.project deleted file mode 100644 index ba7a51a..0000000 --- a/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - sql-library-processing - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - - diff --git a/build.xml b/build.xml deleted file mode 100644 index 90c4d69..0000000 --- a/build.xml +++ /dev/null @@ -1,314 +0,0 @@ - - - - BezierSQLib (formerly SQLibrary) build file, based on Processing libraries build file. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Properties initialized. -src path ${src} -bin path ${bin} -Processing dir ${processing.dir} -processing Libraries ${libraries.dir} -java version ${javaVersion} - - - - - - - Start to build the library ... this is vers. ${versionNumber}, build #${build.number} on ${date} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/documentation/DeBezierDataSQL.html b/documentation/DeBezierDataSQL.html new file mode 100644 index 0000000..547d3d7 --- /dev/null +++ b/documentation/DeBezierDataSQL.html @@ -0,0 +1,279 @@ + + + + + + +DeBezierDataSQL (Javadocs: BezierSQLib (formerly SQLibrary)) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+Class DeBezierDataSQL

+
+java.lang.Object
+  extended by DeBezierDataSQL
+
+
+
+
public class DeBezierDataSQL
extends java.lang.Object
+ + +

+In Java classes in a package can not gain access to + classes outside any package through reflection. +

+ +

+


+ +

+ + + + + + + + + + + +
+Constructor Summary
DeBezierDataSQL() + +
+           
+  + + + + + + + + + + + + + + + +
+Method Summary
+static java.lang.Object[]getValuesFromObject(SQL db, + java.lang.reflect.Field[] fields, + java.lang.reflect.Method[] getters, + java.lang.Object object) + +
+           
+static voidsetFromRow(SQL db, + java.lang.Object object) + +
+           
+ + + + + + + +
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+DeBezierDataSQL

+
+public DeBezierDataSQL()
+
+
+ + + + + + + + +
+Method Detail
+ +

+setFromRow

+
+public static void setFromRow(SQL db,
+                              java.lang.Object object)
+
+
+
+
+
+
+ +

+getValuesFromObject

+
+public static java.lang.Object[] getValuesFromObject(SQL db,
+                                                     java.lang.reflect.Field[] fields,
+                                                     java.lang.reflect.Method[] getters,
+                                                     java.lang.Object object)
+
+
+
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+Processing library BezierSQLib (formerly SQLibrary) by Florian Jenett. (c) 2005 - 2012 + + diff --git a/documentation/allclasses-frame.html b/documentation/allclasses-frame.html new file mode 100644 index 0000000..632ac75 --- /dev/null +++ b/documentation/allclasses-frame.html @@ -0,0 +1,43 @@ + + + + + + +All Classes (Javadocs: BezierSQLib (formerly SQLibrary)) + + + + + + + + + + + +All Classes +
+ + + + + +
DeBezierDataSQL +
+MySQL +
+NameMapper +
+PostgreSQL +
+SQL +
+SQLite +
+UnderScoreToCamelCaseMapper +
+
+ + + diff --git a/documentation/allclasses-noframe.html b/documentation/allclasses-noframe.html new file mode 100644 index 0000000..53f38e4 --- /dev/null +++ b/documentation/allclasses-noframe.html @@ -0,0 +1,43 @@ + + + + + + +All Classes (Javadocs: BezierSQLib (formerly SQLibrary)) + + + + + + + + + + + +All Classes +
+ + + + + +
DeBezierDataSQL +
+MySQL +
+NameMapper +
+PostgreSQL +
+SQL +
+SQLite +
+UnderScoreToCamelCaseMapper +
+
+ + + diff --git a/documentation/constant-values.html b/documentation/constant-values.html new file mode 100644 index 0000000..43c592b --- /dev/null +++ b/documentation/constant-values.html @@ -0,0 +1,144 @@ + + + + + + +Constant Field Values (Javadocs: BezierSQLib (formerly SQLibrary)) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+
+

+Constant Field Values

+
+
+Contents + +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+Processing library BezierSQLib (formerly SQLibrary) by Florian Jenett. (c) 2005 - 2012 + + diff --git a/documentation/de/bezier/data/sql/MySQL.html b/documentation/de/bezier/data/sql/MySQL.html new file mode 100644 index 0000000..497393c --- /dev/null +++ b/documentation/de/bezier/data/sql/MySQL.html @@ -0,0 +1,333 @@ + + + + + + +MySQL (Javadocs: BezierSQLib (formerly SQLibrary)) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +de.bezier.data.sql +
+Class MySQL

+
+java.lang.Object
+  extended by de.bezier.data.sql.SQL
+      extended by de.bezier.data.sql.MySQL
+
+
+
+
public class MySQL
extends SQL
+ + +

+MySQL wrapper for SQL library for Processing 2+ +

+ A wrapper around some of sun's java.sql.* classes + and the "com.mysql.jdbc.Driver" driver by mysql.com (GPL). +

+ see: + - http://www.mysql.com/products/connector/j/ + - http://java.sun.com/products/jdbc/ +

+ +

+

+
Author:
+
Florian Jenett - mail@florianjenett.de + + created: 07.05.2005 - 12:46 Uhr + modified: 2012-02
+
+
+ +

+ + + + + + + +
+Field Summary
+ + + + + + + +
Fields inherited from class de.bezier.data.sql.SQL
connection, database, driver, previousQuery, result, server, statement, type, url, user
+  + + + + + + + + + + + + + +
+Constructor Summary
MySQL(processing.core.PApplet _papplet, + java.lang.String _database) + +
+           
MySQL(processing.core.PApplet _papplet, + java.lang.String _server, + java.lang.String _database, + java.lang.String _user, + java.lang.String _pass) + +
+          Creates a new MySQL connection.
+  + + + + + + + + + + + +
+Method Summary
+ java.lang.String[]getTableNames() + +
+          Get names of available tables in active database, + needs to be implemented per db adapter.
+ + + + + + + +
Methods inherited from class de.bezier.data.sql.SQL
close, connect, dispose, escape, execute, execute, getBigDecimal, getBigDecimal, getBoolean, getBoolean, getColumnNames, getConnection, getDate, getDate, getDebug, getDouble, getDouble, getDriverVersion, getFloat, getFloat, getInt, getInt, getLong, getLong, getNameMapper, getObject, getObject, getString, getString, getTime, getTime, getTimestamp, getTimestamp, insertUpdateInDatabase, nameToGetter, nameToSetter, next, query, query, registerTableNameForClass, saveToDatabase, saveToDatabase, setDebug, setFromRow, setNameMapper
+ + + + + + + +
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+MySQL

+
+public MySQL(processing.core.PApplet _papplet,
+             java.lang.String _database)
+
+
+
+ +

+MySQL

+
+public MySQL(processing.core.PApplet _papplet,
+             java.lang.String _server,
+             java.lang.String _database,
+             java.lang.String _user,
+             java.lang.String _pass)
+
+
Creates a new MySQL connection. +

+

+
Parameters:
_papplet - Normally you'd pass "this" in for your sketch
_server - The server running the database, try "localhost"
_database - Name of the database
_user - Username for that database
_pass - Password for user
+
+ + + + + + + + +
+Method Detail
+ +

+getTableNames

+
+public java.lang.String[] getTableNames()
+
+
Description copied from class: SQL
+
Get names of available tables in active database, + needs to be implemented per db adapter. +

+

+
Specified by:
getTableNames in class SQL
+
+
+ +
Returns:
String[] The table names
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+Processing library BezierSQLib (formerly SQLibrary) by Florian Jenett. (c) 2005 - 2012 + + diff --git a/documentation/de/bezier/data/sql/PostgreSQL.html b/documentation/de/bezier/data/sql/PostgreSQL.html new file mode 100644 index 0000000..4bcbd4e --- /dev/null +++ b/documentation/de/bezier/data/sql/PostgreSQL.html @@ -0,0 +1,343 @@ + + + + + + +PostgreSQL (Javadocs: BezierSQLib (formerly SQLibrary)) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +de.bezier.data.sql +
+Class PostgreSQL

+
+java.lang.Object
+  extended by de.bezier.data.sql.SQL
+      extended by de.bezier.data.sql.PostgreSQL
+
+
+
+
public class PostgreSQL
extends SQL
+ + +

+PostgreSQL wrapper for SQL library for Processing 2+ +

+ This is a wrapper around some of sun's java.sql.* classes + and the "org.postgresql.Driver" driver by postgresql.org (BSD). +

+ see: + + PostgreSQL on OS-X (i used a mix of these on 10.5.x): + PostgreSQL documentation is at: +

+ +

+

+
Author:
+
Florian Jenett - mail@florianjenett.de + + created: 2008-11-29 17:49:23 - fjenett + modified: fjenett 2012-02
+
+
+ +

+ + + + + + + +
+Field Summary
+ + + + + + + +
Fields inherited from class de.bezier.data.sql.SQL
connection, database, driver, previousQuery, result, server, statement, type, url, user
+  + + + + + + + + + + + + + +
+Constructor Summary
PostgreSQL(processing.core.PApplet _papplet, + java.lang.String _database) + +
+           
PostgreSQL(processing.core.PApplet _papplet, + java.lang.String _server, + java.lang.String _database, + java.lang.String _user, + java.lang.String _pass) + +
+          Creates a new PostgreSQL connection.
+  + + + + + + + + + + + +
+Method Summary
+ java.lang.String[]getTableNames() + +
+          Get names of available tables in active database, + needs to be implemented per db adapter.
+ + + + + + + +
Methods inherited from class de.bezier.data.sql.SQL
close, connect, dispose, escape, execute, execute, getBigDecimal, getBigDecimal, getBoolean, getBoolean, getColumnNames, getConnection, getDate, getDate, getDebug, getDouble, getDouble, getDriverVersion, getFloat, getFloat, getInt, getInt, getLong, getLong, getNameMapper, getObject, getObject, getString, getString, getTime, getTime, getTimestamp, getTimestamp, insertUpdateInDatabase, nameToGetter, nameToSetter, next, query, query, registerTableNameForClass, saveToDatabase, saveToDatabase, setDebug, setFromRow, setNameMapper
+ + + + + + + +
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+PostgreSQL

+
+public PostgreSQL(processing.core.PApplet _papplet,
+                  java.lang.String _database)
+
+
+
+ +

+PostgreSQL

+
+public PostgreSQL(processing.core.PApplet _papplet,
+                  java.lang.String _server,
+                  java.lang.String _database,
+                  java.lang.String _user,
+                  java.lang.String _pass)
+
+
Creates a new PostgreSQL connection. +

+

+
Parameters:
_papplet - Normally you'd pass "this" in for your sketch
_server - The server running the database, try "localhost"
_database - Name of the database
_user - Username for that database
_pass - Password for user
+
+ + + + + + + + +
+Method Detail
+ +

+getTableNames

+
+public java.lang.String[] getTableNames()
+
+
Description copied from class: SQL
+
Get names of available tables in active database, + needs to be implemented per db adapter. +

+

+
Specified by:
getTableNames in class SQL
+
+
+ +
Returns:
String[] The table names
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+Processing library BezierSQLib (formerly SQLibrary) by Florian Jenett. (c) 2005 - 2012 + + diff --git a/documentation/de/bezier/data/sql/SQL.html b/documentation/de/bezier/data/sql/SQL.html new file mode 100644 index 0000000..52fdeac --- /dev/null +++ b/documentation/de/bezier/data/sql/SQL.html @@ -0,0 +1,1606 @@ + + + + + + +SQL (Javadocs: BezierSQLib (formerly SQLibrary)) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +de.bezier.data.sql +
+Class SQL

+
+java.lang.Object
+  extended by de.bezier.data.sql.SQL
+
+
+
Direct Known Subclasses:
MySQL, PostgreSQL, SQLite
+
+
+
+
public abstract class SQL
extends java.lang.Object
+ + +

+

SQL library for Processing 2+

+ + Since v 0.2.0 it has some ORM like features, see + + + Links: +

+ +

+

+
Author:
+
Florian Jenett - mail@florianjenett.de + + created: 07.05.2005 - 12:46 Uhr + modified: fjenett 20121217
+
+
+ +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+Field Summary
+ java.sql.Connectionconnection + +
+           
+ java.lang.Stringdatabase + +
+           
+ java.lang.Stringdriver + +
+           
+ java.lang.StringpreviousQuery + +
+           
+ java.sql.ResultSetresult + +
+           
+ java.lang.Stringserver + +
+           
+ java.sql.Statementstatement + +
+           
+ java.lang.Stringtype + +
+           
+ java.lang.Stringurl + +
+           
+ java.lang.Stringuser + +
+           
+  + + + + + + + + + + + + + + + + +
+Constructor Summary
SQL() + +
+          Do not use this contructor.
SQL(processing.core.PApplet _pa, + java.lang.String _db) + +
+          You should not directly use the SQL.class instead use the classes for your database type.
SQL(processing.core.PApplet _pa, + java.lang.String _serv, + java.lang.String _db, + java.lang.String _u, + java.lang.String _p) + +
+          You should not directly use the SQL.class instead use the classes for your database type.
+  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+Method Summary
+ voidclose() + +
+          Close the database connection
+ booleanconnect() + +
+          Open the database connection with the parameters given in the contructor.
+ voiddispose() + +
+          Callback function for PApplet.registerDispose()
+ java.lang.Stringescape(java.lang.Object o) + +
+          Generate an escaped String for a given Object
+ voidexecute(java.lang.String _sql) + +
+          Execute a SQL command on the open database connection.
+ voidexecute(java.lang.String _sql, + java.lang.Object... args) + +
+          Execute a SQL command on the open database connection.
+ java.math.BigDecimalgetBigDecimal(int _column) + +
+          Read a java.math.BigDecimal value from the specified field.
+ java.math.BigDecimalgetBigDecimal(java.lang.String _field) + +
+          Read a java.math.BigDecimal value from the specified field.
+ booleangetBoolean(int _column) + +
+          Read a boolean value from the specified field.
+ booleangetBoolean(java.lang.String _field) + +
+          Read a boolean value from the specified field.
+ java.lang.String[]getColumnNames() + +
+          Returns an array with the column names of the last request.
+ java.sql.ConnectiongetConnection() + +
+          Get connection.
+ java.sql.DategetDate(int _column) + +
+          Read a java.sql.Date value from the specified field.
+ java.sql.DategetDate(java.lang.String _field) + +
+          Read a java.sql.Date value from the specified field.
+ booleangetDebug() + +
+          Get current debugging setting
+ doublegetDouble(int _column) + +
+          Read a double value from the specified field.
+ doublegetDouble(java.lang.String _field) + +
+          Read a double value from the specified field.
+ java.lang.StringgetDriverVersion() + +
+          Return the version of the currently active JDBC driver
+ floatgetFloat(int _column) + +
+          Read a float value from the specified field.
+ floatgetFloat(java.lang.String _field) + +
+          Read a float value from the specified field.
+ intgetInt(int _column) + +
+          Read an integer value from the specified field.
+ intgetInt(java.lang.String _field) + +
+          Read an integer value from the specified field.
+ longgetLong(int _column) + +
+          Read a long value from the specified field.
+ longgetLong(java.lang.String _field) + +
+          Read a long value from the specified field.
+ NameMappergetNameMapper() + +
+          Get the current NameMapper
+ java.lang.ObjectgetObject(int _column) + +
+          Read a value from the specified field to hav it returned as an object.
+ java.lang.ObjectgetObject(java.lang.String _field) + +
+          Read a value from the specified field to hav it returned as an object.
+ java.lang.StringgetString(int _column) + +
+          Read a String value from the specified field.
+ java.lang.StringgetString(java.lang.String _field) + +
+          Read a String value from the specified field.
+abstract  java.lang.String[]getTableNames() + +
+          Get names of available tables in active database, + needs to be implemented per db adapter.
+ java.sql.TimegetTime(int _column) + +
+          Read a java.sql.Time value from the specified field.
+ java.sql.TimegetTime(java.lang.String _field) + +
+          Read a java.sql.Time value from the specified field.
+ java.sql.TimestampgetTimestamp(int _column) + +
+          Read a java.sql.Timestamp value from the specified field.
+ java.sql.TimestampgetTimestamp(java.lang.String _field) + +
+          Read a java.sql.Timestamp value from the specified field.
+ voidinsertUpdateInDatabase(java.lang.String tableName, + java.lang.String[] columnNames, + java.lang.Object[] values) + +
+          Insert or update a bunch of values in the database.
+ java.lang.StringnameToGetter(java.lang.String name) + +
+          Convert a field name to a getter name: fieldName -> getFieldName().
+ java.lang.StringnameToSetter(java.lang.String name) + +
+          Convert a field name to a setter name: fieldName -> setFieldName().
+ booleannext() + +
+          Check if more results (rows) are available.
+ voidquery(java.lang.String _sql) + +
+          Issue a query on the open database connection
+ voidquery(java.lang.String _sql, + java.lang.Object... args) + +
+          Issue a query on the open database connection.
+ voidregisterTableNameForClass(java.lang.String name, + java.lang.Object classOrObject) + +
+          Set a table name for a class.
+ voidsaveToDatabase(java.lang.Object object) + +
+          Take an object, try to find table name from object name (or look it up), + get fields and getters from object and pass that on to + insertUpdateIntoDatabase(table, columns, values).
+ voidsaveToDatabase(java.lang.String tableName, + java.lang.Object object) + +
+          Takes a table name and an object and tries to construct a set of + columns names from fields and getters found in the object.
+ voidsetDebug(boolean yesNo) + +
+          Turn some debugging on/off.
+ voidsetFromRow(java.lang.Object object) + +
+          Highly experimental ...
+ tries to map column names to public fields or setter methods + in the given object.
+ voidsetNameMapper(NameMapper mapper) + +
+          Set the current NameMapper
+ + + + + + + +
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Field Detail
+ +

+server

+
+public java.lang.String server
+
+
+
+
+
+ +

+database

+
+public java.lang.String database
+
+
+
+
+
+ +

+url

+
+public java.lang.String url
+
+
+
+
+
+ +

+user

+
+public java.lang.String user
+
+
+
+
+
+ +

+driver

+
+public java.lang.String driver
+
+
+
+
+
+ +

+type

+
+public java.lang.String type
+
+
+
+
+
+ +

+connection

+
+public java.sql.Connection connection
+
+
+
+
+
+ +

+previousQuery

+
+public java.lang.String previousQuery
+
+
+
+
+
+ +

+statement

+
+public java.sql.Statement statement
+
+
+
+
+
+ +

+result

+
+public java.sql.ResultSet result
+
+
+
+
+ + + + + + + + +
+Constructor Detail
+ +

+SQL

+
+public SQL()
+
+
Do not use this contructor. +

+

+
+ +

+SQL

+
+public SQL(processing.core.PApplet _pa,
+           java.lang.String _db)
+
+
You should not directly use the SQL.class instead use the classes for your database type. +

+

+
+ +

+SQL

+
+public SQL(processing.core.PApplet _pa,
+           java.lang.String _serv,
+           java.lang.String _db,
+           java.lang.String _u,
+           java.lang.String _p)
+
+
You should not directly use the SQL.class instead use the classes for your database type. +

+

+ + + + + + + + +
+Method Detail
+ +

+setDebug

+
+public void setDebug(boolean yesNo)
+
+
Turn some debugging on/off. +

+

+
Parameters:
yesNo - Turn it on or off
+
+
+
+ +

+getDebug

+
+public boolean getDebug()
+
+
Get current debugging setting +

+

+
Parameters:
yesNo - Turn it on or off
+
+
+
+ +

+connect

+
+public boolean connect()
+
+
Open the database connection with the parameters given in the contructor. +

+

+
+
+
+
+ +

+getDriverVersion

+
+public java.lang.String getDriverVersion()
+
+
Return the version of the currently active JDBC driver +

+

+ +
Returns:
String The version of the current driver
+
+
+
+ +

+execute

+
+public void execute(java.lang.String _sql)
+
+
Execute a SQL command on the open database connection. +

+

+
Parameters:
_sql - The SQL command to execute
+
+
+
+ +

+execute

+
+public void execute(java.lang.String _sql,
+                    java.lang.Object... args)
+
+
Execute a SQL command on the open database connection. + Arguments are passed to String.format() first. +

+

+
Parameters:
_sql - SQL command as pattern for String.format()
args - Zero or more objects to be passed to String.format()
See Also:
Format syntax, +String.format(java.lang.String,java.lang.Object...)
+
+
+
+ +

+query

+
+public void query(java.lang.String _sql)
+
+
Issue a query on the open database connection +

+

+
Parameters:
_sql - SQL command to execute for the query
+
+
+
+ +

+query

+
+public void query(java.lang.String _sql,
+                  java.lang.Object... args)
+
+
Issue a query on the open database connection. + Arguments are passed to String.format() first. +

+

+
Parameters:
_sql - SQL command as pattern for String.format()
args - Zero or more objects to be passed to String.format()
See Also:
Format syntax, +String.format(java.lang.String,java.lang.Object...)
+
+
+
+ +

+next

+
+public boolean next()
+
+
Check if more results (rows) are available. This needs to be called before any results can be retrieved. +

+

+ +
Returns:
boolean true if more results are available, false otherwise
+
+
+
+ +

+getTableNames

+
+public abstract java.lang.String[] getTableNames()
+
+
Get names of available tables in active database, + needs to be implemented per db adapter. +

+

+ +
Returns:
String[] The table names
+
+
+
+ +

+getColumnNames

+
+public java.lang.String[] getColumnNames()
+
+
Returns an array with the column names of the last request. +

+

+ +
Returns:
String[] the column names of last result or null
+
+
+
+ +

+getConnection

+
+public java.sql.Connection getConnection()
+
+
Get connection. ... in case you want to do JDBC stuff directly. +

+

+ +
Returns:
java.sql.Connection The connection
+
+
+
+ +

+getInt

+
+public int getInt(java.lang.String _field)
+
+
Read an integer value from the specified field. + Represents an INT / INTEGER type: + http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html + "8.9.6 Conversions by ResultSet.getXXX Methods" +

+

+
Parameters:
_field - The name of the field +
Returns:
int Value of the field or 0
+
+
+
+ +

+getInt

+
+public int getInt(int _column)
+
+
Read an integer value from the specified field. + Represents an INT / INTEGER type: + http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html + "8.9.6 Conversions by ResultSet.getXXX Methods" +

+

+
Parameters:
_column - The column index of the field to read +
Returns:
int Value of the field or 0
+
+
+
+ +

+getLong

+
+public long getLong(java.lang.String _field)
+
+
Read a long value from the specified field. + Represents a BIGINT type: + http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html + "8.9.6 Conversions by ResultSet.getXXX Methods" +

+

+
Parameters:
_field - The name of the field +
Returns:
long Value of the field or 0
+
+
+
+ +

+getLong

+
+public long getLong(int _column)
+
+
Read a long value from the specified field. + Represents a BIGINT type: + http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html + "8.9.6 Conversions by ResultSet.getXXX Methods" +

+

+
Parameters:
_column - The column index of the field +
Returns:
long Value of the field or 0
+
+
+
+ +

+getFloat

+
+public float getFloat(java.lang.String _field)
+
+
Read a float value from the specified field. + Represents a REAL type: + http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html + "8.9.6 Conversions by ResultSet.getXXX Methods" +

+

+
Parameters:
_field - The name of the field +
Returns:
float Value of the field or 0
+
+
+
+ +

+getFloat

+
+public float getFloat(int _column)
+
+
Read a float value from the specified field. + Represents a REAL type: + http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html + "8.9.6 Conversions by ResultSet.getXXX Methods" +

+

+
Parameters:
_column - The index of the column of the field +
Returns:
float Value of the field or 0
+
+
+
+ +

+getDouble

+
+public double getDouble(java.lang.String _field)
+
+
Read a double value from the specified field. + Represents FLOAT and DOUBLE types: + http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html + "8.9.6 Conversions by ResultSet.getXXX Methods" +

+

+
Parameters:
_field - The name of the field +
Returns:
double Value of the field or 0
+
+
+
+ +

+getDouble

+
+public double getDouble(int _column)
+
+
Read a double value from the specified field. + Represents FLOAT and DOUBLE types: + http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html + "8.9.6 Conversions by ResultSet.getXXX Methods" +

+

+
Parameters:
_column - The column index of the field +
Returns:
double Value of the field or 0
+
+
+
+ +

+getBigDecimal

+
+public java.math.BigDecimal getBigDecimal(java.lang.String _field)
+
+
Read a java.math.BigDecimal value from the specified field. + Represents DECIMAL and NUMERIC types: + http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html + "8.9.6 Conversions by ResultSet.getXXX Methods" +

+

+
Parameters:
_field - The name of the field +
Returns:
java.math.BigDecimal Value of the field or null
+
+
+
+ +

+getBigDecimal

+
+public java.math.BigDecimal getBigDecimal(int _column)
+
+
Read a java.math.BigDecimal value from the specified field. + Represents DECIMAL and NUMERIC types: + http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html + "8.9.6 Conversions by ResultSet.getXXX Methods" +

+

+
Parameters:
_column - The column index of the field +
Returns:
java.math.BigDecimal Value of the field or null
+
+
+
+ +

+getBoolean

+
+public boolean getBoolean(java.lang.String _field)
+
+
Read a boolean value from the specified field. + Represents BIT type: + http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html + "8.9.6 Conversions by ResultSet.getXXX Methods" +

+

+
Parameters:
_field - The name of the field +
Returns:
boolean Value of the field or 0
+
+
+
+ +

+getBoolean

+
+public boolean getBoolean(int _column)
+
+
Read a boolean value from the specified field. + Represents BIT type: + http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html + "8.9.6 Conversions by ResultSet.getXXX Methods" +

+

+
Parameters:
_column - The column index of the field +
Returns:
boolean Value of the field or 0
+
+
+
+ +

+getString

+
+public java.lang.String getString(java.lang.String _field)
+
+
Read a String value from the specified field. + Represents VARCHAR and CHAR types: + http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html + "8.9.6 Conversions by ResultSet.getXXX Methods" +

+

+
Parameters:
_field - The name of the field +
Returns:
String Value of the field or null
+
+
+
+ +

+getString

+
+public java.lang.String getString(int _column)
+
+
Read a String value from the specified field. + Represents VARCHAR and CHAR types: + http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html + "8.9.6 Conversions by ResultSet.getXXX Methods" +

+

+
Parameters:
_column - The column index of the field +
Returns:
String Value of the field or null
+
+
+
+ +

+getDate

+
+public java.sql.Date getDate(java.lang.String _field)
+
+
Read a java.sql.Date value from the specified field. + Represents DATE type: + http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html + "8.9.6 Conversions by ResultSet.getXXX Methods" +

+

+
Parameters:
_field - The name of the field +
Returns:
java.sql.Date Value of the field or null
+
+
+
+ +

+getDate

+
+public java.sql.Date getDate(int _column)
+
+
Read a java.sql.Date value from the specified field. + Represents DATE type: + http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html + "8.9.6 Conversions by ResultSet.getXXX Methods" +

+

+
Parameters:
_column - The column index of the field +
Returns:
java.sql.Date Value of the field or null
+
+
+
+ +

+getTime

+
+public java.sql.Time getTime(java.lang.String _field)
+
+
Read a java.sql.Time value from the specified field. + Represents TIME type: + http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html + "8.9.6 Conversions by ResultSet.getXXX Methods" +

+

+
Parameters:
_field - The name of the field +
Returns:
java.sql.Time Value of the field or null
+
+
+
+ +

+getTime

+
+public java.sql.Time getTime(int _column)
+
+
Read a java.sql.Time value from the specified field. + Represents TIME type: + http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html + "8.9.6 Conversions by ResultSet.getXXX Methods" +

+

+
Parameters:
_column - The column index of the field +
Returns:
java.sql.Time Value of the field or null
+
+
+
+ +

+getTimestamp

+
+public java.sql.Timestamp getTimestamp(java.lang.String _field)
+
+
Read a java.sql.Timestamp value from the specified field. + Represents TIMESTAMP type: + http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html + "8.9.6 Conversions by ResultSet.getXXX Methods" +

+

+
Parameters:
_field - The name of the field +
Returns:
java.sql.Timestamp Value of the field or null
+
+
+
+ +

+getTimestamp

+
+public java.sql.Timestamp getTimestamp(int _column)
+
+
Read a java.sql.Timestamp value from the specified field. + Represents TIMESTAMP type: + http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html + "8.9.6 Conversions by ResultSet.getXXX Methods" +

+

+
Parameters:
_column - The column index of the field +
Returns:
java.sql.Timestamp Value of the field or null
+
+
+
+ +

+getObject

+
+public java.lang.Object getObject(java.lang.String _field)
+
+
Read a value from the specified field to hav it returned as an object. +

+

+
Parameters:
_field - The name of the field +
Returns:
Object Value of the field or null
+
+
+
+ +

+getObject

+
+public java.lang.Object getObject(int _column)
+
+
Read a value from the specified field to hav it returned as an object. +

+

+
Parameters:
_column - The column index of the field +
Returns:
Object Value of the field or null
+
+
+
+ +

+close

+
+public void close()
+
+
Close the database connection +

+

+
+
+
+
+ +

+dispose

+
+public void dispose()
+
+
Callback function for PApplet.registerDispose() +

+

+
See Also:
processing.core.PApplet.registerDispose(java.lang.Object)
+
+
+
+ +

+escape

+
+public java.lang.String escape(java.lang.Object o)
+
+
Generate an escaped String for a given Object +

+

+
Parameters:
object - the Object to escape +
Returns:
String the ecaped String representation of the Object
+
+
+
+ +

+setNameMapper

+
+public void setNameMapper(NameMapper mapper)
+
+
Set the current NameMapper +

+

+
Parameters:
mapper - the name mapper
See Also:
NameMapper
+
+
+
+ +

+getNameMapper

+
+public NameMapper getNameMapper()
+
+
Get the current NameMapper +

+

+
See Also:
NameMapper
+
+
+
+ +

+setFromRow

+
+public void setFromRow(java.lang.Object object)
+
+

Highly experimental ...
+ tries to map column names to public fields or setter methods + in the given object.

+ +

Use like so: +

+        db.query("SELECT name, id, sometime FROM table");
+
+        while ( db.next() ) {
+                SomeObject obj = new SomeObject();
+                db.setFromRow(obj);
+                // obj.name is now same as db.getString("name"), etc. 
+  }
+  

+ +

SomeObject might look like: +

+        class SomeObject {
+                public String name;
+                public int id;
+                Date sometime;
+        }
+        

+

+

+
Parameters:
object - The object to populate from the currently selected row
+
+
+
+ +

+nameToSetter

+
+public java.lang.String nameToSetter(java.lang.String name)
+
+
Convert a field name to a setter name: fieldName -> setFieldName(). +

+

+
+
+
+
+ +

+nameToGetter

+
+public java.lang.String nameToGetter(java.lang.String name)
+
+
Convert a field name to a getter name: fieldName -> getFieldName(). +

+

+
+
+
+
+ +

+registerTableNameForClass

+
+public void registerTableNameForClass(java.lang.String name,
+                                      java.lang.Object classOrObject)
+
+
Set a table name for a class. +

+

+
+
+
+
+ +

+saveToDatabase

+
+public void saveToDatabase(java.lang.Object object)
+
+
Take an object, try to find table name from object name (or look it up), + get fields and getters from object and pass that on to + insertUpdateIntoDatabase(table, columns, values). +

+

+
Parameters:
object - Object The object to save to db
See Also:
insertUpdateInDatabase(java.lang.String, java.lang.String[], java.lang.Object[])
+
+
+
+ +

+saveToDatabase

+
+public void saveToDatabase(java.lang.String tableName,
+                           java.lang.Object object)
+
+
Takes a table name and an object and tries to construct a set of + columns names from fields and getters found in the object. After + the values are fetched from the object all is passed to + insertUpdateIntoDatabase(). +

+

+
Parameters:
tableName - String The name of the table
object - Object The object to look at
See Also:
insertUpdateInDatabase(java.lang.String, java.lang.String[], java.lang.Object[])
+
+
+
+ +

+insertUpdateInDatabase

+
+public void insertUpdateInDatabase(java.lang.String tableName,
+                                   java.lang.String[] columnNames,
+                                   java.lang.Object[] values)
+
+
Insert or update a bunch of values in the database. If the given table has a + primary key the entry will be updated if it already existed. +

+

+
Parameters:
tableName - String The name of the table
columnNames - String[] The names of the columns to fill or update
values - Object[] The values to instert or update
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+Processing library BezierSQLib (formerly SQLibrary) by Florian Jenett. (c) 2005 - 2012 + + diff --git a/documentation/de/bezier/data/sql/SQLite.html b/documentation/de/bezier/data/sql/SQLite.html new file mode 100644 index 0000000..2a6bb80 --- /dev/null +++ b/documentation/de/bezier/data/sql/SQLite.html @@ -0,0 +1,339 @@ + + + + + + +SQLite (Javadocs: BezierSQLib (formerly SQLibrary)) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +de.bezier.data.sql +
+Class SQLite

+
+java.lang.Object
+  extended by de.bezier.data.sql.SQL
+      extended by de.bezier.data.sql.SQLite
+
+
+
+
public class SQLite
extends SQL
+ + +

+SQLite wrapper for SQL library for Processing 2+ +

+ A wrapper around some of sun's java.sql.* classes + and the pure java "org.sqlite.JDBC" driver of the Xerial project (Apache 2 license). +

+ see: +

+ +

+

+
Author:
+
Florian Jenett - mail@florianjenett.de + + created: 2008-11-29 12:15:15 - fjenett + modified: fjenett 20121217
+
+
+ +

+ + + + + + + +
+Field Summary
+ + + + + + + +
Fields inherited from class de.bezier.data.sql.SQL
connection, database, driver, previousQuery, result, server, statement, type, url, user
+  + + + + + + + + + + + + + +
+Constructor Summary
SQLite(processing.core.PApplet _papplet, + java.lang.String _database) + +
+          Creates a new SQLite connection.
SQLite(processing.core.PApplet _papplet, + java.lang.String _server, + java.lang.String _database, + java.lang.String _user, + java.lang.String _pass) + +
+          Creates a new SQLite connection, same as SQLite( PApplet, String )
+  + + + + + + + + + + + +
+Method Summary
+ java.lang.String[]getTableNames() + +
+          Get names of available tables in active database, + needs to be implemented per db adapter.
+ + + + + + + +
Methods inherited from class de.bezier.data.sql.SQL
close, connect, dispose, escape, execute, execute, getBigDecimal, getBigDecimal, getBoolean, getBoolean, getColumnNames, getConnection, getDate, getDate, getDebug, getDouble, getDouble, getDriverVersion, getFloat, getFloat, getInt, getInt, getLong, getLong, getNameMapper, getObject, getObject, getString, getString, getTime, getTime, getTimestamp, getTimestamp, insertUpdateInDatabase, nameToGetter, nameToSetter, next, query, query, registerTableNameForClass, saveToDatabase, saveToDatabase, setDebug, setFromRow, setNameMapper
+ + + + + + + +
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+SQLite

+
+public SQLite(processing.core.PApplet _papplet,
+              java.lang.String _database)
+
+
Creates a new SQLite connection. +

+

+
Parameters:
_papplet - Your sketch, pass "this" in here
_database - Path to the database file, if this is just a name the data and sketch folders are searched for the file
+
+
+ +

+SQLite

+
+public SQLite(processing.core.PApplet _papplet,
+              java.lang.String _server,
+              java.lang.String _database,
+              java.lang.String _user,
+              java.lang.String _pass)
+
+
Creates a new SQLite connection, same as SQLite( PApplet, String ) +

+

+
Parameters:
_papplet - Your sketch, pass "this" in here
_server - Ignored
_database - Path to the database file, if this is just a name the data and sketch folders are searched for the file
_user - Ignored
_pass - Ignored
+
+ + + + + + + + +
+Method Detail
+ +

+getTableNames

+
+public java.lang.String[] getTableNames()
+
+
Description copied from class: SQL
+
Get names of available tables in active database, + needs to be implemented per db adapter. +

+

+
Specified by:
getTableNames in class SQL
+
+
+ +
Returns:
String[] The table names
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+Processing library BezierSQLib (formerly SQLibrary) by Florian Jenett. (c) 2005 - 2012 + + diff --git a/documentation/de/bezier/data/sql/mapper/NameMapper.html b/documentation/de/bezier/data/sql/mapper/NameMapper.html new file mode 100644 index 0000000..f112ce7 --- /dev/null +++ b/documentation/de/bezier/data/sql/mapper/NameMapper.html @@ -0,0 +1,243 @@ + + + + + + +NameMapper (Javadocs: BezierSQLib (formerly SQLibrary)) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +de.bezier.data.sql.mapper +
+Interface NameMapper

+
+
All Known Implementing Classes:
UnderScoreToCamelCaseMapper
+
+
+
+
public interface NameMapper
+ + +

+NameMapper is used to map database names to instance names + When setting objects from objects with SQL.setFromRow(). + + This is just an interface and only one implementation is + provided in form of the default UnderScoreToCamelCaseMapper + which does: field_name -> fieldName and vv. +

+ +

+


+ +

+ + + + + + + + + + + + + + + + +
+Method Summary
+ java.lang.Stringbackward(java.lang.String name) + +
+          Reverse of forward, maps object names to database + names like: fieldName -> field_name.
+ java.lang.Stringforward(java.lang.String name) + +
+          Maps a database name to an object name, typically + this might look like: field_name -> fieldName.
+  +

+ + + + + + + + +
+Method Detail
+ +

+forward

+
+java.lang.String forward(java.lang.String name)
+
+
Maps a database name to an object name, typically + this might look like: field_name -> fieldName. +

+

+
+
+
+
+ +

+backward

+
+java.lang.String backward(java.lang.String name)
+
+
Reverse of forward, maps object names to database + names like: fieldName -> field_name. +

+

+
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+Processing library BezierSQLib (formerly SQLibrary) by Florian Jenett. (c) 2005 - 2012 + + diff --git a/documentation/de/bezier/data/sql/mapper/UnderScoreToCamelCaseMapper.html b/documentation/de/bezier/data/sql/mapper/UnderScoreToCamelCaseMapper.html new file mode 100644 index 0000000..066b1dd --- /dev/null +++ b/documentation/de/bezier/data/sql/mapper/UnderScoreToCamelCaseMapper.html @@ -0,0 +1,314 @@ + + + + + + +UnderScoreToCamelCaseMapper (Javadocs: BezierSQLib (formerly SQLibrary)) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+ +

+ +de.bezier.data.sql.mapper +
+Class UnderScoreToCamelCaseMapper

+
+java.lang.Object
+  extended by de.bezier.data.sql.mapper.UnderScoreToCamelCaseMapper
+
+
+
All Implemented Interfaces:
NameMapper
+
+
+
+
public class UnderScoreToCamelCaseMapper
extends java.lang.Object
implements NameMapper
+ + +

+UnderScoreToCamelCaseMapper, does as it says. +

+ +

+


+ +

+ + + + + + + + + + + +
+Constructor Summary
UnderScoreToCamelCaseMapper() + +
+           
+  + + + + + + + + + + + + + + + + + + + +
+Method Summary
+ java.lang.Stringbackward(java.lang.String name) + +
+          Reverse of forward, maps object names to database + names like: fieldName -> field_name.
+ java.lang.Stringforward(java.lang.String name) + +
+          Maps a database name to an object name, typically + this might look like: field_name -> fieldName.
+static voidmain(java.lang.String... args) + +
+           
+ + + + + + + +
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+  +

+ + + + + + + + +
+Constructor Detail
+ +

+UnderScoreToCamelCaseMapper

+
+public UnderScoreToCamelCaseMapper()
+
+
+ + + + + + + + +
+Method Detail
+ +

+backward

+
+public java.lang.String backward(java.lang.String name)
+
+
Description copied from interface: NameMapper
+
Reverse of forward, maps object names to database + names like: fieldName -> field_name. +

+

+
Specified by:
backward in interface NameMapper
+
+
+
+
+
+
+ +

+forward

+
+public java.lang.String forward(java.lang.String name)
+
+
Description copied from interface: NameMapper
+
Maps a database name to an object name, typically + this might look like: field_name -> fieldName. +

+

+
Specified by:
forward in interface NameMapper
+
+
+
+
+
+
+ +

+main

+
+public static void main(java.lang.String... args)
+
+
+
+
+
+
+
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+Processing library BezierSQLib (formerly SQLibrary) by Florian Jenett. (c) 2005 - 2012 + + diff --git a/documentation/de/bezier/data/sql/mapper/package-frame.html b/documentation/de/bezier/data/sql/mapper/package-frame.html new file mode 100644 index 0000000..842634b --- /dev/null +++ b/documentation/de/bezier/data/sql/mapper/package-frame.html @@ -0,0 +1,43 @@ + + + + + + +de.bezier.data.sql.mapper (Javadocs: BezierSQLib (formerly SQLibrary)) + + + + + + + + + + + +de.bezier.data.sql.mapper + + + + +
+Interfaces  + +
+NameMapper
+ + + + + + +
+Classes  + +
+UnderScoreToCamelCaseMapper
+ + + + diff --git a/documentation/de/bezier/data/sql/mapper/package-summary.html b/documentation/de/bezier/data/sql/mapper/package-summary.html new file mode 100644 index 0000000..a4c9662 --- /dev/null +++ b/documentation/de/bezier/data/sql/mapper/package-summary.html @@ -0,0 +1,170 @@ + + + + + + +de.bezier.data.sql.mapper (Javadocs: BezierSQLib (formerly SQLibrary)) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+

+Package de.bezier.data.sql.mapper +

+ + + + + + + + + +
+Interface Summary
NameMapperNameMapper is used to map database names to instance names + When setting objects from objects with SQL.setFromRow().
+  + +

+ + + + + + + + + +
+Class Summary
UnderScoreToCamelCaseMapperUnderScoreToCamelCaseMapper, does as it says.
+  + +

+

+
+
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+Processing library BezierSQLib (formerly SQLibrary) by Florian Jenett. (c) 2005 - 2012 + + diff --git a/documentation/de/bezier/data/sql/mapper/package-tree.html b/documentation/de/bezier/data/sql/mapper/package-tree.html new file mode 100644 index 0000000..1c033b1 --- /dev/null +++ b/documentation/de/bezier/data/sql/mapper/package-tree.html @@ -0,0 +1,157 @@ + + + + + + +de.bezier.data.sql.mapper Class Hierarchy (Javadocs: BezierSQLib (formerly SQLibrary)) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+
+

+Hierarchy For Package de.bezier.data.sql.mapper +

+
+
+
Package Hierarchies:
All Packages
+
+

+Class Hierarchy +

+ +

+Interface Hierarchy +

+ +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+Processing library BezierSQLib (formerly SQLibrary) by Florian Jenett. (c) 2005 - 2012 + + diff --git a/documentation/de/bezier/data/sql/package-frame.html b/documentation/de/bezier/data/sql/package-frame.html new file mode 100644 index 0000000..1c65d2a --- /dev/null +++ b/documentation/de/bezier/data/sql/package-frame.html @@ -0,0 +1,38 @@ + + + + + + +de.bezier.data.sql (Javadocs: BezierSQLib (formerly SQLibrary)) + + + + + + + + + + + +de.bezier.data.sql + + + + +
+Classes  + +
+MySQL +
+PostgreSQL +
+SQL +
+SQLite
+ + + + diff --git a/documentation/de/bezier/data/sql/package-summary.html b/documentation/de/bezier/data/sql/package-summary.html new file mode 100644 index 0000000..5b7b6f3 --- /dev/null +++ b/documentation/de/bezier/data/sql/package-summary.html @@ -0,0 +1,167 @@ + + + + + + +de.bezier.data.sql (Javadocs: BezierSQLib (formerly SQLibrary)) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+

+Package de.bezier.data.sql +

+ + + + + + + + + + + + + + + + + + + + + +
+Class Summary
MySQLMySQL wrapper for SQL library for Processing 2+
PostgreSQLPostgreSQL wrapper for SQL library for Processing 2+
SQLSQL library for Processing 2+
SQLiteSQLite wrapper for SQL library for Processing 2+
+  + +

+

+
+
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+Processing library BezierSQLib (formerly SQLibrary) by Florian Jenett. (c) 2005 - 2012 + + diff --git a/documentation/de/bezier/data/sql/package-tree.html b/documentation/de/bezier/data/sql/package-tree.html new file mode 100644 index 0000000..296dc4f --- /dev/null +++ b/documentation/de/bezier/data/sql/package-tree.html @@ -0,0 +1,153 @@ + + + + + + +de.bezier.data.sql Class Hierarchy (Javadocs: BezierSQLib (formerly SQLibrary)) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+
+

+Hierarchy For Package de.bezier.data.sql +

+
+
+
Package Hierarchies:
All Packages
+
+

+Class Hierarchy +

+ +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+Processing library BezierSQLib (formerly SQLibrary) by Florian Jenett. (c) 2005 - 2012 + + diff --git a/documentation/deprecated-list.html b/documentation/deprecated-list.html new file mode 100644 index 0000000..a297c60 --- /dev/null +++ b/documentation/deprecated-list.html @@ -0,0 +1,144 @@ + + + + + + +Deprecated List (Javadocs: BezierSQLib (formerly SQLibrary)) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+
+

+Deprecated API

+
+
+Contents + +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+Processing library BezierSQLib (formerly SQLibrary) by Florian Jenett. (c) 2005 - 2012 + + diff --git a/documentation/help-doc.html b/documentation/help-doc.html new file mode 100644 index 0000000..6d2f3af --- /dev/null +++ b/documentation/help-doc.html @@ -0,0 +1,217 @@ + + + + + + +API Help (Javadocs: BezierSQLib (formerly SQLibrary)) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+
+

+How This API Document Is Organized

+
+This API (Application Programming Interface) document has pages corresponding to the items in the navigation bar, described as follows.

+Overview

+
+ +

+The Overview page is the front page of this API document and provides a list of all packages with a summary for each. This page can also contain an overall description of the set of packages.

+

+Package

+
+ +

+Each package has a page that contains a list of its classes and interfaces, with a summary for each. This page can contain four categories:

+
+

+Class/Interface

+
+ +

+Each class, interface, nested class and nested interface has its own separate page. Each of these pages has three sections consisting of a class/interface description, summary tables, and detailed member descriptions:

+Each summary entry contains the first sentence from the detailed description for that item. The summary entries are alphabetical, while the detailed descriptions are in the order they appear in the source code. This preserves the logical groupings established by the programmer.
+ +

+Annotation Type

+
+ +

+Each annotation type has its own separate page with the following sections:

+
+ +

+Enum

+
+ +

+Each enum has its own separate page with the following sections:

+
+

+Tree (Class Hierarchy)

+
+There is a Class Hierarchy page for all packages, plus a hierarchy for each package. Each hierarchy page contains a list of classes and a list of interfaces. The classes are organized by inheritance structure starting with java.lang.Object. The interfaces do not inherit from java.lang.Object. +
+

+Deprecated API

+
+The Deprecated API page lists all of the API that have been deprecated. A deprecated API is not recommended for use, generally due to improvements, and a replacement API is usually given. Deprecated APIs may be removed in future implementations.
+

+Index

+
+The Index contains an alphabetic list of all classes, interfaces, constructors, methods, and fields.
+

+Prev/Next

+These links take you to the next or previous class, interface, package, or related page.

+Frames/No Frames

+These links show and hide the HTML frames. All pages are available with or without frames. +

+

+Serialized Form

+Each serializable or externalizable class has a description of its serialization fields and methods. This information is of interest to re-implementors, not to developers using the API. While there is no link in the navigation bar, you can get to this information by going to any serialized class and clicking "Serialized Form" in the "See also" section of the class description. +

+

+Constant Field Values

+The Constant Field Values page lists the static final fields and their values. +

+ + +This help file applies to API documentation generated using the standard doclet. + +
+


+ + + + + + + + + + + + + + + +
+ +
+ + + +
+Processing library BezierSQLib (formerly SQLibrary) by Florian Jenett. (c) 2005 - 2012 + + diff --git a/documentation/index-all.html b/documentation/index-all.html new file mode 100644 index 0000000..9cf9d92 --- /dev/null +++ b/documentation/index-all.html @@ -0,0 +1,451 @@ + + + + + + +Index (Javadocs: BezierSQLib (formerly SQLibrary)) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ + + +B C D E F G I M N P Q R S T U
+

+B

+
+
backward(String) - +Method in interface de.bezier.data.sql.mapper.NameMapper +
Reverse of forward, maps object names to database + names like: fieldName -> field_name. +
backward(String) - +Method in class de.bezier.data.sql.mapper.UnderScoreToCamelCaseMapper +
  +
+
+

+C

+
+
close() - +Method in class de.bezier.data.sql.SQL +
Close the database connection +
connect() - +Method in class de.bezier.data.sql.SQL +
Open the database connection with the parameters given in the contructor. +
connection - +Variable in class de.bezier.data.sql.SQL +
  +
+
+

+D

+
+
database - +Variable in class de.bezier.data.sql.SQL +
  +
de.bezier.data.sql - package de.bezier.data.sql
 
de.bezier.data.sql.mapper - package de.bezier.data.sql.mapper
 
DeBezierDataSQL - Class in <Unnamed>
In Java classes in a package can not gain access to + classes outside any package through reflection.
DeBezierDataSQL() - +Constructor for class DeBezierDataSQL +
  +
dispose() - +Method in class de.bezier.data.sql.SQL +
Callback function for PApplet.registerDispose() +
driver - +Variable in class de.bezier.data.sql.SQL +
  +
+
+

+E

+
+
escape(Object) - +Method in class de.bezier.data.sql.SQL +
Generate an escaped String for a given Object +
execute(String) - +Method in class de.bezier.data.sql.SQL +
Execute a SQL command on the open database connection. +
execute(String, Object...) - +Method in class de.bezier.data.sql.SQL +
Execute a SQL command on the open database connection. +
+
+

+F

+
+
forward(String) - +Method in interface de.bezier.data.sql.mapper.NameMapper +
Maps a database name to an object name, typically + this might look like: field_name -> fieldName. +
forward(String) - +Method in class de.bezier.data.sql.mapper.UnderScoreToCamelCaseMapper +
  +
+
+

+G

+
+
getBigDecimal(String) - +Method in class de.bezier.data.sql.SQL +
Read a java.math.BigDecimal value from the specified field. +
getBigDecimal(int) - +Method in class de.bezier.data.sql.SQL +
Read a java.math.BigDecimal value from the specified field. +
getBoolean(String) - +Method in class de.bezier.data.sql.SQL +
Read a boolean value from the specified field. +
getBoolean(int) - +Method in class de.bezier.data.sql.SQL +
Read a boolean value from the specified field. +
getColumnNames() - +Method in class de.bezier.data.sql.SQL +
Returns an array with the column names of the last request. +
getConnection() - +Method in class de.bezier.data.sql.SQL +
Get connection. +
getDate(String) - +Method in class de.bezier.data.sql.SQL +
Read a java.sql.Date value from the specified field. +
getDate(int) - +Method in class de.bezier.data.sql.SQL +
Read a java.sql.Date value from the specified field. +
getDebug() - +Method in class de.bezier.data.sql.SQL +
Get current debugging setting +
getDouble(String) - +Method in class de.bezier.data.sql.SQL +
Read a double value from the specified field. +
getDouble(int) - +Method in class de.bezier.data.sql.SQL +
Read a double value from the specified field. +
getDriverVersion() - +Method in class de.bezier.data.sql.SQL +
Return the version of the currently active JDBC driver +
getFloat(String) - +Method in class de.bezier.data.sql.SQL +
Read a float value from the specified field. +
getFloat(int) - +Method in class de.bezier.data.sql.SQL +
Read a float value from the specified field. +
getInt(String) - +Method in class de.bezier.data.sql.SQL +
Read an integer value from the specified field. +
getInt(int) - +Method in class de.bezier.data.sql.SQL +
Read an integer value from the specified field. +
getLong(String) - +Method in class de.bezier.data.sql.SQL +
Read a long value from the specified field. +
getLong(int) - +Method in class de.bezier.data.sql.SQL +
Read a long value from the specified field. +
getNameMapper() - +Method in class de.bezier.data.sql.SQL +
Get the current NameMapper +
getObject(String) - +Method in class de.bezier.data.sql.SQL +
Read a value from the specified field to hav it returned as an object. +
getObject(int) - +Method in class de.bezier.data.sql.SQL +
Read a value from the specified field to hav it returned as an object. +
getString(String) - +Method in class de.bezier.data.sql.SQL +
Read a String value from the specified field. +
getString(int) - +Method in class de.bezier.data.sql.SQL +
Read a String value from the specified field. +
getTableNames() - +Method in class de.bezier.data.sql.MySQL +
  +
getTableNames() - +Method in class de.bezier.data.sql.PostgreSQL +
  +
getTableNames() - +Method in class de.bezier.data.sql.SQL +
Get names of available tables in active database, + needs to be implemented per db adapter. +
getTableNames() - +Method in class de.bezier.data.sql.SQLite +
  +
getTime(String) - +Method in class de.bezier.data.sql.SQL +
Read a java.sql.Time value from the specified field. +
getTime(int) - +Method in class de.bezier.data.sql.SQL +
Read a java.sql.Time value from the specified field. +
getTimestamp(String) - +Method in class de.bezier.data.sql.SQL +
Read a java.sql.Timestamp value from the specified field. +
getTimestamp(int) - +Method in class de.bezier.data.sql.SQL +
Read a java.sql.Timestamp value from the specified field. +
getValuesFromObject(SQL, Field[], Method[], Object) - +Static method in class DeBezierDataSQL +
  +
+
+

+I

+
+
insertUpdateInDatabase(String, String[], Object[]) - +Method in class de.bezier.data.sql.SQL +
Insert or update a bunch of values in the database. +
+
+

+M

+
+
main(String...) - +Static method in class de.bezier.data.sql.mapper.UnderScoreToCamelCaseMapper +
  +
MySQL - Class in de.bezier.data.sql
MySQL wrapper for SQL library for Processing 2+
MySQL(PApplet, String) - +Constructor for class de.bezier.data.sql.MySQL +
  +
MySQL(PApplet, String, String, String, String) - +Constructor for class de.bezier.data.sql.MySQL +
Creates a new MySQL connection. +
+
+

+N

+
+
NameMapper - Interface in de.bezier.data.sql.mapper
NameMapper is used to map database names to instance names + When setting objects from objects with SQL.setFromRow().
nameToGetter(String) - +Method in class de.bezier.data.sql.SQL +
Convert a field name to a getter name: fieldName -> getFieldName(). +
nameToSetter(String) - +Method in class de.bezier.data.sql.SQL +
Convert a field name to a setter name: fieldName -> setFieldName(). +
next() - +Method in class de.bezier.data.sql.SQL +
Check if more results (rows) are available. +
+
+

+P

+
+
PostgreSQL - Class in de.bezier.data.sql
PostgreSQL wrapper for SQL library for Processing 2+
PostgreSQL(PApplet, String) - +Constructor for class de.bezier.data.sql.PostgreSQL +
  +
PostgreSQL(PApplet, String, String, String, String) - +Constructor for class de.bezier.data.sql.PostgreSQL +
Creates a new PostgreSQL connection. +
previousQuery - +Variable in class de.bezier.data.sql.SQL +
  +
+
+

+Q

+
+
query(String) - +Method in class de.bezier.data.sql.SQL +
Issue a query on the open database connection +
query(String, Object...) - +Method in class de.bezier.data.sql.SQL +
Issue a query on the open database connection. +
+
+

+R

+
+
registerTableNameForClass(String, Object) - +Method in class de.bezier.data.sql.SQL +
Set a table name for a class. +
result - +Variable in class de.bezier.data.sql.SQL +
  +
+
+

+S

+
+
saveToDatabase(Object) - +Method in class de.bezier.data.sql.SQL +
Take an object, try to find table name from object name (or look it up), + get fields and getters from object and pass that on to + insertUpdateIntoDatabase(table, columns, values). +
saveToDatabase(String, Object) - +Method in class de.bezier.data.sql.SQL +
Takes a table name and an object and tries to construct a set of + columns names from fields and getters found in the object. +
server - +Variable in class de.bezier.data.sql.SQL +
  +
setDebug(boolean) - +Method in class de.bezier.data.sql.SQL +
Turn some debugging on/off. +
setFromRow(Object) - +Method in class de.bezier.data.sql.SQL +
Highly experimental ...
+ tries to map column names to public fields or setter methods + in the given object. +
setFromRow(SQL, Object) - +Static method in class DeBezierDataSQL +
  +
setNameMapper(NameMapper) - +Method in class de.bezier.data.sql.SQL +
Set the current NameMapper +
SQL - Class in de.bezier.data.sql
SQL library for Processing 2+
SQL() - +Constructor for class de.bezier.data.sql.SQL +
Do not use this contructor. +
SQL(PApplet, String) - +Constructor for class de.bezier.data.sql.SQL +
You should not directly use the SQL.class instead use the classes for your database type. +
SQL(PApplet, String, String, String, String) - +Constructor for class de.bezier.data.sql.SQL +
You should not directly use the SQL.class instead use the classes for your database type. +
SQLite - Class in de.bezier.data.sql
SQLite wrapper for SQL library for Processing 2+
SQLite(PApplet, String) - +Constructor for class de.bezier.data.sql.SQLite +
Creates a new SQLite connection. +
SQLite(PApplet, String, String, String, String) - +Constructor for class de.bezier.data.sql.SQLite +
Creates a new SQLite connection, same as SQLite( PApplet, String ) +
statement - +Variable in class de.bezier.data.sql.SQL +
  +
+
+

+T

+
+
type - +Variable in class de.bezier.data.sql.SQL +
  +
+
+

+U

+
+
UnderScoreToCamelCaseMapper - Class in de.bezier.data.sql.mapper
UnderScoreToCamelCaseMapper, does as it says.
UnderScoreToCamelCaseMapper() - +Constructor for class de.bezier.data.sql.mapper.UnderScoreToCamelCaseMapper +
  +
url - +Variable in class de.bezier.data.sql.SQL +
  +
user - +Variable in class de.bezier.data.sql.SQL +
  +
+
+B C D E F G I M N P Q R S T U + + + + + + + + + + + + + + +
+ +
+ + + +
+Processing library BezierSQLib (formerly SQLibrary) by Florian Jenett. (c) 2005 - 2012 + + diff --git a/documentation/index.html b/documentation/index.html new file mode 100644 index 0000000..48b1c9a --- /dev/null +++ b/documentation/index.html @@ -0,0 +1,39 @@ + + + + + + +Javadocs: BezierSQLib (formerly SQLibrary) + + + + + + + + + + + +<H2> +Frame Alert</H2> + +<P> +This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. +<BR> +Link to<A HREF="overview-summary.html">Non-frame version.</A> + + + diff --git a/documentation/overview-frame.html b/documentation/overview-frame.html new file mode 100644 index 0000000..d0e8234 --- /dev/null +++ b/documentation/overview-frame.html @@ -0,0 +1,46 @@ + + + + + + +Overview List (Javadocs: BezierSQLib (formerly SQLibrary)) + + + + + + + + + + + + + + + +
+
+ + + + + +
All Classes +

+ +Packages +
+<unnamed package> +
+de.bezier.data.sql +
+de.bezier.data.sql.mapper +
+

+ +

+  + + diff --git a/documentation/overview-summary.html b/documentation/overview-summary.html new file mode 100644 index 0000000..d531da1 --- /dev/null +++ b/documentation/overview-summary.html @@ -0,0 +1,158 @@ + + + + + + +Overview (Javadocs: BezierSQLib (formerly SQLibrary)) + + + + + + + + + + + + +


+ + + + + + + + + + + + + + + +
+ +
+ + + +
+
+

+Javadocs: BezierSQLib +

+
+ + + + + + + + + + + + + +
+Packages
de.bezier.data.sql 
de.bezier.data.sql.mapper 
+ +


+ + + + + + + + + + + + + + + +
+ +
+ + + +
+Processing library BezierSQLib (formerly SQLibrary) by Florian Jenett. (c) 2005 - 2012 + + diff --git a/documentation/overview-tree.html b/documentation/overview-tree.html new file mode 100644 index 0000000..c7827b0 --- /dev/null +++ b/documentation/overview-tree.html @@ -0,0 +1,158 @@ + + + + + + +Class Hierarchy (Javadocs: BezierSQLib (formerly SQLibrary)) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+
+

+Hierarchy For All Packages

+
+
+
Package Hierarchies:
de.bezier.data.sql, de.bezier.data.sql.mapper
+
+

+Class Hierarchy +

+ +

+Interface Hierarchy +

+ +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+Processing library BezierSQLib (formerly SQLibrary) by Florian Jenett. (c) 2005 - 2012 + + diff --git a/documentation/package-frame.html b/documentation/package-frame.html new file mode 100644 index 0000000..7dde9fa --- /dev/null +++ b/documentation/package-frame.html @@ -0,0 +1,32 @@ + + + + + + +<Unnamed> (Javadocs: BezierSQLib (formerly SQLibrary)) + + + + + + + + + + + +<Unnamed> + + + + +
+Classes  + +
+DeBezierDataSQL
+ + + + diff --git a/documentation/package-list b/documentation/package-list new file mode 100644 index 0000000..1afec4e --- /dev/null +++ b/documentation/package-list @@ -0,0 +1,3 @@ + +de.bezier.data.sql +de.bezier.data.sql.mapper diff --git a/documentation/package-summary.html b/documentation/package-summary.html new file mode 100644 index 0000000..da9a249 --- /dev/null +++ b/documentation/package-summary.html @@ -0,0 +1,156 @@ + + + + + + + (Javadocs: BezierSQLib (formerly SQLibrary)) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+

+Package <Unnamed> +

+ + + + + + + + + +
+Class Summary
DeBezierDataSQLIn Java classes in a package can not gain access to + classes outside any package through reflection.
+  + +

+

+
+
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+Processing library BezierSQLib (formerly SQLibrary) by Florian Jenett. (c) 2005 - 2012 + + diff --git a/documentation/package-tree.html b/documentation/package-tree.html new file mode 100644 index 0000000..d802b29 --- /dev/null +++ b/documentation/package-tree.html @@ -0,0 +1,151 @@ + + + + + + + Class Hierarchy (Javadocs: BezierSQLib (formerly SQLibrary)) + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+
+

+Hierarchy For Package <Unnamed> +

+
+
+
Package Hierarchies:
All Packages
+
+

+Class Hierarchy +

+ +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
+Processing library BezierSQLib (formerly SQLibrary) by Florian Jenett. (c) 2005 - 2012 + + diff --git a/documentation/resources/inherit.gif b/documentation/resources/inherit.gif new file mode 100644 index 0000000..c814867 Binary files /dev/null and b/documentation/resources/inherit.gif differ diff --git a/resources/stylesheet.css b/documentation/stylesheet.css similarity index 100% rename from resources/stylesheet.css rename to documentation/stylesheet.css diff --git a/lib/sqlite-jdbc-3.7.2.jar b/download/BezierSQLib-0.2.0.zip similarity index 65% rename from lib/sqlite-jdbc-3.7.2.jar rename to download/BezierSQLib-0.2.0.zip index b0bec7b..c792eef 100644 Binary files a/lib/sqlite-jdbc-3.7.2.jar and b/download/BezierSQLib-0.2.0.zip differ diff --git a/examples/MySQL_example1.zip b/examples/MySQL_example1.zip new file mode 100644 index 0000000..129fd70 Binary files /dev/null and b/examples/MySQL_example1.zip differ diff --git a/examples/MySQL_example1/MySQL_example1.pde b/examples/MySQL_example1/MySQL_example1.pde index f165dbb..22e9641 100644 --- a/examples/MySQL_example1/MySQL_example1.pde +++ b/examples/MySQL_example1/MySQL_example1.pde @@ -1,14 +1,10 @@ -/** - * MySQL example 1 - * https://github.com/fjenett/sql-library-processing - * - * created 2005-05-10 by fjenett - * updated fjenett 20130718 - * tested with Processing 2.0.x - */ - import de.bezier.data.sql.*; + +// created 2005-05-10 by fjenett +// updated fjenett 20081129 + + MySQL msql; @@ -17,40 +13,33 @@ void setup() size( 100, 100 ); // this example assumes that you are running the - // mysql server locally (on "localhost") - - // 1 - // replace your mysql login: - - String user = "sql_user"; - String pass = "sql_pass"; - - // 2 + // mysql server locally (on "localhost"). + // + + // replace --username--, --password-- with your mysql-account. + // + String user = "root"; + String pass = "admin"; + // name of the database to use - - String database = "sql_library_test_db"; - + // + String database = "bildwelt"; // add additional parameters like this: - // sql_library_test_db?useUnicode=true&characterEncoding=UTF-8 - - // 3 + // bildwelt?useUnicode=true&characterEncoding=UTF-8 + // connect to database of server "localhost" - + // msql = new MySQL( this, "localhost", database, user, pass ); if ( msql.connect() ) { - msql.query( "SELECT COUNT(*) FROM %s", "example1" ); + msql.query( "SELECT COUNT(*) FROM image" ); msql.next(); - println( "this table has " + msql.getInt(1) + " number of rows" ); + println( "number of rows: " + msql.getInt(1) ); } else { // connection failed ! - - // - check your login, password - // - check that your server runs on localhost and that the port is set right - // - try connecting through other means (terminal or console / MySQL workbench / ...) } } diff --git a/examples/MySQL_example1/sketch.properties b/examples/MySQL_example1/sketch.properties deleted file mode 100644 index 8630fa2..0000000 --- a/examples/MySQL_example1/sketch.properties +++ /dev/null @@ -1,2 +0,0 @@ -mode.id=processing.mode.java.JavaMode -mode=Java diff --git a/examples/MySQL_example2.zip b/examples/MySQL_example2.zip new file mode 100644 index 0000000..8e2c073 Binary files /dev/null and b/examples/MySQL_example2.zip differ diff --git a/examples/MySQL_example3.zip b/examples/MySQL_example3.zip new file mode 100644 index 0000000..0eec95f Binary files /dev/null and b/examples/MySQL_example3.zip differ diff --git a/examples/MySQL_localhost_example/MySQL_localhost_example.pde b/examples/MySQL_localhost_example/MySQL_localhost_example.pde deleted file mode 100644 index c6bfeb3..0000000 --- a/examples/MySQL_localhost_example/MySQL_localhost_example.pde +++ /dev/null @@ -1,37 +0,0 @@ -// Library by fjenett -// Example created on 2014-03-12 by Powder -// Tested with Processing 3.0a5 - -import de.bezier.data.sql.*; - -String dbHost = "localhost"; // if you are using a using a local database, this should be fine -String dbPort = "8889"; // replace with database port, MAMP standard is 8889 -String dbUser = "root"; // replace with database username, MAMP standard is "root" -String dbPass = "root"; // replace with database password, MAMP standard is "root" -String dbName = "database_name"; // replace with database name -String tableName = "table_name"; // replace with table name - -MySQL msql; - -void setup() { - msql = new MySQL( this, dbHost + ":" + dbPort, dbName, dbUser, dbPass ); - - if (msql.connect()) { - // get number of rows - msql.query("SELECT COUNT(*) FROM " + tableName); - msql.next(); - println("Number of rows: " + msql.getInt(1)); - println(); - - // access table - msql.query("SELECT * FROM " + tableName); - while (msql.next()){ - // replace "first_name" and "last_name" with column names from your table - String s1 = msql.getString("first_name"); - String s2 = msql.getString("last_name"); - println(s1 + " " + s2); - } - } else { - println("Yikes, there was an error!"); - } -} diff --git a/examples/MySQL_timestamp.zip b/examples/MySQL_timestamp.zip new file mode 100644 index 0000000..8fcf4f5 Binary files /dev/null and b/examples/MySQL_timestamp.zip differ diff --git a/examples/PostgreSQL_example1.zip b/examples/PostgreSQL_example1.zip new file mode 100644 index 0000000..d6b3a5e Binary files /dev/null and b/examples/PostgreSQL_example1.zip differ diff --git a/examples/SQLite_example1.zip b/examples/SQLite_example1.zip new file mode 100644 index 0000000..682fe56 Binary files /dev/null and b/examples/SQLite_example1.zip differ diff --git a/examples/SQLite_example2.zip b/examples/SQLite_example2.zip new file mode 100644 index 0000000..d26e5e7 Binary files /dev/null and b/examples/SQLite_example2.zip differ diff --git a/resources/web/index.html b/index.html similarity index 74% rename from resources/web/index.html rename to index.html index 1c06e44..fb4a414 100644 --- a/resources/web/index.html +++ b/index.html @@ -2,15 +2,15 @@ - ##yourLibrary## version ##versionNumber## - by ##author## + BezierSQLib version 0.2.0 - by Florian Jenett - + - + @@ -20,8 +20,8 @@

@@ -43,10 +43,10 @@

##yourLibrary##

-

##yourLibrary##

+

BezierSQLib

a library for the programming environment processing.
- last update, ##date##. + last update, 12/17/2012.

SQLibrary lets you communicate with a MySQL, PostgreSQL or SQLite databases. @@ -63,7 +63,7 @@

##yourLibrary##

Download

- Get ##yourLibrary## version ##versionNumber## in .zip format + Get BezierSQLib version 0.2.0 in .zip format

Installation

@@ -74,7 +74,7 @@

Installation

Installation in Processing 2.0 should be as easy as opening the "Library Manager" from the menu at:
- Sketch > Import Library ... > Add Library ... > (select ##yourLibrary## and click "install") + Sketch > Import Library ... > Add Library ... > (select BezierSQLib and click "install")

Manual installation (Processing 1.5 and earlier): @@ -82,9 +82,9 @@

Installation

  • Quit processing
  • Find your sketchbook folder, see second paragraph here
  • Add a folder called libraries (lowercase) to your sketchbook if its not already there
  • -
  • Move the ##yourLibrary##-##versionNumber##.zip into that libraries folder
  • +
  • Move the BezierSQLib-0.2.0.zip into that libraries folder
  • Unzip it in place
  • -
  • Rename it to ##yourLibrary##
  • +
  • Rename it to BezierSQLib
  • Start processing and run one of the included examples to see if the lib is working
  • @@ -92,7 +92,7 @@

    Installation

    -

    Keywords: ##keywords## +

    Keywords: MySQL, SQLite, PostgreSQL, SQL, database

    Documentation is online here and included in the download.

    @@ -107,9 +107,9 @@

    Installation

    Examples

    - find a list of examples in the current distribution of ##yourLibrary##, or have a look at them by following the links below. + find a list of examples in the current distribution of BezierSQLib, or have a look at them by following the links below.

    @@ -153,12 +153,12 @@

    Used in:

    - Fork me on GitHub + Fork me on GitHub \ No newline at end of file diff --git a/lib/ant-contrib-1.0b3.jar b/lib/ant-contrib-1.0b3.jar deleted file mode 100644 index 0625376..0000000 Binary files a/lib/ant-contrib-1.0b3.jar and /dev/null differ diff --git a/lib/build.number b/lib/build.number deleted file mode 100644 index f535698..0000000 --- a/lib/build.number +++ /dev/null @@ -1,3 +0,0 @@ -#Build Number for ANT. Do not edit! -#Sun Jan 08 14:58:26 CET 2023 -build.number=599 diff --git a/lib/mysql-connector-j-8.0.31.jar b/lib/mysql-connector-j-8.0.31.jar deleted file mode 100644 index 8b74bb8..0000000 Binary files a/lib/mysql-connector-j-8.0.31.jar and /dev/null differ diff --git a/lib/postgresql-9.2-1002.jdbc3.jar b/lib/postgresql-9.2-1002.jdbc3.jar deleted file mode 100644 index e77b065..0000000 Binary files a/lib/postgresql-9.2-1002.jdbc3.jar and /dev/null differ diff --git a/readme.md b/readme.md deleted file mode 100755 index 1234d59..0000000 --- a/readme.md +++ /dev/null @@ -1,39 +0,0 @@ -This library wraps around JDBC drivers to let you access MySQL, SQLite and PostgreSQL databases. - -## Latest Release (0.3.2) - -This fork has been modified slightly for Processing 3. It's now available in the Contribution Manager in the PDE, or you can install manually by unzipping this folder into your libraries folder: -https://github.com/fjenett/sql-library-processing/raw/latest/release/BezierSQLib.zip - -## Features - -It's not an ORM (and will not become one) but it has some handy features -since v0.2.0 that makes it easier to load and save objects to a database. - - setFromRow(object) - saveToDatabase(object) - insertUpdateIntoDatabase(table, columns, values) - -See: -https://raw.github.com/fjenett/sql-library-processing/master/src/de/bezier/data/sql/SQL.java - -## Database Drivers - -Parts of this library are available under their own licenses. These are redistributed as downloaded from the original sources: - -MySQL Connector/J (JDBC driver) -mysql-connector-java-3.1.8-bin.jar -http://dev.mysql.com/downloads/connector/j/ -http://dev.mysql.com/downloads/connector/j/3.1.html -GPL, http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - -PostgreSQL JDBC driver -postgresql-8.3-604.jdbc3.jar -http://jdbc.postgresql.org/ -http://jdbc.postgresql.org/download.html -BSD, http://jdbc.postgresql.org/license.html - -SQLite JDBC driver -sqlite-jdbc-3.7.2.jar -http://code.google.com/p/sqlite-jdbc/ -Apache License 2.0, http://www.apache.org/licenses/LICENSE-2.0 diff --git a/release/BezierSQLib.txt b/release/BezierSQLib.txt deleted file mode 100644 index 3a9b7bf..0000000 --- a/release/BezierSQLib.txt +++ /dev/null @@ -1,8 +0,0 @@ -name = BezierSQLib -authorList = [Florian Jenett](http://www.bezier.de/) -url = https://github.com/fjenett/sql-library-processing -category = Data -sentence = A library to facilitate communication with SQL-based databases -paragraph = SQLibrary is an interface to MySQL, SQLite and PostgreSQL databases -version = 1192 -prettyVersion = 0.3.2 \ No newline at end of file diff --git a/release/BezierSQLib.zip b/release/BezierSQLib.zip deleted file mode 100644 index ce506cf..0000000 Binary files a/release/BezierSQLib.zip and /dev/null differ diff --git a/resources/build.number b/resources/build.number deleted file mode 100644 index 3464fae..0000000 --- a/resources/build.number +++ /dev/null @@ -1,3 +0,0 @@ -#Build Number for ANT. Do not edit! -#Sun Jan 08 14:58:26 CET 2023 -build.number=1194 diff --git a/resources/library.properties b/resources/library.properties deleted file mode 100644 index 22c2a11..0000000 --- a/resources/library.properties +++ /dev/null @@ -1,8 +0,0 @@ -name = @@LIBRARY_NAME@@ -authorList = [Florian Jenett](http://www.bezier.de/) -url = https://github.com/fjenett/sql-library-processing -category = Data -sentence = A library to facilitate communication with SQL-based databases -paragraph = SQLibrary is an interface to MySQL, SQLite and PostgreSQL databases -version = @@VERSION@@ -prettyVersion = @@PRETTY_VERSION@@ \ No newline at end of file diff --git a/src/DeBezierDataSQL.java b/src/DeBezierDataSQL.java deleted file mode 100644 index 79ccd22..0000000 --- a/src/DeBezierDataSQL.java +++ /dev/null @@ -1,153 +0,0 @@ -/** UNPACKAGED to be able to access unpackaged classes **/ - -import de.bezier.data.sql.*; -import de.bezier.data.sql.mapper.*; -import java.lang.reflect.*; - -/** - * Java classes in a package can not gain access to - * classes outside any package through Java's reflection. - * - * This class is a helper that can access other unpackaged - * classes (as Processing sketches are). - * - * de.bezier.data.SQL <-> DeBezierDataSQL <-> _unpackaged_class_ - * - * fjenett 2011 - */ - -public class DeBezierDataSQL -{ - public static void setFromRow ( SQL db, Object object ) - { - String[] colNames = db.getColumnNames(); - if ( colNames == null || colNames.length == 0 ) return; - - Class klass = object.getClass(); - for ( String colName : colNames ) - { - // translate the fieldname via mapper - - String fieldName = colName; - NameMapper mapper = db.getNameMapper(); - if ( mapper != null ) - { - fieldName = mapper.forward( colName ); - } - - // fetch value from DB - - Object val = null; - try { - val = db.getObject(colName); - } catch (Exception e) { - if (db.getDebug()) e.printStackTrace(); - } - if ( val == null ) { - if (db.getDebug()) { - System.err.println( "setFromRow(): Value is null" ); - System.err.println( colName ); - } - continue; // TODO warn here? - } - - // // try to make a clone of the value ..? - // - // Class vClass = val.getClass(); - // try { - // Method vMeth = vClass.getMethod("clone"); - // if ( vMeth != null && - // Modifier.isPublic(vMeth.getModifiers()) ) - // { - // Object tmp = vMeth.invoke(val); - // val = tmp; - // //if (DEBUG) System.out.println("Value cloned."); - // } - // } catch ( Exception ex ) { - // if (DEBUG) ex.printStackTrace(); - // } - - // - // try fields first - // obj.fieldName = value - - Field f = null; - try { - f = klass.getField( fieldName ); - } catch ( Exception e ) { - if (db.getDebug()) e.printStackTrace(); - } - if ( f != null ) - { - try { - f.set( object, val ); - continue; - } catch (Exception e) { - if (db.getDebug()) e.printStackTrace(); - } - } - - // - // try setter next .. - // obj.setFieldName( value ) - // obj.fieldName( value ) - - Method[] meths = null; - try { - meths = klass.getMethods(); - } catch ( Exception e ) { - if (db.getDebug()) e.printStackTrace(); - } - if ( meths != null && meths.length > 0 ) - { - String setterName = db.nameToSetter(fieldName); - //Class[] paramTypes = new Class[]{val.getClass()}; - for ( Method meth : meths ) - { - if ( meth.getName().equals(setterName) || - meth.getName().equals(fieldName) - /*&& meth.getParameterTypes().equals(paramTypes)*/ ) - { - //if (db.getDebug()) System.out.println( meth ); - try { - meth.invoke( object, new Object[]{val} ); - break; - } catch ( Exception e ) { - if (db.getDebug()) e.printStackTrace(); - } - } - } - } - } - } - - public static Object[] getValuesFromObject ( SQL db, Field[] fields, Method[] getters, Object object ) - { - if ( db == null || object == null ) return null; - if ( fields == null || getters == null ) return null; - if ( fields.length != getters.length ) return null; - - Object[] vals = new Object[fields.length]; - - for ( int i = 0; i < vals.length; i++ ) { - try { - if ( fields[i] != null ) - vals[i] = fields[i].get(object); - else if ( getters[i] != null ) - vals[i] = getters[i].invoke(object); - else - { - System.err.println(String.format( - "getValuesFromObject() : neither field nor getter given for a value." - )); - return null; - } - } catch ( Exception e ) { - e.printStackTrace(); - return null; - } - } - - return vals; - } -} \ No newline at end of file diff --git a/src/de/bezier/data/sql/MySQL.java b/src/de/bezier/data/sql/MySQL.java deleted file mode 100644 index d8fc019..0000000 --- a/src/de/bezier/data/sql/MySQL.java +++ /dev/null @@ -1,68 +0,0 @@ -package de.bezier.data.sql; - -import processing.core.*; -import java.util.ArrayList; - -/** - * MySQL wrapper for SQL library for Processing 2+ - *

    - * A wrapper around some of sun's java.sql.* classes - * and the "com.mysql.jdbc.Driver" driver by mysql.com (GPL). - *

    - * see: - * - http://www.mysql.com/products/connector/j/ - * - http://java.sun.com/products/jdbc/ - * - * - * @author Florian Jenett - mail@florianjenett.de - * - * created: 07.05.2005 - 12:46 Uhr - * modified: 2012-02 - * - */ - -public class MySQL -extends de.bezier.data.sql.SQL -{ - public MySQL ( PApplet _papplet, String _database ) - { - // should not be used - } - - /** - * Creates a new MySQL connection. - * - * @param _papplet Normally you'd pass "this" in for your sketch - * @param _server The server running the database, try "localhost" - * @param _database Name of the database - * @param _user Username for that database - * @param _pass Password for user - */ - - public MySQL ( PApplet _papplet, String _server, String _database, String _user, String _pass) - { - super( _papplet, _server, _database, _user, _pass ); - init(); - } - - private void init () - { - this.driver = "com.mysql.cj.jdbc.Driver"; - this.type = "mysql"; - - this.url = "jdbc:" + type + "://" + server + "/" + database; - } - - public String[] getTableNames () - { - if ( tableNames == null ) - { - tableNames = new ArrayList(); - query( "SHOW TABLES" ); - while ( next() ) { - tableNames.add( getObject("Tables_in_"+database).toString() ); - } - } - return tableNames.toArray(new String[0]); - } -} diff --git a/src/de/bezier/data/sql/PostgreSQL.java b/src/de/bezier/data/sql/PostgreSQL.java deleted file mode 100644 index 776f5d6..0000000 --- a/src/de/bezier/data/sql/PostgreSQL.java +++ /dev/null @@ -1,77 +0,0 @@ -package de.bezier.data.sql; - -import processing.core.*; -import java.util.ArrayList; - -/** - * PostgreSQL wrapper for SQL library for Processing 2+ - *

    - * This is a wrapper around some of sun's java.sql.* classes - * and the "org.postgresql.Driver" driver by postgresql.org (BSD). - *

    - * see:
      - *
    • http://jdbc.postgresql.org/download.html
    • - *
    • http://java.sun.com/products/jdbc/
    • - *
    - * - * PostgreSQL on OS-X (i used a mix of these on 10.5.x):
      - *
    • http://developer.apple.com/internet/opensource/postgres.html
    • - *
    • http://shifteleven.com/articles/2008/03/21/installing-postgresql-on-leopard-using-macports
    • - *
    • http://systems.takizo.com/2008/03/10/installing-postgresql-82-on-leopard-with-macports/
    • - *
    - * PostgreSQL documentation is at:
      - *
    • http://www.postgresql.org/docs/8.3/interactive/index.html
    • - *
    - * - * @author Florian Jenett - mail@florianjenett.de - * - * created: 2008-11-29 17:49:23 - fjenett - * modified: fjenett 2012-02 - * - */ - -public class PostgreSQL -extends de.bezier.data.sql.SQL -{ - public PostgreSQL ( PApplet _papplet, String _database ) - { - // should not be used - } - - /** - * Creates a new PostgreSQL connection. - * - * @param _papplet Normally you'd pass "this" in for your sketch - * @param _server The server running the database, try "localhost" - * @param _database Name of the database - * @param _user Username for that database - * @param _pass Password for user - */ - - public PostgreSQL ( PApplet _papplet, String _server, String _database, String _user, String _pass ) - { - super( _papplet, _server, _database, _user, _pass ); - init(); - } - - private void init () - { - this.driver = "org.postgresql.Driver"; - this.type = "postgresql"; - - this.url = "jdbc:" + type + "://" + server + "/" + database; - } - - public String[] getTableNames () - { - if ( tableNames == null ) - { - tableNames = new ArrayList(); - query( "SELECT relname AS table_name FROM pg_stat_user_tables WHERE schemaname='public'" ); - while ( next() ) { - tableNames.add( getObject("table_name").toString() ); - } - } - return tableNames.toArray(new String[0]); - } -} diff --git a/src/de/bezier/data/sql/SQL.java b/src/de/bezier/data/sql/SQL.java deleted file mode 100644 index 33c04bb..0000000 --- a/src/de/bezier/data/sql/SQL.java +++ /dev/null @@ -1,1704 +0,0 @@ -package de.bezier.data.sql; - -import processing.core.*; -import de.bezier.data.sql.mapper.*; - -import java.io.*; -import java.sql.*; -import java.lang.reflect.*; -import java.util.HashMap; -import java.util.Map; -import java.util.ArrayList; - -/** - *

    SQL library for Processing 2+

    - * - * Since v 0.2.0 it has some ORM like features, see - * - * - * Links:
      - *
    • http://www.mysql.com/products/connector/j/
    • - *
    • http://java.sun.com/products/jdbc/
    • - *
    • http://www.toxi.co.uk/blog/2007/07/using-javadb-and-db4o-in-processing.htm
    • - *
    • http://www.tom-carden.co.uk/2007/07/30/a-quick-note-on-using-sqlite-in-processing/
    • - *
    - * - * @author Florian Jenett - mail@florianjenett.de - * - * created: 07.05.2005 - 12:46 Uhr - * modified: fjenett 20121217 - */ - -abstract public class SQL -{ - PApplet papplet; - - public String server; - public String database; - public String url; - public String user; - protected String pass; - public String driver = ""; - public String type = ""; - - private int driverMinorVersion = -1; - private int driverMajorVersion = -1; - - public java.sql.Connection connection; - public String previousQuery; - - public java.sql.Statement statement; - public java.sql.ResultSet result; - - private boolean DEBUG = true; - //private HashMap columnNamesCache; - private NameMapper mapper; - private HashMap classToTableMap; - protected ArrayList tableNames; - - /** - * Do not use this contructor. - */ - public SQL () - { - System.out.println( - "SQL(): Please use this constructor\n"+ - "\tSQL ( String _serv, String _db, String _u, String _p, PApplet _pa )" - ); - - mapper = new de.bezier.data.sql.mapper.UnderScoreToCamelCaseMapper(); - } - - - /** - * You should not directly use the SQL.class instead use the classes for your database type. - */ - public SQL ( PApplet _pa, String _db ) - { - this.user = ""; - this.pass = ""; - this.server = ""; - - String f = _pa.dataPath(_db); - File ff = new File(f); - if ( !ff.exists() || !ff.canRead() ) - { - f = _pa.sketchPath( _db ); - ff = new File(f); - - if ( !ff.exists() || !ff.canRead() ) - { - f = _db; - ff = new File(f); - - if ( !ff.exists() || !ff.canRead() ) - { - System.err.println( - "Sorry can't find any file named " + _db + - " make sure it exists and the path is correct." - ); - } - } - } - - PApplet.println( "Using this database: " + f ); - - this.database = f; - - this.url = "jdbc:" + type + ":" + database; - - this.papplet = _pa; - papplet.registerMethod("dispose", this); - mapper = new de.bezier.data.sql.mapper.UnderScoreToCamelCaseMapper(); - } - - - /** - * You should not directly use the SQL.class instead use the classes for your database type. - */ - public SQL ( PApplet _pa, String _serv, String _db, String _u, String _p ) - { - this.server = _serv; - this.database = _db; - - this.url = "jdbc:" + type + "://" + server + "/" + database; - - this.user = _u; - this.pass = _p; - - this.papplet = _pa; - papplet.registerMethod("dispose", this); - mapper = new de.bezier.data.sql.mapper.UnderScoreToCamelCaseMapper(); - } - - - /** - * Turn some debugging on/off. - * - * @param yesNo Turn it on or off - */ - public void setDebug ( boolean yesNo ) - { - DEBUG = yesNo; - } - - - /** - * Get current debugging setting - * - * @param yesNo Turn it on or off - */ - public boolean getDebug () - { - return DEBUG; - } - - - /** - * Open the database connection with the parameters given in the contructor. - */ - public boolean connect() - { - if ( driver == null || driver.equals("") || - type == null || type.equals("") ) - { - System.out.println( "SQL.connect(): You have to set a driver and type first." ); - return false; - } - - // TODO: need to add mechanisms for different connection types and parameters, see: - // http://jdbc.postgresql.org/documentation/83/connect.html - - try - { - Class.forName(driver); - connection = java.sql.DriverManager.getConnection(url, user, pass); - - } - catch (ClassNotFoundException e) - { - System.out.println( "SQL.connect(): Could not find the database driver ( "+driver+" ).\r" ); - if (DEBUG) e.printStackTrace(); - return false; - - } - catch (java.sql.SQLException e) - { - System.out.println( "SQL.connect(): Could not connect to the database ( "+url+" ).\r" ); - if (DEBUG) e.printStackTrace(); - return false; - - } - - getTableNames(); - - try { - Driver jdbcDriver = java.sql.DriverManager.getDriver( url ); - if ( jdbcDriver != null ) { - driverMinorVersion = jdbcDriver.getMinorVersion(); - driverMajorVersion = jdbcDriver.getMajorVersion(); - - if ( DEBUG ) System.out.println( "Using driver " + getDriverVersion() ); - } - } catch ( SQLException sqle ) { - sqle.printStackTrace(); - } - - return true; - } - - - /** - * Return the version of the currently active JDBC driver - * - * @return String The version of the current driver - */ - public String getDriverVersion () - { - if ( connection == null ) { - System.out.println( "SQL.getDriverVersion(): you need to connect() first" ); - return null; - } else if ( driver == null || driver.equals("") ) { - System.out.println( "SQL.getDriverVersion(): no driver specified ... or it is null" ); - return null; - } - return driver + " " + driverMajorVersion + "." + driverMinorVersion; - } - - private void preQueryOrExecute () - { - result = null; - } - - - /** - * Execute a SQL command on the open database connection. - * - * @param _sql The SQL command to execute - */ - public void execute ( String _sql ) - { - preQueryOrExecute(); - - query( _sql, false ); - } - - - /** - * Execute a SQL command on the open database connection. - * Arguments are passed to String.format() first. - * - * @param _sql SQL command as pattern for String.format() - * @param args Zero or more objects to be passed to String.format() - * - * @see Format syntax - * @see java.lang.String#format(java.lang.String,java.lang.Object...) - */ - public void execute ( String _sql, Object ... args ) - { - preQueryOrExecute(); - - if ( args == null || args.length == 0 ) queryOrExecute( _sql, false ); - - Method meth = null; - try { - meth = String.class.getMethod( - "format", - String.class, - java.lang.reflect.Array.newInstance(Object.class,0).getClass() - ); - } catch ( Exception ex ) { - ex.printStackTrace(); - return; - } - // Object[] args2 = new Object[args.length+1]; - // args2[0] = _sql; - // System.arraycopy( args, 0, args2, 1, args.length ); - String sql2 = null; - try { - sql2 = (String)meth.invoke( null, _sql, args ); - } catch ( Exception ex ) { - if (DEBUG) ex.printStackTrace(); - } - - queryOrExecute( sql2, false ); - } - - - /** - * Issue a query on the open database connection - * - * @param _sql SQL command to execute for the query - */ - public void query ( String _sql ) - { - preQueryOrExecute(); - - queryOrExecute( _sql, true ); - } - - - /** - * Issue a query on the open database connection. - * Arguments are passed to String.format() first. - * - * @param _sql SQL command as pattern for String.format() - * @param args Zero or more objects to be passed to String.format() - * - * @see Format syntax - * @see java.lang.String#format(java.lang.String,java.lang.Object...) - */ - public void query ( String _sql, Object ... args ) - { - preQueryOrExecute(); - - if ( args == null || args.length == 0 ) queryOrExecute( _sql, true ); - - Method meth = null; - try { - meth = String.class.getMethod( - "format", - String.class, - java.lang.reflect.Array.newInstance(Object.class,0).getClass() - ); - } catch ( Exception ex ) { - ex.printStackTrace(); - return; - } - - String sql2 = null; - try { - sql2 = (String)meth.invoke( null, _sql, args ); - } catch ( Exception ex ) { - if (DEBUG) ex.printStackTrace(); - } - - queryOrExecute( sql2, true ); - } - - - /** - * Query implemenbtation called by execute() / query() - */ - private void queryOrExecute ( String _sql, boolean keep ) - { - if ( connection == null ) - { - System.out.println( "SQL.query(): You need to connect() first." ); - return; - } - - previousQuery = _sql; - - try - { - if ( statement == null ) - { - statement = connection.createStatement(); - } - - boolean hasResults = statement.execute( _sql ); - - if ( keep && hasResults ) - { - this.result = statement.getResultSet(); - } - } - catch ( java.sql.SQLException e ) - { - System.out.println( "SQL.query(): java.sql.SQLException.\r" ); - if (DEBUG) { - System.out.println( _sql ); - e.printStackTrace(); - } - } - } - - - /** - * Check if more results (rows) are available. This needs to be called before any results can be retrieved. - * - * @return boolean true if more results are available, false otherwise - */ - public boolean next () - { - if ( result == null ) - { - System.out.println( "SQL.next(): You need to query() something first." ); - return false; - } - - try - { - return result.next(); - } - catch ( java.sql.SQLException e ) - { - System.out.println( "SQL.next(): java.sql.SQLException.\r" ); - if ( DEBUG ) e.printStackTrace(); - } - return false; - } - - - /** - * Get names of available tables in active database, - * needs to be implemented per db adapter. - * - * @return String[] The table names - */ - abstract public String[] getTableNames (); - - - /** - * Returns an array with the column names of the last request. - * - * @return String[] the column names of last result or null - */ - public String[] getColumnNames () - { - String[] colNames = null; - - if ( result == null ) - { - System.out.println( "SQL.getColumnNames(): You need to query() something first." ); - return null; - } - - // if ( columnNamesCache == null ) - // columnNamesCache = new HashMap(); - // - // colNames = columnNamesCache.get( result ); - // if ( colNames != null ) return colNames; - - java.sql.ResultSetMetaData meta = null; - try { - meta = result.getMetaData(); - } catch ( SQLException sqle ) { - if (DEBUG) sqle.printStackTrace(); - return null; - } - - if ( meta != null ) - { - try { - colNames = new String[ meta.getColumnCount() ]; - for ( int i = 1, k = meta.getColumnCount(); i <= k; i++ ) - { - colNames[i-1] = meta.getColumnName( i ); - } - } catch ( SQLException sqle ) { - if (DEBUG) sqle.printStackTrace(); - return null; - } - } - - // columnNamesCache.clear(); - // columnNamesCache.put( result, colNames ); - - return colNames; - } - - - /** - * Get connection. ... in case you want to do JDBC stuff directly. - * - * @return java.sql.Connection The connection - */ - public java.sql.Connection getConnection () - { - return connection; - } - - - /** - * Read an integer value from the specified field. - * Represents an INT / INTEGER type: - * http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html - * "8.9.6 Conversions by ResultSet.getXXX Methods" - * - * @param _field The name of the field - * @return int Value of the field or 0 - */ - public int getInt ( String _field ) - { - // TODO: 0 does not seem to be a good return value for a numeric field to indicate failure - // same goes for other numeric fields - - if ( result == null ) - { - System.out.println( "SQL.getInt(): You need to query() something first." ); - return 0; - } - - try - { - return result.getInt( _field ); - } - catch ( java.sql.SQLException e ) - { - System.out.println( "SQL.getInt(): java.sql.SQLException.\r" ); - if (DEBUG) e.printStackTrace(); - } - return 0; - } - - /** - * Read an integer value from the specified field. - * Represents an INT / INTEGER type: - * http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html - * "8.9.6 Conversions by ResultSet.getXXX Methods" - * - * @param _column The column index of the field to read - * @return int Value of the field or 0 - */ - public int getInt ( int _column ) - { - if ( result == null ) - { - System.out.println( "SQL.getInt(): You need to query() something first." ); - return 0; - } - - try - { - return result.getInt( _column ); - } - catch ( java.sql.SQLException e ) - { - System.out.println( "SQL.getInt(): java.sql.SQLException.\r" ); - if (DEBUG) e.printStackTrace(); - } - return 0; - } - - - /** - * Read a long value from the specified field. - * Represents a BIGINT type: - * http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html - * "8.9.6 Conversions by ResultSet.getXXX Methods" - * - * @param _field The name of the field - * @return long Value of the field or 0 - */ - public long getLong ( String _field ) - { - if ( result == null ) - { - System.out.println( "SQL.getLong(): You need to query() something first." ); - return 0; - } - - try - { - return result.getLong( _field ); - } - catch ( java.sql.SQLException e ) - { - System.out.println( "SQL.getLong(): java.sql.SQLException.\r" ); - if (DEBUG) e.printStackTrace(); - } - return 0; - } - - - /** - * Read a long value from the specified field. - * Represents a BIGINT type: - * http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html - * "8.9.6 Conversions by ResultSet.getXXX Methods" - * - * @param _column The column index of the field - * @return long Value of the field or 0 - */ - public long getLong ( int _column ) - { - if ( result == null ) - { - System.out.println( "SQL.getLong(): You need to query() something first." ); - return 0; - } - - try - { - return result.getLong( _column ); - } - catch ( java.sql.SQLException e ) - { - System.out.println( "SQL.getLong(): java.sql.SQLException.\r" ); - if (DEBUG) e.printStackTrace(); - } - return 0; - } - - - /** - * Read a float value from the specified field. - * Represents a REAL type: - * http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html - * "8.9.6 Conversions by ResultSet.getXXX Methods" - * - * @param _field The name of the field - * @return float Value of the field or 0 - */ - public float getFloat ( String _field ) - { - if ( result == null ) - { - System.out.println( "SQL.getFloat(): You need to query() something first." ); - return 0.0f; - } - - try - { - return result.getFloat( _field ); - } - catch ( java.sql.SQLException e ) - { - System.out.println( "SQL.getFloat(): java.sql.SQLException.\r" ); - if (DEBUG) e.printStackTrace(); - } - return 0.0f; - } - - - /** - * Read a float value from the specified field. - * Represents a REAL type: - * http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html - * "8.9.6 Conversions by ResultSet.getXXX Methods" - * - * @param _column The index of the column of the field - * @return float Value of the field or 0 - */ - public float getFloat ( int _column ) - { - if ( result == null ) - { - System.out.println( "SQL.getFloat(): You need to query() something first." ); - return 0.0f; - } - - try - { - return result.getFloat( _column ); - } - catch ( java.sql.SQLException e ) - { - System.out.println( "SQL.getFloat(): java.sql.SQLException.\r" ); - if (DEBUG) e.printStackTrace(); - } - return 0.0f; - } - - - /** - * Read a double value from the specified field. - * Represents FLOAT and DOUBLE types: - * http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html - * "8.9.6 Conversions by ResultSet.getXXX Methods" - * - * @param _field The name of the field - * @return double Value of the field or 0 - */ - public double getDouble ( String _field ) - { - if ( result == null ) - { - System.out.println( "SQL.getDouble(): You need to query() something first." ); - return 0.0; - } - - try - { - return result.getDouble( _field ); - } - catch ( java.sql.SQLException e ) - { - System.out.println( "SQL.getDouble(): java.sql.SQLException.\r" ); - if (DEBUG) e.printStackTrace(); - } - return 0.0; - } - - - /** - * Read a double value from the specified field. - * Represents FLOAT and DOUBLE types: - * http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html - * "8.9.6 Conversions by ResultSet.getXXX Methods" - * - * @param _column The column index of the field - * @return double Value of the field or 0 - */ - public double getDouble ( int _column ) - { - if ( result == null ) - { - System.out.println( "SQL.getDouble(): You need to query() something first." ); - return 0.0; - } - - try - { - return result.getDouble( _column ); - } - catch ( java.sql.SQLException e ) - { - System.out.println( "SQL.getDouble(): java.sql.SQLException.\r" ); - if (DEBUG) e.printStackTrace(); - } - return 0.0; - } - - - /** - * Read a java.math.BigDecimal value from the specified field. - * Represents DECIMAL and NUMERIC types: - * http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html - * "8.9.6 Conversions by ResultSet.getXXX Methods" - * - * @param _field The name of the field - * @return java.math.BigDecimal Value of the field or null - */ - public java.math.BigDecimal getBigDecimal ( String _field ) - { - if ( result == null ) - { - System.out.println( "SQL.getBigDecimal(): You need to query() something first." ); - return null; - } - - try - { - return result.getBigDecimal( _field ); - } - catch ( java.sql.SQLException e ) - { - System.out.println( "SQL.getBigDecimal(): java.sql.SQLException.\r" ); - if (DEBUG) e.printStackTrace(); - } - return null; - } - - - /** - * Read a java.math.BigDecimal value from the specified field. - * Represents DECIMAL and NUMERIC types: - * http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html - * "8.9.6 Conversions by ResultSet.getXXX Methods" - * - * @param _column The column index of the field - * @return java.math.BigDecimal Value of the field or null - */ - public java.math.BigDecimal getBigDecimal ( int _column ) - { - if ( result == null ) - { - System.out.println( "SQL.getBigDecimal(): You need to query() something first." ); - return null; - } - - try - { - return result.getBigDecimal( _column ); - } - catch ( java.sql.SQLException e ) - { - System.out.println( "SQL.getBigDecimal(): java.sql.SQLException.\r" ); - if (DEBUG) e.printStackTrace(); - } - return null; - } - - - /** - * Read a boolean value from the specified field. - * Represents BIT type: - * http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html - * "8.9.6 Conversions by ResultSet.getXXX Methods" - * - * @param _field The name of the field - * @return boolean Value of the field or 0 - */ - public boolean getBoolean ( String _field ) - { - if ( result == null ) - { - System.out.println( "SQL.getBoolean(): You need to query() something first." ); - return false; - } - - try - { - return result.getBoolean( _field ); - } - catch ( java.sql.SQLException e ) - { - System.out.println( "SQL.getBoolean(): java.sql.SQLException.\r" ); - if (DEBUG) e.printStackTrace(); - } - return false; - } - - - /** - * Read a boolean value from the specified field. - * Represents BIT type: - * http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html - * "8.9.6 Conversions by ResultSet.getXXX Methods" - * - * @param _column The column index of the field - * @return boolean Value of the field or 0 - */ - public boolean getBoolean ( int _column ) - { - if ( result == null ) - { - System.out.println( "SQL.getBoolean(): You need to query() something first." ); - return false; - } - - try - { - return result.getBoolean( _column ); - } - catch ( java.sql.SQLException e ) - { - System.out.println( "SQL.getBoolean(): java.sql.SQLException.\r" ); - if (DEBUG) e.printStackTrace(); - } - return false; - } - - - /** - * Read a String value from the specified field. - * Represents VARCHAR and CHAR types: - * http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html - * "8.9.6 Conversions by ResultSet.getXXX Methods" - * - * @param _field The name of the field - * @return String Value of the field or null - */ - public String getString ( String _field ) - { - if ( result == null ) - { - System.out.println( "SQL.getString(): You need to query() something first." ); - return null; - } - - try - { - return result.getString( _field ); - } - catch ( java.sql.SQLException e ) - { - System.out.println( "SQL.getString(): java.sql.SQLException.\r" ); - if (DEBUG) e.printStackTrace(); - } - return null; - } - - /** - * Read a String value from the specified field. - * Represents VARCHAR and CHAR types: - * http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html - * "8.9.6 Conversions by ResultSet.getXXX Methods" - * - * @param _column The column index of the field - * @return String Value of the field or null - */ - public String getString ( int _column ) - { - if ( result == null ) - { - System.out.println( "SQL.getString(): You need to query() something first." ); - return null; - } - - try - { - return result.getString( _column ); - } - catch ( java.sql.SQLException e ) - { - System.out.println( "SQL.getString(): java.sql.SQLException.\r" ); - if (DEBUG) e.printStackTrace(); - } - return null; - } - - /** - * Read a java.sql.Date value from the specified field. - * Represents DATE type: - * http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html - * "8.9.6 Conversions by ResultSet.getXXX Methods" - * - * @param _field The name of the field - * @return java.sql.Date Value of the field or null - */ - public java.sql.Date getDate ( String _field ) - { - if ( result == null ) - { - System.out.println( "SQL.getDate(): You need to query() something first." ); - return null; - } - - try - { - return result.getDate( _field ); - } - catch ( java.sql.SQLException e ) - { - System.out.println( "SQL.getDate(): java.sql.SQLException.\r" ); - if (DEBUG) e.printStackTrace(); - } - return null; - } - - - /** - * Read a java.sql.Date value from the specified field. - * Represents DATE type: - * http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html - * "8.9.6 Conversions by ResultSet.getXXX Methods" - * - * @param _column The column index of the field - * @return java.sql.Date Value of the field or null - */ - public java.sql.Date getDate ( int _column ) - { - if ( result == null ) - { - System.out.println( "SQL.getDate(): You need to query() something first." ); - return null; - } - - try - { - return result.getDate( _column ); - } - catch ( java.sql.SQLException e ) - { - System.out.println( "SQL.getDate(): java.sql.SQLException.\r" ); - if (DEBUG) e.printStackTrace(); - } - return null; - } - - - /** - * Read a java.sql.Time value from the specified field. - * Represents TIME type: - * http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html - * "8.9.6 Conversions by ResultSet.getXXX Methods" - * - * @param _field The name of the field - * @return java.sql.Time Value of the field or null - */ - public java.sql.Time getTime ( String _field ) - { - if ( result == null ) - { - System.out.println( "SQL.getTime(): You need to query() something first." ); - return null; - } - - try - { - return result.getTime( _field ); - } - catch ( java.sql.SQLException e ) - { - System.out.println( "SQL.getTime(): java.sql.SQLException.\r" ); - if (DEBUG) e.printStackTrace(); - } - return null; - } - - - /** - * Read a java.sql.Time value from the specified field. - * Represents TIME type: - * http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html - * "8.9.6 Conversions by ResultSet.getXXX Methods" - * - * @param _column The column index of the field - * @return java.sql.Time Value of the field or null - */ - public java.sql.Time getTime ( int _column ) - { - if ( result == null ) - { - System.out.println( "SQL.getTime(): You need to query() something first." ); - return null; - } - - try - { - return result.getTime( _column ); - } - catch ( java.sql.SQLException e ) - { - System.out.println( "SQL.getTime(): java.sql.SQLException.\r" ); - if (DEBUG) e.printStackTrace(); - } - return null; - } - - - /** - * Read a java.sql.Timestamp value from the specified field. - * Represents TIMESTAMP type: - * http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html - * "8.9.6 Conversions by ResultSet.getXXX Methods" - * - * @param _field The name of the field - * @return java.sql.Timestamp Value of the field or null - */ - public java.sql.Timestamp getTimestamp ( String _field ) - { - if ( result == null ) - { - System.out.println( "SQL.getTimestamp(): You need to query() something first." ); - return null; - } - - try - { - return result.getTimestamp( _field ); - } - catch ( java.sql.SQLException e ) - { - System.out.println( "SQL.getTimestamp(): java.sql.SQLException.\r" ); - if (DEBUG) e.printStackTrace(); - } - return null; - } - - - /** - * Read a java.sql.Timestamp value from the specified field. - * Represents TIMESTAMP type: - * http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html - * "8.9.6 Conversions by ResultSet.getXXX Methods" - * - * @param _column The column index of the field - * @return java.sql.Timestamp Value of the field or null - */ - public java.sql.Timestamp getTimestamp ( int _column ) - { - if ( result == null ) - { - System.out.println( "SQL.getTimestamp(): You need to query() something first." ); - return null; - } - - try - { - return result.getTimestamp( _column ); - } - catch ( java.sql.SQLException e ) - { - System.out.println( "SQL.getTimestamp(): java.sql.SQLException.\r" ); - if (DEBUG) e.printStackTrace(); - } - return null; - } - - - /** - * Read a value from the specified field to have it returned as an byte[] - * - * @param _field The name of the field - * @return byte[] byte array representing a blob - */ - public byte[] getBlob ( String _field ) - { - if ( result == null ) - { - System.out.println( "SQL.getBlob(): You need to query() something first." ); - return null; - } - - try - { - Blob blob = result.getBlob( _field ); - return blob.getBytes(1,(int)blob.length()); - } - catch ( java.sql.SQLException e ) - { - System.out.println( "SQL.getObject(): java.sql.SQLException.\r" ); - if (DEBUG) e.printStackTrace(); - } - return null; - } - - - /** - * Read a value from the specified field to have it returned as an byte[] - * - * @param _column The column index of the field - * @return byte[] byte array representing a blob - */ - public byte[] getBlob ( int _column ) - { - if ( result == null ) - { - System.out.println( "SQL.getBlob(): You need to query() something first." ); - return null; - } - - try - { - Blob blob = result.getBlob( _column ); - return blob.getBytes(1,(int)blob.length()); - } - catch ( java.sql.SQLException e ) - { - System.out.println( "SQL.getObject(): java.sql.SQLException.\r" ); - if (DEBUG) e.printStackTrace(); - } - return null; - } - - - /** - * Read a value from the specified field to have it returned as an object. - * - * @param _field The name of the field - * @return Object Value of the field or null - */ - public Object getObject ( String _field ) - { - if ( result == null ) - { - System.out.println( "SQL.getObject(): You need to query() something first." ); - return null; - } - - try - { - return result.getObject( _field ); - } - catch ( java.sql.SQLException e ) - { - System.out.println( "SQL.getObject(): java.sql.SQLException.\r" ); - if (DEBUG) e.printStackTrace(); - } - return null; - } - - - /** - * Read a value from the specified field to have it returned as an object. - * - * @param _column The column index of the field - * @return Object Value of the field or null - */ - public Object getObject ( int _column ) - { - if ( result == null ) - { - System.out.println( "SQL.getObject(): You need to query() something first." ); - return null; - } - - try - { - return result.getObject( _column ); - } - catch ( java.sql.SQLException e ) - { - System.out.println( "SQL.getObject(): java.sql.SQLException.\r" ); - if (DEBUG) e.printStackTrace(); - } - return null; - } - - - /** - * Close the database connection - */ - public void close() - { - dispose(); - } - - - /** - * Callback function for PApplet.registerDispose() - * - * @see processing.core.PApplet.registerDispose(java.lang.Object) - */ - public void dispose () - { - if ( result != null ) - { - try - { - result.close(); - } - catch ( java.sql.SQLException e ) { ; } - - result = null; - } - - if ( statement != null ) - { - try - { - statement.close(); - } - catch ( java.sql.SQLException e ) { ; } - - statement = null; - } - - if ( connection != null ) - { - try - { - connection.close(); - } - catch ( java.sql.SQLException e ) { ; } - - connection = null; - } - } - - - /** - * Generate an escaped String for a given Object - * - * @param object the Object to escape - * @return String the ecaped String representation of the Object - */ - public String escape ( Object o ) - { - return "\"" + o.toString().replaceAll("\"","\\\"") + "\""; - } - - - /** - * Set the current NameMapper - * - * @param mapper the name mapper - * @see de.bezier.data.sql.mapper.NameMapper - */ - public void setNameMapper ( NameMapper mapper ) - { - this.mapper = mapper; - } - - - /** - * Get the current NameMapper - * - * @see de.bezier.data.sql.mapper.NameMapper - */ - public NameMapper getNameMapper () - { - return mapper; - } - - - /** - *

    Highly experimental ...
    - * tries to map column names to public fields or setter methods - * in the given object.

    - * - *

    Use like so: - *

    -	 *	db.query("SELECT name, id, sometime FROM table");
    -	 *
    -	 *	while ( db.next() ) {
    -	 *		SomeObject obj = new SomeObject();
    -	 *		db.setFromRow(obj);
    -	 *		// obj.name is now same as db.getString("name"), etc.
    -	 *  }
    -	 *  

    - * - *

    SomeObject might look like: - *

    -	 *	class SomeObject {
    -	 *		public String name;
    -	 *		public int id;
    -	 *		Date sometime;
    -	 *	}
    -	 *	

    - * - * @param object The object to populate from the currently selected row - */ - public void setFromRow ( Object object ) - { - if ( object == null ) { - System.err.println( "SQL.rowToObject(): Handing in null won't cut it." ); - return; - } - - if ( result == null ) { - System.err.println( "SQL.rowToObject(): You need to query() something first!" ); - return; - } - - String[] colNames = getColumnNames(); - if ( colNames == null ) - { - System.err.println( - "SQL.rowToObject(): uh-oh something went wrong: unable to get column names." ); - return; - } - - if ( colNames.length > 0 ) - { - Class klass = null; - try { - klass = Class.forName("DeBezierDataSQL"); - } catch ( Exception e ) { - if (DEBUG) e.printStackTrace(); - } - if ( klass != null ) { - Method meth = null; - try { - meth = klass.getMethod( - "setFromRow", - new Class[]{ SQL.class, Object.class } - ); - } catch ( Exception e ) { - if (DEBUG) e.printStackTrace(); - } - // System.out.println( meth ); - // System.out.println( meth.getParameterTypes() ); - if ( meth != null ) { - try { - meth.invoke( null, this, object ); - } catch ( Exception e ) { - if (DEBUG) e.printStackTrace(); - } - } - } - } - } - - - /** - * Convert a field name to a setter name: fieldName -> setFieldName(). - */ - public String nameToSetter ( String name ) - { - if ( name == null ) return name; - if ( name.length() == 0 ) return null; - return "set" + name.substring(0,1).toUpperCase() + name.substring(1); - } - - - /** - * Convert a field name to a getter name: fieldName -> getFieldName(). - */ - public String nameToGetter ( String name ) - { - if ( name == null ) return name; - if ( name.length() == 0 ) return null; - return "get" + name.substring(0,1).toUpperCase() + name.substring(1); - } - - - /** - * Set a table name for a class. - */ - public void registerTableNameForClass ( String name, Object classOrObject ) - { - if ( name == null || name.equals("") || classOrObject == null ) return; - - Class klass = null; - if ( classOrObject.getClass() != Class.class ) - klass = classOrObject.getClass(); - else - klass = (Class)classOrObject; - - if ( classToTableMap == null ) - classToTableMap = new HashMap(); - - classToTableMap.put( klass, name ); - if (DEBUG) System.out.println( String.format( - "Class \"%s\" is now mapped to table \"%s\"", klass.getName(), name - )); - } - - - /** - * Take an object, try to find table name from object name (or look it up), - * get fields and getters from object and pass that on to - * insertUpdateIntoDatabase(table, columns, values). - * - * @param object Object The object to save to db - * - * @see #insertUpdateInDatabase(java.lang.String, java.lang.String[], java.lang.Object[]) - */ - public void saveToDatabase ( Object object ) - { - if ( object == null ) return; - - // Find the table name - - String tableName = null; - - if ( classToTableMap == null ) - classToTableMap = new HashMap(); - - tableName = classToTableMap.get(object.getClass()); - - if ( tableName != null ) - saveToDatabase( tableName, object ); - else - { - Class klass = object.getClass(); - tableName = klass.getName(); - - for ( char c : new char[]{'$','.'} ) - { - int indx = tableName.lastIndexOf(c); - if ( indx >= 0 ) { - tableName = tableName.substring(indx+1); - } - } - - if ( mapper != null ) { - tableName = mapper.backward(tableName); - } - - registerTableNameForClass( tableName, klass ); - - saveToDatabase( tableName, object ); - } - } - - - /** - * Takes a table name and an object and tries to construct a set of - * columns names from fields and getters found in the object. After - * the values are fetched from the object all is passed to - * insertUpdateIntoDatabase(). - * - * @param tableName String The name of the table - * @param object Object The object to look at - * - * @see #insertUpdateInDatabase(java.lang.String, java.lang.String[], java.lang.Object[]) - */ - public void saveToDatabase ( String tableName, Object object ) - { - if ( object == null ) return; - - String[] tableNames = getTableNames(); - if ( !java.util.Arrays.asList(tableNames).contains(tableName) ) { - System.err.println(String.format( - "saveToDatabase(): table '%s' not found in database '%s'", tableName, database - )); - return; - } - - String[] colNames = getColumnNames(); - String[] fieldNames = new String[colNames.length]; - - if ( mapper != null ) - { - for ( int i = 0; i < colNames.length; i++ ) - { - //System.out.println(colNames[i]); - fieldNames[i] = mapper.forward(colNames[i]); - //System.out.println(fieldNames[i]); - } - } - - Class klass = object.getClass(); - Field[] fields = new Field[colNames.length]; - Method[] getters = new Method[colNames.length]; - - for ( int i = 0; i < colNames.length; i++ ) - { - String fieldName = fieldNames[i]; - String colName = colNames[i]; - - Field f = null; - try { - f = klass.getField(fieldName); - if ( f == null ) { - f = klass.getField(colName); - } - } catch ( Exception e ) { - if (DEBUG) e.printStackTrace(); - } - if ( f != null ) { - // try { - // values[i] = f.get(object); - // } catch ( Exception e ) { - // if (DEBUG) e.printStackTrace(); - // } - fields[i] = f; - } - else - { - if (DEBUG) System.out.println( "Field not found, trying setter method" ); - - String getterName = nameToGetter(fieldName); - Method getter = null; - try { - getter = klass.getMethod( - getterName, new Class[0] - ); - } catch ( Exception e ) { - if (DEBUG) e.printStackTrace(); - } - // try { - // values[i] = getter.invoke(object); - // } catch ( Exception e ) { - // if (DEBUG) e.printStackTrace(); - // } - getters[i] = getter; - } - if ( fields[i] == null && getters[i] == null ) { - System.err.println(String.format( - "Unable to get a field or getter for column '%s'", colName - )); - return; - } - } - - Object[] values = null; - - Class clazz = null; - try { - clazz = Class.forName("DeBezierDataSQL"); - } catch ( Exception e ) { - if (DEBUG) e.printStackTrace(); - } - - if ( klass != null ) { - Method meth = null; - try { - meth = clazz.getMethod( - "getValuesFromObject", - new Class[]{ SQL.class, Field[].class, Method[].class, Object.class } - ); - } catch ( Exception e ) { - if (DEBUG) e.printStackTrace(); - } - // System.out.println( meth ); - // System.out.println( meth.getParameterTypes() ); - if ( meth != null ) { - try { - values = (Object[])meth.invoke( null, this, fields, getters, object ); - } catch ( Exception e ) { - if (DEBUG) e.printStackTrace(); - } - } - } - - if ( values != null ) - { - insertUpdateInDatabase( tableName, colNames, values ); - } - else - { - System.err.println("saveToDatabase() : trouble, trouble!!"); - } - } - - - /** - * Insert or update a bunch of values in the database. If the given table has a - * primary key the entry will be updated if it already existed. - * - * @param tableName String The name of the table - * @param columnNames String[] The names of the columns to fill or update - * @param values Object[] The values to instert or update - */ - public void insertUpdateInDatabase ( String tableName, String[] columnNames, Object[] values ) - { - HashMap valuesKeys = new HashMap(); - for ( int i = 0; i < values.length; i++ ) - { - valuesKeys.put(columnNames[i], values[i]); - } - - HashMap primaryKeys = null; - try { - DatabaseMetaData meta = connection.getMetaData(); - ResultSet rs = meta.getPrimaryKeys(null, null, tableName); - - while ( rs.next() ) - { - if ( primaryKeys == null ) - primaryKeys = new HashMap(); - - String columnName = rs.getString("COLUMN_NAME"); - primaryKeys.put(columnName, valuesKeys.get(columnName)); - valuesKeys.remove(columnName); - } - - } catch ( SQLException sqle ) { - sqle.printStackTrace(); - } - - //System.out.println(valuesKeys); - //System.out.println(primaryKeys); - - String cols = ""; - String patt = ""; - HashMap valueIndices = new HashMap(); - int i = 1; - for ( Map.Entry e : valuesKeys.entrySet() ) - { - cols += ( i > 1 ? " , " : "" ) + e.getKey(); - patt += ( i > 1 ? " , " : "" ) + "?"; - valueIndices.put( e.getKey(), i ); - i++; - } - - String sql = null, opts = null; - HashMap primaryIndices = null; - if ( primaryKeys == null || primaryKeys.size() == 0 ) { - sql = "INSERT INTO " + tableName + " ( " + cols + " ) VALUES ( " + patt + " )"; - } else { - primaryIndices = new HashMap(); - opts = " WHERE "; - int p = 1; - for ( Map.Entry e : primaryKeys.entrySet() ) { - opts += (p > 1 ? " , " : "") + e.getKey() + " = ? "; - primaryIndices.put( e.getKey(), p ); - p++; - } - //System.out.println( opts ); - String sqlFind = "SELECT * FROM "+tableName+" "+opts; - //System.out.println( sqlFind ); - try { - PreparedStatement psFind = connection.prepareStatement( sqlFind ); - for ( Map.Entry e : primaryKeys.entrySet() ) { - psFind.setString( primaryIndices.get(e.getKey()), e.getValue().toString() ); - } - result = psFind.executeQuery(); - boolean found = next(); - psFind.close(); - if ( !found ) { - if (DEBUG) System.out.println(String.format( - "No entry with %s found in table '%s'", primaryKeys.toString(), tableName - )); - int k = 1, m = valueIndices.size(); - for ( Map.Entry e : primaryKeys.entrySet() ) { - cols += ( m > 0 ? " , " : "" ) + e.getKey(); - patt += ( m > 0 ? " , " : "" ) + "?"; - valuesKeys.put( e.getKey(), e.getValue() ); - valueIndices.put( e.getKey(), m+k ); - k++; - } - sql = "INSERT INTO " + tableName + " ( " + cols + " ) VALUES ( " + patt + " )"; - primaryKeys = null; - } - else - { - cols = ""; - for ( Map.Entry e : valuesKeys.entrySet() ) - { - cols += ( cols.equals("") ? "" : " , " ) + e.getKey() + " = " + "?"; - } - sql = "UPDATE "+tableName+" SET " + cols + " " + opts; - } - } catch ( java.sql.SQLException sqle ) { - sqle.printStackTrace(); - } - } - - if (DEBUG) System.out.println( sql ); - - try { - PreparedStatement ps = connection.prepareStatement( sql ); - - for ( Map.Entry e : valuesKeys.entrySet() ) - { - ps.setString( valueIndices.get(e.getKey()), e.getValue()+"" ); - } - - if ( primaryKeys != null ) - { - for ( Map.Entry e : primaryKeys.entrySet() ) - { - ps.setString( valueIndices.size()+primaryIndices.get(e.getKey()), e.getValue()+"" ); - } - } - - ps.executeUpdate(); - ps.close(); - } catch ( java.sql.SQLException sqle ) { - sqle.printStackTrace(); - } - } -} diff --git a/src/de/bezier/data/sql/SQLite.java b/src/de/bezier/data/sql/SQLite.java deleted file mode 100644 index bc453f0..0000000 --- a/src/de/bezier/data/sql/SQLite.java +++ /dev/null @@ -1,78 +0,0 @@ -package de.bezier.data.sql; - -import processing.core.*; -import java.util.ArrayList; - -/** - * SQLite wrapper for SQL library for Processing 2+ - *

    - * A wrapper around some of sun's java.sql.* classes - * and the pure java "org.sqlite.JDBC" driver of the Xerial project (Apache 2 license). - *

    - * see:
      - *
    • http://www.xerial.org/trac/Xerial/wiki/SQLiteJDBC
    • - *
    • http://www.xerial.org/maven/repository/site/xerial-project/sqlite-jdbc/apidocs/index.html?index-all.html
    • - *
    • http://java.sun.com/products/jdbc/
    • - *
    - * - * - * @author Florian Jenett - mail@florianjenett.de - * - * created: 2008-11-29 12:15:15 - fjenett - * modified: fjenett 20121217 - * - */ - -public class SQLite -extends de.bezier.data.sql.SQL -{ - /** - * Creates a new SQLite connection. - * - * @param _papplet Your sketch, pass "this" in here - * @param _database Path to the database file, if this is just a name the data and sketch folders are searched for the file - */ - - public SQLite ( PApplet _papplet, String _database ) - { - super( _papplet, _database ); - init(); - } - - /** - * Creates a new SQLite connection, same as SQLite( PApplet, String ) - * - * @param _papplet Your sketch, pass "this" in here - * @param _server Ignored - * @param _database Path to the database file, if this is just a name the data and sketch folders are searched for the file - * @param _user Ignored - * @param _pass Ignored - */ - - public SQLite ( PApplet _papplet, String _server, String _database, String _user, String _pass ) - { - this( _papplet, _database ); - } - - - private void init () - { - this.driver = "org.sqlite.JDBC"; - this.type = "sqlite"; - - this.url = "jdbc:" + type + ":" + database; - } - - public String[] getTableNames () - { - if ( tableNames == null ) - { - tableNames = new ArrayList(); - query( "SELECT name AS 'table_name' FROM SQLITE_MASTER WHERE type=\"table\"" ); - while ( next() ) { - tableNames.add( getObject("table_name").toString() ); - } - } - return tableNames.toArray(new String[0]); - } -} diff --git a/src/de/bezier/data/sql/mapper/NameMapper.java b/src/de/bezier/data/sql/mapper/NameMapper.java deleted file mode 100644 index 7cdcc33..0000000 --- a/src/de/bezier/data/sql/mapper/NameMapper.java +++ /dev/null @@ -1,25 +0,0 @@ -package de.bezier.data.sql.mapper; - -/** - * NameMapper is used to map database names to instance names - * When setting objects from objects with SQL.setFromRow(). - * - * This is just an interface and only one implementation is - * provided in form of the default UnderScoreToCamelCaseMapper - * which does: field_name -> fieldName and vv. - */ - -public interface NameMapper -{ - /** - * Maps a database name to an object name, typically - * this might look like: field_name -> fieldName. - */ - public String forward ( String name ); - - /** - * Reverse of forward, maps object names to database - * names like: fieldName -> field_name. - */ - public String backward ( String name ); -} \ No newline at end of file diff --git a/src/de/bezier/data/sql/mapper/UnderScoreToCamelCaseMapper.java b/src/de/bezier/data/sql/mapper/UnderScoreToCamelCaseMapper.java deleted file mode 100644 index a36b44e..0000000 --- a/src/de/bezier/data/sql/mapper/UnderScoreToCamelCaseMapper.java +++ /dev/null @@ -1,61 +0,0 @@ -package de.bezier.data.sql.mapper; - -/** - * UnderScoreToCamelCaseMapper, does as it says. - */ -public class UnderScoreToCamelCaseMapper implements NameMapper -{ - public String backward ( String name ) - { - String newName = ""; - for ( int i = 0, k = name.length(); i < k; i++ ) - { - String c = name.charAt(i) + ""; - if ( c.toUpperCase().equals(c) && !c.toLowerCase().equals(c) ) { - if ( i > 0 && i < k-1 ) - c = "_" + c.toLowerCase(); - else - c = c.toLowerCase(); - } - newName += c; - } - return newName; - } - - public String forward ( String name ) - { - String[] pieces = name.split("_"); - String newName = pieces[0]; - for ( int i = 1; i < pieces.length; i++ ) - { - if ( pieces[i] != null && pieces[1].length() > 0 ) - { - newName += pieces[i].substring(0,1).toUpperCase() + - pieces[i].substring(1); - } - } - return newName; - } - - public static void main ( String ... args ) - { - String[] test = new String[]{ - "created_at", - "created_at_and_else", - "rank_1", - "_rank_abc", - "rank_abc_", - "camelCase_and_more" - }; - UnderScoreToCamelCaseMapper mapper = new UnderScoreToCamelCaseMapper(); - for ( String t : test ) - { - String fwd = mapper.forward(t); - System.out.println( t + " -> " + fwd ); - String back = mapper.backward(fwd); - System.out.println( fwd + " -> " + back ); - System.out.println( t.equals(back) ); - System.out.println( "" ); - } - } -} \ No newline at end of file diff --git a/resources/web/stylesheet.css b/stylesheet.css similarity index 100% rename from resources/web/stylesheet.css rename to stylesheet.css