
com.viaoa.ds.jdbc.delegate.Delegate 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.lang.reflect.*;
import java.sql.Statement;
import com.viaoa.ds.jdbc.*;
import com.viaoa.ds.jdbc.db.*;
import com.viaoa.ds.jdbc.query.*;
import com.viaoa.object.*;
/**
* Used to get additional information about a JDBC DataSource.
* @author vvia
*
*/
public class Delegate {
/**
Returns max length allowed for a property. returns "-1" for any length
*/
public static int getPropertyMaxLength(OADataSourceJDBC ds, Class c, String propertyName) {
QueryConverter qc = new QueryConverter(ds);
Class[] classes = qc.getSelectClasses(c);
for (int i=0; classes != null && i < classes.length; i++) {
Table table = ds.getDatabase().getTable(classes[i]);
if (table == null) continue;
Column[] columns = table.getSelectColumns();
for (int ii=0; columns != null && ii < columns.length; ii++) {
if (propertyName.equalsIgnoreCase(columns[ii].propertyName)) {
return getMaxLength(columns[ii]);
}
}
}
return -1;
}
public static int getPropertyMaxLength(Database database, Class c, String propertyName) {
for (Table table : database.getTables()) {
Column[] columns = table.getSelectColumns();
for (int ii=0; columns != null && ii < columns.length; ii++) {
if (propertyName.equalsIgnoreCase(columns[ii].propertyName)) {
return getMaxLength(columns[ii]);
}
}
}
return -1;
}
public static int getMaxLength(Column c) {
if (c == null) return -1;
Method m = c.getGetMethod();
if (m != null) {
if (m.getReturnType().equals(String.class)) {
if (c.maxLength < 256) {
int type = c.getSqlType();
if (type == 0 || type == java.sql.Types.VARCHAR || type == java.sql.Types.CHAR) {
return c.maxLength;
}
}
}
return -1;
}
return c.maxLength;
}
public static void adjustDatabase(OADataSourceJDBC ds) {
if (ds == null) return;
Database database = ds.getDatabase();
DBMetaData dbmd = ds.getDBMetaData();
Table[] tables = database.getTables();
for (int i=0; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy