Package org.springmodules.datamap.jdbc.sqlmap

Examples of org.springmodules.datamap.jdbc.sqlmap.PersistentField


        newPo.setTableName(tableName);
        final String sqlTableName = tableName;
        final Map newMetaData = new HashMap(10);
        Field[] f = clazz.getDeclaredFields();
        for (int i = 0; i < f.length; i++) {
            PersistentField pf = new PersistentField();
            pf.setFieldName(f[i].getName());
            pf.setColumnName(ActiveMapperUtils.underscoreName(f[i].getName()));
            pf.setJavaType(f[i].getType());
            if ("id".equals(f[i].getName())) {
                if (!pf.isIdField())
                    pf.setIdField(true);
            }
            newMetaData.put(pf.getColumnName(), pf);
        }

        try {
            JdbcUtils.extractDatabaseMetaData(dataSource, new DatabaseMetaDataCallback() {
                public Object processMetaData(DatabaseMetaData databaseMetaData) throws SQLException {
                    newPo.setUsingLowerCaseIdentifiers(databaseMetaData.storesLowerCaseIdentifiers());
                    newPo.setDatabaseProductName(databaseMetaData.getDatabaseProductName());
                    if ("PostgreSQL".equals(newPo.getDatabaseProductName())) {
                        newPo.setUsingGeneratedKeysStrategy(false);
                        newPo.setIncrementer(new PostgreSQLSequenceMaxValueIncrementer(dataSource, newPo.getBaseName() + "_seq"));
                    }
                    else if ("HSQL Database Engine".equals(newPo.getDatabaseProductName())) {
                        newPo.setUsingGeneratedKeysStrategy(false);
                        newPo.setIncrementer(new HsqlMaxValueIncrementer(dataSource, newPo.getBaseName() + "_seq", "value"));
                    }
                    else if ("Oracle".equals(newPo.getDatabaseProductName())) {
                        newPo.setUsingGeneratedKeysStrategy(false);
                        newPo.setIncrementer(new OracleSequenceMaxValueIncrementer(dataSource, newPo.getBaseName() + "_seq"));
                    }
                    else {
                        newPo.setUsingGeneratedKeysStrategy(true);
                    }
                    String metaDataTableName;
                    if (newPo.isUsingLowerCaseIdentifiers())
                        metaDataTableName = sqlTableName.toLowerCase();
                    else
                        metaDataTableName = sqlTableName.toUpperCase();
                    ResultSet pkrs = databaseMetaData.getPrimaryKeys(null, null, metaDataTableName);
                    Set primaryKeys = new HashSet();
                    while (pkrs.next()) {
                        primaryKeys.add(pkrs.getString(4));
                    }
                    pkrs.close();
                    newPo.setPrimaryKeyColumns(primaryKeys);
                    int unmappedKey = primaryKeys.size();
                    ResultSet crs = databaseMetaData.getColumns(null, null, metaDataTableName, null);
                    while (crs.next()) {
                        PersistentField pf = (PersistentField)newMetaData.get(crs.getString(4).toLowerCase());
                        if (pf != null) {
                            pf.setSqlType(crs.getInt(5));
                            if (primaryKeys.contains(pf.getColumnName())) {
                                pf.setIdField(true);
                                unmappedKey--;
                            }
                        }
                    }
                    crs.close();
View Full Code Here

TOP

Related Classes of org.springmodules.datamap.jdbc.sqlmap.PersistentField

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.