Java SQL Table getImmutableDefaults()

Here you can find the source of getImmutableDefaults()

Description

get Immutable Defaults

License

Apache License

Return

the map of all immutable types -> the default values for those types

Declaration

public static synchronized Map<Class<?>, Object> getImmutableDefaults() 

Method Source Code

//package com.java2s;
/**/*from   w  w w .  jav  a 2  s . c  o  m*/
 * $Id: ConstructorUtils.java 61 2009-09-25 11:14:16Z azeckoski $
 * $URL: http://reflectutils.googlecode.com/svn/trunk/src/main/java/org/azeckoski/reflectutils/ConstructorUtils.java $
 * FieldUtils.java - genericdao - May 19, 2008 10:10:15 PM - azeckoski
 **************************************************************************
 * Copyright (c) 2008 Aaron Zeckoski
 * Licensed under the Apache License, Version 2.0
 * 
 * A copy of the Apache License has been included in this 
 * distribution and is available at: http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 * Aaron Zeckoski (azeckoski @ gmail.com) (aaronz @ vt.edu) (aaron @ caret.cam.ac.uk)
 */

import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Timestamp;

import java.util.Date;
import java.util.HashMap;

import java.util.Map;

public class Main {
    private static Map<Class<?>, Object> immutableDefaults = null;
    private static char c;

    /**
     * @return the map of all immutable types -> the default values for those types
     */
    public static synchronized Map<Class<?>, Object> getImmutableDefaults() {
        if (immutableDefaults == null || immutableDefaults.isEmpty()) {
            makeImmutableDefaultsMap();
        }
        return immutableDefaults;
    }

    private static void makeImmutableDefaultsMap() {
        immutableDefaults = new HashMap<Class<?>, Object>();
        immutableDefaults.put(BigDecimal.class, new BigDecimal(0));
        immutableDefaults.put(BigInteger.class, BigInteger.valueOf(0l));
        immutableDefaults.put(Boolean.class, Boolean.FALSE);
        immutableDefaults.put(Byte.class, Byte.valueOf((byte) 0));
        immutableDefaults.put(Character.class, (Character) c);
        immutableDefaults.put(Date.class, new Date(0));
        immutableDefaults.put(Double.class, Double.valueOf(0));
        immutableDefaults.put(Float.class, Float.valueOf(0));
        immutableDefaults.put(Long.class, Long.valueOf(0));
        immutableDefaults.put(Integer.class, Integer.valueOf(0));
        immutableDefaults.put(String.class, "");
        immutableDefaults.put(Short.class, Short.valueOf((short) 0));
        immutableDefaults.put(Timestamp.class, new Timestamp(0));
    }
}

Related

  1. getAllTableNames(Connection connection)
  2. getAllTables(Connection conn)
  3. getBatchResultMessage(String tableName, int rowIdx, int resultCode)
  4. getCount(Connection conn, String tableName)
  5. getIdNumber(String tableName)
  6. getLastCreatedEntry(Connection conn, String tableName)
  7. getMetaDataMap(Statement statement, String tableOrViewName)
  8. getNextId(Connection con, String table, String identityFieldName)
  9. getRowCount(Statement stmt, String tableName)