Search in sources :

Example 1 with JDBCTypeInfo

use of org.datanucleus.store.rdbms.schema.JDBCTypeInfo in project datanucleus-rdbms by datanucleus.

the class RDBMSStoreManager method printInformation.

/**
 * Method to output particular information owned by this datastore.
 * Supports "DATASTORE" and "SCHEMA" categories.
 * @param category Category of information
 * @param ps PrintStream
 * @throws Exception Thrown if an error occurs in the output process
 */
public void printInformation(String category, PrintStream ps) throws Exception {
    DatastoreAdapter dba = getDatastoreAdapter();
    super.printInformation(category, ps);
    if (category.equalsIgnoreCase("DATASTORE")) {
        ps.println(dba.toString());
        ps.println();
        ps.println("Database TypeInfo");
        RDBMSTypesInfo typesInfo = (RDBMSTypesInfo) schemaHandler.getSchemaData(null, "types", null);
        if (typesInfo != null) {
            Iterator iter = typesInfo.getChildren().keySet().iterator();
            while (iter.hasNext()) {
                String jdbcTypeStr = (String) iter.next();
                short jdbcTypeNumber = 0;
                try {
                    jdbcTypeNumber = Short.parseShort(jdbcTypeStr);
                } catch (NumberFormatException nfe) {
                }
                JDBCTypeInfo jdbcType = (JDBCTypeInfo) typesInfo.getChild(jdbcTypeStr);
                Collection<String> sqlTypeNames = jdbcType.getChildren().keySet();
                StringBuilder sqlTypesName = new StringBuilder();
                String defaultSqlTypeName = null;
                for (String sqlTypeName : sqlTypeNames) {
                    if (!sqlTypeName.equals("DEFAULT")) {
                        if (sqlTypesName.length() > 0) {
                            sqlTypesName.append(',');
                        }
                        sqlTypesName.append(sqlTypeName);
                    } else {
                        defaultSqlTypeName = ((SQLTypeInfo) jdbcType.getChild(sqlTypeName)).getTypeName();
                    }
                }
                // SQL type names for JDBC type
                String typeStr = "JDBC Type=" + dba.getNameForJDBCType(jdbcTypeNumber) + " sqlTypes=" + sqlTypesName + (defaultSqlTypeName != null ? (" (default=" + defaultSqlTypeName + ")") : "");
                ps.println(typeStr);
                for (String sqlTypeName : sqlTypeNames) {
                    // SQL type details
                    if (!sqlTypeName.equals("DEFAULT")) {
                        SQLTypeInfo sqlType = (SQLTypeInfo) jdbcType.getChild(sqlTypeName);
                        ps.println(sqlType.toString("    "));
                    }
                }
            }
        }
        ps.println("");
        // Print out the keywords info
        ps.println("Database Keywords");
        Iterator reservedWordsIter = dba.iteratorReservedWords();
        while (reservedWordsIter.hasNext()) {
            Object words = reservedWordsIter.next();
            ps.println(words);
        }
        ps.println("");
    } else if (category.equalsIgnoreCase("SCHEMA")) {
        ps.println(dba.toString());
        ps.println();
        ps.println("TABLES");
        ManagedConnection mc = connectionMgr.getConnection(-1);
        try {
            Connection conn = (Connection) mc.getConnection();
            RDBMSSchemaInfo schemaInfo = (RDBMSSchemaInfo) schemaHandler.getSchemaData(conn, "tables", new Object[] { this.catalogName, this.schemaName });
            if (schemaInfo != null) {
                Iterator tableIter = schemaInfo.getChildren().values().iterator();
                while (tableIter.hasNext()) {
                    // Print out the table information
                    RDBMSTableInfo tableInfo = (RDBMSTableInfo) tableIter.next();
                    ps.println(tableInfo);
                    Iterator<StoreSchemaData> columnIter = tableInfo.getChildren().iterator();
                    while (columnIter.hasNext()) {
                        // Print out the column information
                        RDBMSColumnInfo colInfo = (RDBMSColumnInfo) columnIter.next();
                        ps.println(colInfo);
                    }
                }
            }
        } finally {
            if (mc != null) {
                mc.release();
            }
        }
        ps.println("");
    }
}
Also used : RDBMSColumnInfo(org.datanucleus.store.rdbms.schema.RDBMSColumnInfo) RDBMSTableInfo(org.datanucleus.store.rdbms.schema.RDBMSTableInfo) Connection(java.sql.Connection) NucleusConnection(org.datanucleus.store.NucleusConnection) ManagedConnection(org.datanucleus.store.connection.ManagedConnection) MacroString(org.datanucleus.util.MacroString) SQLTypeInfo(org.datanucleus.store.rdbms.schema.SQLTypeInfo) JDBCTypeInfo(org.datanucleus.store.rdbms.schema.JDBCTypeInfo) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) DatastoreAdapter(org.datanucleus.store.rdbms.adapter.DatastoreAdapter) RDBMSTypesInfo(org.datanucleus.store.rdbms.schema.RDBMSTypesInfo) ManagedConnection(org.datanucleus.store.connection.ManagedConnection) RDBMSSchemaInfo(org.datanucleus.store.rdbms.schema.RDBMSSchemaInfo)

Example 2 with JDBCTypeInfo

use of org.datanucleus.store.rdbms.schema.JDBCTypeInfo in project datanucleus-rdbms by datanucleus.

the class PointbaseAdapter method initialiseTypes.

/**
 * Initialise the types for this datastore.
 * @param handler SchemaHandler that we initialise the types for
 * @param mconn Managed connection to use
 */
public void initialiseTypes(StoreSchemaHandler handler, ManagedConnection mconn) {
    super.initialiseTypes(handler, mconn);
    // Add on any missing JDBC types
    // Based on PointbaseAdapter : PointBase version=5.1 ECF build 295, major=5, minor=1, revision=0
    // Driver name=PointBase JDBC Driver, version=5.1 ECF build 295, major=5, minor=1
    RDBMSTypesInfo typesInfo = (RDBMSTypesInfo) handler.getSchemaData(mconn.getConnection(), "types", null);
    JDBCTypeInfo jdbcType = (JDBCTypeInfo) typesInfo.getChild("9");
    if (jdbcType != null && jdbcType.getNumberOfChildren() > 0) {
        // somehow BIGINT is set to 9 in the JDBC driver so add it at its correct value
        SQLTypeInfo dfltTypeInfo = (SQLTypeInfo) jdbcType.getChild("DEFAULT");
        SQLTypeInfo sqlType = new SQLTypeInfo(dfltTypeInfo.getTypeName(), (short) Types.BIGINT, dfltTypeInfo.getPrecision(), dfltTypeInfo.getLiteralPrefix(), dfltTypeInfo.getLiteralSuffix(), dfltTypeInfo.getCreateParams(), dfltTypeInfo.getNullable(), dfltTypeInfo.isCaseSensitive(), dfltTypeInfo.getSearchable(), dfltTypeInfo.isUnsignedAttribute(), dfltTypeInfo.isFixedPrecScale(), dfltTypeInfo.isAutoIncrement(), dfltTypeInfo.getLocalTypeName(), dfltTypeInfo.getMinimumScale(), dfltTypeInfo.getMaximumScale(), dfltTypeInfo.getNumPrecRadix());
        addSQLTypeForJDBCType(handler, mconn, (short) Types.BIGINT, sqlType, true);
    }
    jdbcType = (JDBCTypeInfo) typesInfo.getChild("16");
    if (jdbcType != null) {
        // somehow BOOLEAN is set to 16 in the JDBC driver so add it at its correct location
        SQLTypeInfo dfltTypeInfo = (SQLTypeInfo) jdbcType.getChild("DEFAULT");
        SQLTypeInfo sqlType = new SQLTypeInfo(dfltTypeInfo.getTypeName(), (short) Types.BOOLEAN, dfltTypeInfo.getPrecision(), dfltTypeInfo.getLiteralPrefix(), dfltTypeInfo.getLiteralSuffix(), dfltTypeInfo.getCreateParams(), dfltTypeInfo.getNullable(), dfltTypeInfo.isCaseSensitive(), dfltTypeInfo.getSearchable(), dfltTypeInfo.isUnsignedAttribute(), dfltTypeInfo.isFixedPrecScale(), dfltTypeInfo.isAutoIncrement(), dfltTypeInfo.getLocalTypeName(), dfltTypeInfo.getMinimumScale(), dfltTypeInfo.getMaximumScale(), dfltTypeInfo.getNumPrecRadix());
        addSQLTypeForJDBCType(handler, mconn, (short) Types.BOOLEAN, sqlType, true);
    }
}
Also used : JDBCTypeInfo(org.datanucleus.store.rdbms.schema.JDBCTypeInfo) RDBMSTypesInfo(org.datanucleus.store.rdbms.schema.RDBMSTypesInfo) SQLTypeInfo(org.datanucleus.store.rdbms.schema.SQLTypeInfo)

Example 3 with JDBCTypeInfo

use of org.datanucleus.store.rdbms.schema.JDBCTypeInfo in project datanucleus-rdbms by datanucleus.

the class RDBMSStoreManager method getSQLTypeInfoForJDBCType.

/**
 * Accessor for the SQL type info for the specified JDBC type.
 * @param jdbcType JDBC type
 * @param sqlType The SQL type name (if known, otherwise uses the default for this JDBC type).
 * @return SQL type info
 * @throws UnsupportedDataTypeException If the JDBC type is not found
 */
public SQLTypeInfo getSQLTypeInfoForJDBCType(int jdbcType, String sqlType) throws UnsupportedDataTypeException {
    RDBMSTypesInfo typesInfo = (RDBMSTypesInfo) schemaHandler.getSchemaData(null, "types", null);
    JDBCTypeInfo jdbcTypeInfo = (JDBCTypeInfo) typesInfo.getChild("" + jdbcType);
    if (jdbcTypeInfo.getNumberOfChildren() == 0) {
        // No sql-type for this jdbc-type so unsupported
        throw new UnsupportedDataTypeException(Localiser.msg("051005", dba.getNameForJDBCType(jdbcType)));
    }
    SQLTypeInfo sqlTypeInfo = (SQLTypeInfo) jdbcTypeInfo.getChild(sqlType != null ? sqlType : "DEFAULT");
    if (sqlTypeInfo == null && sqlType != null) {
        // Try uppercase form of sql-type
        sqlTypeInfo = (SQLTypeInfo) jdbcTypeInfo.getChild(sqlType.toUpperCase());
        if (sqlTypeInfo == null) {
            // Try lowercase form of sql-type
            sqlTypeInfo = (SQLTypeInfo) jdbcTypeInfo.getChild(sqlType.toLowerCase());
            if (sqlTypeInfo == null) {
                // fallback to DEFAULT
                NucleusLogger.DATASTORE_SCHEMA.debug("Attempt to find JDBC driver 'typeInfo' for jdbc-type=" + dba.getNameForJDBCType(jdbcType) + " but sql-type=" + sqlType + " is not found. Using default sql-type for this jdbc-type.");
                sqlTypeInfo = (SQLTypeInfo) jdbcTypeInfo.getChild("DEFAULT");
            }
        }
    }
    return sqlTypeInfo;
}
Also used : JDBCTypeInfo(org.datanucleus.store.rdbms.schema.JDBCTypeInfo) RDBMSTypesInfo(org.datanucleus.store.rdbms.schema.RDBMSTypesInfo) UnsupportedDataTypeException(org.datanucleus.store.rdbms.exceptions.UnsupportedDataTypeException) SQLTypeInfo(org.datanucleus.store.rdbms.schema.SQLTypeInfo)

Aggregations

JDBCTypeInfo (org.datanucleus.store.rdbms.schema.JDBCTypeInfo)3 RDBMSTypesInfo (org.datanucleus.store.rdbms.schema.RDBMSTypesInfo)3 SQLTypeInfo (org.datanucleus.store.rdbms.schema.SQLTypeInfo)3 Connection (java.sql.Connection)1 Iterator (java.util.Iterator)1 ListIterator (java.util.ListIterator)1 NucleusConnection (org.datanucleus.store.NucleusConnection)1 ManagedConnection (org.datanucleus.store.connection.ManagedConnection)1 DatastoreAdapter (org.datanucleus.store.rdbms.adapter.DatastoreAdapter)1 UnsupportedDataTypeException (org.datanucleus.store.rdbms.exceptions.UnsupportedDataTypeException)1 RDBMSColumnInfo (org.datanucleus.store.rdbms.schema.RDBMSColumnInfo)1 RDBMSSchemaInfo (org.datanucleus.store.rdbms.schema.RDBMSSchemaInfo)1 RDBMSTableInfo (org.datanucleus.store.rdbms.schema.RDBMSTableInfo)1 MacroString (org.datanucleus.util.MacroString)1