Java SQL Table constructObject(Class theClass, Connection db, int objectId, String tableName, String uniqueField)

Here you can find the source of constructObject(Class theClass, Connection db, int objectId, String tableName, String uniqueField)

Description

Description of the Method

License

Open Source License

Parameter

Parameter Description
theClass Description of the Parameter
db Description of the Parameter
objectId Description of the Parameter
tableName Description of the Parameter
uniqueField Description of the Parameter

Return

Description of the Return Value

Declaration

public static Object constructObject(Class theClass, Connection db, int objectId, String tableName,
        String uniqueField) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.lang.reflect.Constructor;

import java.sql.Connection;

public class Main {
    /**//from  w  ww.ja va  2 s. c o m
     *  Constructs an object with a null constructor
     *
     * @param  theClass  Description of the Parameter
     * @return           Description of the Return Value
     */
    public static Object constructObject(Class theClass) {
        try {
            Class[] paramClass = null;
            Constructor constructor = theClass.getConstructor(paramClass);
            Object[] paramObject = null;
            return constructor.newInstance(paramObject);
        } catch (Exception e) {
            return null;
        }
    }

    /**
     *  Constructs a new object in which the object loads itself from a database
     *  given a parameter
     *
     * @param  theClass   Description of the Parameter
     * @param  parameter  Description of the Parameter
     * @param  db         Description of the Parameter
     * @return            Description of the Return Value
     */
    public static Object constructObject(Class theClass, Object parameter, Connection db) {
        try {
            Class[] paramClass = new Class[] { parameter.getClass(), Class.forName("java.sql.Connection") };
            Constructor constructor = theClass.getConstructor(paramClass);
            Object[] paramObject = new Object[] { parameter, db };
            return constructor.newInstance(paramObject);
        } catch (Exception e) {
            return null;
        }
    }

    /**
     *  Constructs a new object in which the object loads itself from a database
     *  given an id for the object
     *
     * @param  theClass  Description of Parameter
     * @param  db        Description of Parameter
     * @param  objectId  Description of Parameter
     * @return           Description of the Returned Value
     */
    public static Object constructObject(Class theClass, Connection db, int objectId) {
        try {
            Class[] paramClass = new Class[] { Class.forName("java.sql.Connection"), int.class };
            Constructor constructor = theClass.getConstructor(paramClass);
            Object[] paramObject = new Object[] { db, new Integer(objectId) };
            return constructor.newInstance(paramObject);
        } catch (Exception e) {
            return null;
        }
    }

    /**
     *  Constructs a new object in which the object loads itself from a database
     *  given an id for the object and a String typically used as a tableName for
     *  a lookupElement object
     *
     * @param  theClass   Description of the Parameter
     * @param  db         Description of the Parameter
     * @param  objectId   Description of the Parameter
     * @param  tableName  Description of the Parameter
     * @return            Description of the Return Value
     */
    public static Object constructObject(Class theClass, Connection db, int objectId, String tableName) {
        try {
            Class[] paramClass = new Class[] { Class.forName("java.sql.Connection"), int.class,
                    Class.forName("java.lang.String") };
            Constructor constructor = theClass.getConstructor(paramClass);
            Object[] paramObject = new Object[] { db, new Integer(objectId), tableName };
            return constructor.newInstance(paramObject);
        } catch (Exception e) {
            return null;
        }
    }

    /**
     *  Description of the Method
     *
     * @param  theClass     Description of the Parameter
     * @param  db           Description of the Parameter
     * @param  objectId     Description of the Parameter
     * @param  tableName    Description of the Parameter
     * @param  uniqueField  Description of the Parameter
     * @return              Description of the Return Value
     */
    public static Object constructObject(Class theClass, Connection db, int objectId, String tableName,
            String uniqueField) {
        try {
            Class[] paramClass = new Class[] { Class.forName("java.sql.Connection"), int.class,
                    Class.forName("java.lang.String"), Class.forName("java.lang.String") };
            Constructor constructor = theClass.getConstructor(paramClass);
            Object[] paramObject = new Object[] { db, new Integer(objectId), tableName, uniqueField };
            return constructor.newInstance(paramObject);
        } catch (Exception e) {
            return null;
        }
    }
}

Related

  1. clearTables(Connection conn)
  2. clearTables(Connection conn, String[] tables)
  3. clearTables(Connection connection)
  4. columnExist(String table, String column, Connection con)
  5. count(Connection conn, String table)
  6. countTables(Connection connection)
  7. createBagValuesTables(Connection con)
  8. createFreqTable()