src/de/bezier/data/sql/SQL.java
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<? extends Object> 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!!");
		}
	}
/**
	 *	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[])
	 */
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


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
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++ )
			{
				fieldNames[i] = mapper.forward(colNames[i]);
			}
		}
		Class<? extends Object> 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 ) {
				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();
				}
				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();
			}
			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!!");
		}
	}
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 ++ ) { fieldNames [ i ] = mapper . forward ( colNames [ i ] ) ; } } Class < ? extends Object > 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 ) { 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 ( ) ; } 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 ( ) ; } 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!!" ) ; } }
Takes a table name and an object and tries to construct a set of
      columns names from fields and getters found in the 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 .
//System.out.println(colNames[i]); //System.out.println(fieldNames[i]); // try { // 	values[i] = f.get(object); // } catch ( Exception e ) { // 	if (DEBUG) e.printStackTrace(); // } // try { // 	values[i] = getter.invoke(object); // } catch ( Exception e ) { // 	if (DEBUG) e.printStackTrace(); // } // System.out.println( meth ); // System.out.println( meth.getParameterTypes() );