use of org.hsqldb_voltpatches.types.Type in project voltdb by VoltDB.
the class Routine method newRoutine.
/**
* Returns a new function Routine object based solely on a Java Method object.
*/
public static Routine newRoutine(Method method) {
Routine routine = new Routine(SchemaObject.FUNCTION);
int offset = 0;
Class[] params = method.getParameterTypes();
String className = method.getDeclaringClass().getName();
StringBuffer sb = new StringBuffer();
sb.append("CLASSPATH:");
sb.append(method.getDeclaringClass().getName()).append('.');
sb.append(method.getName());
if (params.length > 0 && params[0].equals(java.sql.Connection.class)) {
offset = 1;
}
String name = sb.toString();
if (className.equals("org.hsqldb_voltpatches.Library") || className.equals("java.lang.Math")) {
routine.isLibraryRoutine = true;
}
for (int j = offset; j < params.length; j++) {
Type methodParamType = Type.getDefaultTypeWithSize(Types.getParameterSQLTypeNumber(params[j]));
ColumnSchema param = new ColumnSchema(null, methodParamType, !params[j].isPrimitive(), false, null);
routine.addParameter(param);
}
routine.setLanguage(Routine.LANGUAGE_JAVA);
routine.setMethod(method);
routine.setMethodURL(name);
routine.setDataImpact(Routine.NO_SQL);
Type methodReturnType = Type.getDefaultTypeWithSize(Types.getParameterSQLTypeNumber(method.getReturnType()));
routine.javaMethodWithConnection = offset == 1;
;
routine.setReturnType(methodReturnType);
routine.resolve();
return routine;
}
use of org.hsqldb_voltpatches.types.Type in project voltdb by VoltDB.
the class JDBCParameterMetaData method getPrecision.
/**
* Retrieves the designated parameter's specified column size.
*
* <P>The returned value represents the maximum column size for the given parameter.
* For numeric data, this is the maximum precision. For character data, this is the length in characters.
* For datetime datatypes, this is the length in characters of the String representation (assuming the
* maximum allowed precision of the fractional seconds component). For binary data, this is the length in bytes. For the ROWID datatype,
* this is the length in bytes. 0 is returned for data types where the
* column size is not applicable.
*
* @param param the first parameter is 1, the second is 2, ...
* @return precision
* @exception SQLException if a database access error occurs
* @since JDK 1.4, HSQLDB 1.7.2
*/
public int getPrecision(int param) throws SQLException {
checkRange(param);
Type type = rmd.columnTypes[--param];
if (type.isDateTimeType()) {
return type.displaySize();
} else {
long size = type.precision;
if (size > Integer.MAX_VALUE) {
size = 0;
}
return (int) size;
}
}
use of org.hsqldb_voltpatches.types.Type in project voltdb by VoltDB.
the class JDBCPreparedStatement method setParameter.
/**
* The internal parameter value setter always converts the parameter to
* the Java type required for data transmission.
*
* @param i parameter index
* @param o object
* @throws SQLException if either argument is not acceptable.
*/
void setParameter(int i, Object o) throws SQLException {
checkSetParameterIndex(i, false);
i--;
if (o == null) {
parameterValues[i] = null;
return;
}
Type outType = parameterTypes[i];
switch(outType.typeCode) {
case Types.OTHER:
try {
if (o instanceof Serializable) {
o = new JavaObjectData((Serializable) o);
break;
}
} catch (HsqlException e) {
Util.throwError(e);
}
Util.throwError(Error.error(ErrorCode.X_42565));
break;
case Types.SQL_BIT:
case Types.SQL_BIT_VARYING:
if (o instanceof Boolean) {
if (outType.precision == 1) {
byte[] bytes = ((Boolean) o).booleanValue() ? new byte[] { -0x80 } : new byte[] { 0 };
o = new BinaryData(bytes, 1);
break;
}
Util.throwError(Error.error(ErrorCode.X_42565));
}
try {
if (o instanceof byte[]) {
o = outType.convertToDefaultType(connection.sessionProxy, o);
break;
}
if (o instanceof String) {
o = outType.convertToDefaultType(connection.sessionProxy, o);
break;
}
} catch (HsqlException e) {
Util.throwError(e);
}
Util.throwError(Error.error(ErrorCode.X_42565));
// $FALL-THROUGH$
case Types.SQL_BINARY:
case Types.SQL_VARBINARY:
if (o instanceof byte[]) {
o = new BinaryData((byte[]) o, !connection.isNetConn);
break;
}
try {
if (o instanceof String) {
o = outType.convertToDefaultType(connection.sessionProxy, o);
break;
}
} catch (HsqlException e) {
Util.throwError(e);
}
Util.throwError(Error.error(ErrorCode.X_42565));
break;
case Types.SQL_BLOB:
setBlobParameter(i + 1, o);
return;
case Types.SQL_CLOB:
setClobParameter(i + 1, o);
return;
case Types.SQL_DATE:
case Types.SQL_TIME_WITH_TIME_ZONE:
case Types.SQL_TIMESTAMP_WITH_TIME_ZONE:
case Types.SQL_TIME:
case Types.SQL_TIMESTAMP:
{
try {
if (o instanceof String) {
o = outType.convertToType(connection.sessionProxy, o, Type.SQL_VARCHAR);
break;
}
o = outType.convertJavaToSQL(connection.sessionProxy, o);
break;
} catch (HsqlException e) {
Util.throwError(e);
}
}
// $FALL-THROUGH$
case Types.TINYINT:
case Types.SQL_SMALLINT:
case Types.SQL_INTEGER:
case Types.SQL_BIGINT:
case Types.SQL_REAL:
case Types.SQL_FLOAT:
case Types.SQL_DOUBLE:
case Types.SQL_NUMERIC:
case Types.SQL_DECIMAL:
try {
if (o instanceof String) {
o = outType.convertToType(connection.sessionProxy, o, Type.SQL_VARCHAR);
break;
}
o = outType.convertToDefaultType(connection.sessionProxy, o);
break;
} catch (HsqlException e) {
Util.throwError(e);
}
// $FALL-THROUGH$
default:
try {
o = outType.convertToDefaultType(connection.sessionProxy, o);
break;
} catch (HsqlException e) {
Util.throwError(e);
}
}
parameterValues[i] = o;
}
use of org.hsqldb_voltpatches.types.Type in project voltdb by VoltDB.
the class JDBCDatabaseMetaData method supportsConvert.
/** @todo needs the full conversion matrix here. Should use org.hsqldb_voltpatches.types */
/**
* (JDBC4 clarification:)
* Retrieves whether this database supports the JDBC scalar function
* <code>CONVERT</code> for conversions between the JDBC types <i>fromType</i>
* and <i>toType</i>. The JDBC types are the generic SQL data types defined
* in <code>java.sql.Types</code>.
*
* <!-- start release-specific documentation -->
* <div class="ReleaseSpecificDocumentation">
* <h3>HSQLDB-Specific Information:</h3> <p>
*
* HSQLDB 1.9.0 supports conversion according to SQL standards. In addition,
* it supports conversion between values of BOOLEAN and BIT types.
* </div>
* <!-- end release-specific documentation -->
*
*
* @param fromType the type to convert from; one of the type codes from
* the class <code>java.sql.Types</code>
* @param toType the type to convert to; one of the type codes from
* the class <code>java.sql.Types</code>
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
* @see java.sql.Types
*/
public boolean supportsConvert(int fromType, int toType) throws SQLException {
//#ifdef JAVA6
switch(fromType) {
case java.sql.Types.NCHAR:
{
fromType = java.sql.Types.CHAR;
break;
}
case java.sql.Types.NCLOB:
{
fromType = java.sql.Types.CLOB;
break;
}
case java.sql.Types.NVARCHAR:
{
fromType = java.sql.Types.VARCHAR;
break;
}
}
switch(toType) {
case java.sql.Types.NCHAR:
{
toType = java.sql.Types.CHAR;
break;
}
case java.sql.Types.NCLOB:
{
toType = java.sql.Types.CLOB;
break;
}
case java.sql.Types.NVARCHAR:
{
toType = java.sql.Types.VARCHAR;
break;
}
}
//#endif JAVA6
Type from = Type.getDefaultType(Type.getHSQLDBTypeCode(fromType));
Type to = Type.getDefaultType(Type.getHSQLDBTypeCode(toType));
if (from == null || to == null) {
return false;
}
return to.canConvertFrom(from);
}
use of org.hsqldb_voltpatches.types.Type in project voltdb by VoltDB.
the class Grantee method getRightsSQL.
public HsqlArrayList getRightsSQL() {
HsqlArrayList list = new HsqlArrayList();
String roleString = getDirectRolesAsString();
if (roleString.length() != 0) {
list.add("GRANT " + roleString + " TO " + getStatementName());
}
MultiValueHashMap rightsMap = getRights();
Iterator dbObjects = rightsMap.keySet().iterator();
while (dbObjects.hasNext()) {
Object nameObject = dbObjects.next();
Iterator rights = rightsMap.get(nameObject);
while (rights.hasNext()) {
Right right = (Right) rights.next();
StringBuffer sb = new StringBuffer(128);
HsqlName hsqlname = (HsqlName) nameObject;
switch(hsqlname.type) {
case SchemaObject.TABLE:
case SchemaObject.VIEW:
Table table = granteeManager.database.schemaManager.findUserTable(null, hsqlname.name, hsqlname.schema.name);
if (table != null) {
sb.append(Tokens.T_GRANT).append(' ');
sb.append(right.getTableRightsSQL(table));
sb.append(' ').append(Tokens.T_ON).append(' ');
sb.append("TABLE ").append(hsqlname.getSchemaQualifiedStatementName());
}
break;
case SchemaObject.SEQUENCE:
NumberSequence sequence = (NumberSequence) granteeManager.database.schemaManager.findSchemaObject(hsqlname.name, hsqlname.schema.name, SchemaObject.SEQUENCE);
if (sequence != null) {
sb.append(Tokens.T_GRANT).append(' ');
sb.append(Tokens.T_USAGE);
sb.append(' ').append(Tokens.T_ON).append(' ');
sb.append("SEQUENCE ").append(hsqlname.getSchemaQualifiedStatementName());
}
break;
case SchemaObject.DOMAIN:
Type domain = (Type) granteeManager.database.schemaManager.findSchemaObject(hsqlname.name, hsqlname.schema.name, SchemaObject.DOMAIN);
if (domain != null) {
sb.append(Tokens.T_GRANT).append(' ');
sb.append(Tokens.T_USAGE);
sb.append(' ').append(Tokens.T_ON).append(' ');
sb.append("DOMAIN ").append(hsqlname.getSchemaQualifiedStatementName());
}
break;
case SchemaObject.TYPE:
Type type = (Type) granteeManager.database.schemaManager.findSchemaObject(hsqlname.name, hsqlname.schema.name, SchemaObject.DOMAIN);
if (type != null) {
sb.append(Tokens.T_GRANT).append(' ');
sb.append(Tokens.T_USAGE);
sb.append(' ').append(Tokens.T_ON).append(' ');
sb.append("TYPE ").append(hsqlname.getSchemaQualifiedStatementName());
}
break;
}
if (sb.length() == 0) {
continue;
}
sb.append(' ').append(Tokens.T_TO).append(' ');
sb.append(getStatementName());
list.add(sb.toString());
}
}
return list;
}
Aggregations