
com.viaoa.ds.jdbc.delegate.VerifyDelegate Maven / Gradle / Ivy
/*
This software and documentation is the confidential and proprietary
information of ViaOA, Inc. ("Confidential Information").
You shall not disclose such Confidential Information and shall use
it only in accordance with the terms of the license agreement you
entered into with ViaOA, Inc.
ViaOA, Inc. MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE, OR NON-INFRINGEMENT. ViaOA, Inc. SHALL NOT BE LIABLE FOR ANY DAMAGES
SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
THIS SOFTWARE OR ITS DERIVATIVES.
Copyright (c) 2001-2013 ViaOA, Inc.
All rights reserved.
*/
package com.viaoa.ds.jdbc.delegate;
import java.sql.*;
import java.util.logging.Logger;
import com.viaoa.ds.jdbc.db.*;
import com.viaoa.ds.jdbc.*;
import com.viaoa.util.OAString;
/**
* Methods to validate that OAObject database metadata matches database scheme.
* @author vvia
*
*/
public class VerifyDelegate {
private static Logger LOG = Logger.getLogger(VerifyDelegate.class.getName());
public static boolean verify(OADataSourceJDBC ds) throws Exception {
Connection connection = null;
try {
connection = ds.getConnection(true);
boolean b = _verify(ds, connection);
return b;
}
catch (Exception e) {
return false;
}
finally {
if (connection != null) {
ds.releaseConnection(connection);
}
}
}
/**
Verifies Tables, Columns and Indexes. Prints to console window.
@returns true if all tables, columns and indexes exist, else returns false if any are missing.
*/
private static boolean _verify(OADataSourceJDBC ds, Connection connection) throws Exception {
DatabaseMetaData dbmd = connection.getMetaData();
ResultSet rs;
boolean bResult = true;
Table[] tables = ds.getDatabase().getTables();
for (int i=0; i iSize) {
String s = DDLDelegate.getAlterColumnSQL(ds.getDBMetaData(), t.name, c.columnName, "VARCHAR(" + c.maxLength + ")");
ds.execute(s);
LOG.warning("-- resized Column: "+t.name+"."+c.columnName+" from " + iSize + " to " + c.maxLength+ " : " + s);
}
else {
c.maxLength = iSize;
LOG.warning("-- will use column size of " + c.maxLength);
}
*/
continue;
}
}
}
else {
b = false;
// see if CLOB or LONGVARCHAR match
if (iType == java.sql.Types.LONGVARCHAR || iType == java.sql.Types.CLOB) {
if (c.getSqlType() == java.sql.Types.LONGVARCHAR || c.getSqlType() == java.sql.Types.CLOB) {
b = true;
}
}
if (!b && iType == java.sql.Types.VARCHAR && dbx != null && dbx.databaseType == dbx.SQLSERVER) {
if (c.getSqlType() == java.sql.Types.CLOB && iSize > Math.pow(10, 9)) {
b = true;
}
}
if (!b && iType == java.sql.Types.VARBINARY && dbx != null && dbx.databaseType == dbx.SQLSERVER) {
if (c.getSqlType() == java.sql.Types.BLOB) {
b = true;
}
}
if (iType == java.sql.Types.BIT || iType == java.sql.Types.BOOLEAN) {
if (c.getSqlType() == java.sql.Types.BIT || c.getSqlType() == java.sql.Types.BOOLEAN) {
b = true;
}
}
if (iType == java.sql.Types.SMALLINT || iType == java.sql.Types.BOOLEAN || iType == java.sql.Types.CHAR || iType == java.sql.Types.BIT) {
if (c.getSqlType() == java.sql.Types.BIT || c.getSqlType() == java.sql.Types.BOOLEAN) {
b = true;
}
}
if (!b && (iType == java.sql.Types.REAL || iType == java.sql.Types.DOUBLE)) {
if (c.getSqlType() == java.sql.Types.REAL || c.getSqlType() == java.sql.Types.DOUBLE) {
b = true;
}
}
if (!b && (iType == java.sql.Types.TIMESTAMP)) {
if (c.getSqlType() == java.sql.Types.DATE || c.getSqlType() == java.sql.Types.TIME) {
b = true;
}
}
if (!b) {
LOG.warning("DB ERROR: Column TYPE mismatch: "+t.name+"."+c.columnName+" ds:"+c.getSqlType()+" != db:"+iType);
continue;
}
}
}
rs.close();
if (!b) {
bResult = false;
LOG.warning("DB ERROR: Column not found: "+t.name+"."+c.columnName);
continue;
}
if (c.columnLowerName != null && c.columnLowerName.length() > 0) {
rs = dbmd.getColumns(null,null,t.name.toUpperCase(),c.columnLowerName.toUpperCase());
b = rs.next();
rs.close();
if (!b) {
bResult = false;
LOG.warning("DB ERROR: Column not found: "+t.name+"."+c.columnLowerName);
continue;
}
}
if (c.primaryKey) {
rs = dbmd.getPrimaryKeys(null, null, t.name.toUpperCase());
b = rs.next();
String colname=null;
String pkname=null;
if (b) {
colname = rs.getString(4); // column name
pkname = rs.getString(6); // pk name
b = pkname.equalsIgnoreCase("PK"+t.name);
}
rs.close();
if (!b) {
LOG.warning("DB ERROR: PK missing: "+" PK" + t.name+" "+t.name+"."+c.columnName + " - FOUND: pkName="+pkname+", colname="+colname);
}
}
// public static String convert(DBMetaData dbmd, Column column, Object value) {
try {
ConverterDelegate.convert(ds.getDBMetaData(), c, "1");
}
catch (Exception e) {
LOG.warning("DB ERROR: ConverterDelegate wont be able to convert column type: Table:" + t.name + " Column:" + c.columnName);
bResult = false;
}
}
Index[] indexes = t.getIndexes();
for (int j=0; j
© 2015 - 2025 Weber Informatics LLC | Privacy Policy