📄 stringcolumnspec.java
字号:
/*
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations under
* the License.
*
* The Original Code is jRelationalFramework.
*
* The Initial Developer of the Original Code is is.com.
* Portions created by is.com are Copyright (C) 2000 is.com.
* All Rights Reserved.
*
* Contributor(s): Jonathan Carlson (joncrlsn@users.sf.net)
* Contributor(s): ____________________________________
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License (the "GPL") or the GNU Lesser General
* Public license (the "LGPL"), in which case the provisions of the GPL or
* LGPL are applicable instead of those above. If you wish to allow use of
* your version of this file only under the terms of either the GPL or LGPL
* and not to allow others to use your version of this file under the MPL,
* indicate your decision by deleting the provisions above and replace them
* with the notice and other provisions required by either the GPL or LGPL
* License. If you do not delete the provisions above, a recipient may use
* your version of this file under either the MPL or GPL or LGPL License.
*
*/
package com.is.jrf;
import com.is.util.sql.JDBCHelper;
import java.sql.SQLException;
/**
* This subclass of AbstractColumnSpec does String-specific things.
*/
public class StringColumnSpec
extends AbstractColumnSpec
{
/* =============== Static Variables =============== */
protected static Class s_class = String.class;
/* =============== Constructors =============== */
public StringColumnSpec(
String columnName,
String getter,
String setter,
Object defaultValue)
{
super(columnName,
getter,
setter,
(String) defaultValue);
}
public StringColumnSpec(
String columnName,
String getter,
String setter,
Object defaultValue,
int option1)
{
super(columnName,
getter,
setter,
(String) defaultValue,
option1);
}
public StringColumnSpec(
String columnName,
String getter,
String setter,
Object defaultValue,
int option1,
int option2)
{
super(columnName,
getter,
setter,
(String) defaultValue,
option1,
option2);
}
public StringColumnSpec(
String columnName,
String getter,
String setter,
Object defaultValue,
int option1,
int option2,
int option3)
{
super(columnName,
getter,
setter,
(String) defaultValue,
option1,
option2,
option3);
}
/**
* This method overrides the superclass implementation. A string of
* "null" is returned if object is null, otherwise it returns a String
* with quotes around it. Internal single quotes are converted to
* two single quotes and the string is wrapped in single quotes.
*
* @param aValueObject a value of type 'ValueObject'
* @return a value of type 'String'
*/
public String formatForSql(Object obj, DatabasePolicy dbPolicy)
{
String returnValue = "null";
if (obj != null)
{
returnValue = JDBCHelper.delimitString((String)obj, "'");
}
return returnValue;
} // formatForSql(...)
/**
* This method goes with encode(). The String parameter must have been
* created by the encode() method.
*
* @param aString a value of type 'String'
* @return a value of type 'Object' (This actually will be a String or null)
*/
public Object decode(String aString)
{
if (aString.trim().equals("null"))
{
return null;
}
return aString;
}
public Class getColumnClass()
{
return s_class;
}
/**
* Return a String from JDBCHelper. If String is one blank, return an
* empty string. This resolves a strange issue with SQLServer (and maybe
* Sybase) that keeps returning empty or whitespace strings as one blank
* character. If one blank is truly desired, then maybe this should go
* into the DatabasePolicy, but then we'll have differing behavior when
* switching databases.
*
* @param helper a value of type 'JDBCHelper'
* @return a value of type 'Object'
* @exception SQLException if an error occurs in JDBCHelper
*/
public Object getColumnValueFrom(JDBCHelper helper)
throws SQLException
{
String returnValue = helper.getString(this.getColumnName());
// This if is here to solve a problem with SQLServer where an empty
// string is returned as a one character blank string.
if (returnValue != null &&
returnValue.equals(" "))
{
returnValue = "";
}
return returnValue;
}
/**
* This is an override of the superclass implementation. This method adds
* a check to make sure the string is not empty or blank.
*
* @param aPO a value of type 'PersistentObject'
* @return a value of type 'Object'
* @exception MissingAttributeException if an error occurs
*/
public Object validateRequired(PersistentObject aPO)
throws MissingAttributeException
{
String value = (String) super.validateRequired(aPO);
// a null value tells us it had to be non-required or an error would
// have been thrown.
if (value != null &&
value.trim().length() == 0)
{
throw new MissingAttributeException(
"Required attribute - "
+ this.getColumnName()
+ "- is an empty string value.");
}
return value;
} // validateRequired(aPersistentObject)
/**
* Return the ANSI standard SQL column type. This was written to support
* the test suites. If there is no standard that will work across
* platforms, then we'll add a method to dbPolicy and return its' value.
*
* @param dbPolicy a value of type 'DatabasePolicy'
* @return a value of type 'String'
*/
public String getSQLColumnType(DatabasePolicy dbPolicy)
{
return "VARCHAR(255)";
}
public JoinColumn buildJoinColumn()
{
return new StringJoinColumn(this.getColumnName(),
this.getSetter());
}
} // StringColumnSpec
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -