?? classmap.java
字號:
{
for (int i = 0; i < classMap.getSize(); i++)
{
statement.addSqlClause((isFirst ? "" : ", ") +
classMap.getAttributeMap(i).getColumnMap().getFullyQualifiedName());
isFirst = false;
}
classMap = classMap.getSuperClass();
}
while(classMap != null);
return statement;
}
/**
* Returns the first select sql statement for this class map.
* @return pl.sql.SqlStatement
* @param obj pl.PersistentObject
*/
public SqlStatement getSelectProxySql() throws PlException
{
// Create new statement
SqlStatement statement = new SqlStatement();
// Add 'SELECT' clause to the select statement
statement.addSqlClause(getRelationalDatabase().getClauseStringSelect() + " ");
// Add clauses for all attributes. Do not add ", " before the first attribute
boolean isFirst = true;
ClassMap classMap = this;
do
{
for (int i = 0; i < classMap.getProxySize(); i++)
{
statement.addSqlClause((isFirst ? "" : ", ") +
classMap.getProxyAttributeMap(i).getColumnMap().getFullyQualifiedName());
isFirst = false;
}
classMap = classMap.getSuperClass();
}
while(classMap != null);
return statement;
}
/**
* Returns select sql statement for the timestamp attribute of the given object.
* @return pl.sql.SqlStatement
* @param obj pl.PersistentObject
*/
public SqlStatement getSelectSqlFor(PersistentObject object) throws PlException
{
// Clone statement
SqlStatement statement = (SqlStatement)selectStatement.clone();
// Fill statement with values
for(int i = 0; i < getKeySize(); i++)
{
AttributeMap aMap = getKeyAttributeMap(i);
Object value = aMap.getColumnMap().getConverter().convertFrom(aMap.getValue(object));
statement.addParameter(value, aMap.getColumnMap().getPlType());
}
return statement;
}
/**
* Returns select sql statement for the timestamp attribute of the given object.
* @return pl.sql.SqlStatement
* @param obj pl.PersistentObject
*/
public SqlStatement getSelectProxySqlFor(PersistentObject object) throws PlException
{
// Clone statement
SqlStatement statement = (SqlStatement)selectProxyStatement.clone();
// Fill statement with values
for(int i = 0; i < getKeySize(); i++)
{
AttributeMap aMap = getKeyAttributeMap(i);
Object value = aMap.getColumnMap().getConverter().convertFrom(aMap.getValue(object));
statement.addParameter(value, aMap.getColumnMap().getPlType());
}
return statement;
}
/**
* Returns delete sql statement for the given object.
* @return pl.sql.SqlStatement
* @param obj pl.PersistentObject
*/
public SqlStatement getSelectTimestampSqlFor(PersistentObject object) throws PlException
{
// Check if optimistic lock is supported by the object
// Try to find timestamp attribute map
if(selectTimestampStatement == null)
{
throw new OptimisticLockException("Optimistic lock is not supported by the object");
}
// Clone statement
SqlStatement statement = (SqlStatement)selectTimestampStatement.clone();
// Fill statement with values
for(int i = 0; i < getKeySize(); i++)
{
AttributeMap aMap = getKeyAttributeMap(i);
Object value = aMap.getColumnMap().getConverter().convertFrom(aMap.getValue(object));
statement.addParameter(value, aMap.getColumnMap().getPlType());
}
return statement;
}
/**
* Returns number of attribute maps.
* @return int
*/
public int getSize()
{
return attributeMaps.size();
}
/**
* Returns the straight association map with the specified index.
*
* @return pl.map.UniDirectionalAssociationMap
* @param index index
*/
public UniDirectionalAssociationMap getStraightAssociationMap(int index)
{
return (UniDirectionalAssociationMap)straightAssociationMaps.get(index);
}
/**
* Returns the number of straight association maps.
*
* @return int
*/
public int getStraightAssociationMapSize()
{
return straightAssociationMaps.size();
}
/**
* Returns ClassMap for superclass.
* @return pl.map.ClassMap
*/
public ClassMap getSuperClass()
{
return superClass;
}
/**
* Insert the method's description here.
* Creation date: (27.07.00 12:26:20)
* @return java.util.HashSet
*/
public java.util.HashSet getTables()
{
return tables;
}
/**
* Returns attribute map for the timestamp attribute of this class map.
*
* @return attribute map for the timestamp attribute of this class map
*/
public AttributeMap getTimestampAttributeMap()
{
return timestampAttributeMap;
}
/**
* Returns update sql statement for the given object.
* @return pl.sql.SqlStatement
* @param obj pl.PersistentObject
*/
public SqlStatement getUpdateSqlFor(PersistentObject object) throws PlException
{
// Clone statement
SqlStatement statement = (SqlStatement)updateStatement.clone();
// Fill statement with values
for(int i = 0; i < getUpdateSize(); i++)
{
AttributeMap aMap = getUpdateAttributeMap(i);
Object value = aMap.getColumnMap().getConverter().convertFrom(aMap.getValue(object));
statement.addParameter(value, aMap.getColumnMap().getPlType());
}
for(int i = 0; i < getKeySize(); i++)
{
AttributeMap aMap = getAttributeMap(i);
Object value = aMap.getColumnMap().getConverter().convertFrom(aMap.getValue(object));
statement.addParameter(value, aMap.getColumnMap().getPlType());
}
return statement;
}
public String getXmlName()
{
return xmlName;
}
/**
* Init this class map.
*/
public synchronized void init() throws pl.PlException
{
// We don't have to init class map twice
if(isInited)
return;
// Init all statements
//
// Init SELECT statement
//
selectStatement = getSelectSql();
// Add 'FROM' and 'WHERE' clauses to the select statement
selectStatement.addSqlClause(" ");
selectStatement.addSqlStatement(getFromAndWhereSql());
//
// Init SELECT statement for proxy
//
selectProxyStatement = getSelectProxySql();
// Add 'FROM' and 'WHERE' clauses to the select statement
selectProxyStatement.addSqlClause(" ");
selectProxyStatement.addSqlStatement(getFromAndWhereSql());
//
// Init SELECT statement for timestamp
//
ClassMap cm = this;
AttributeMap am = null;
while(cm != null)
{
am = cm.getTimestampAttributeMap();
if(am != null)
break;
cm = cm.getSuperClass();
}
if(am != null)
{
// Create new statement
selectTimestampStatement = new SqlStatement();
// Add 'SELECT' clause to the select statement
selectTimestampStatement.addSqlClause(getRelationalDatabase().getClauseStringSelect() + " ");
selectTimestampStatement.addSqlClause(am.getColumnMap().getFullyQualifiedName());
// Add 'FROM' and 'WHERE' clauses to the select statement
selectTimestampStatement.addSqlStatement(getFromAndWhereSql());
// Add FOR UPDATE clause if object needs to be locked
selectTimestampStatement.addSqlClause(" " + getRelationalDatabase().getClauseStringForUpdate());
}
//
// Init UPDATE statement
//
updateStatement = new SqlStatement();
// Add 'UPDATE' clause to the select statement
updateStatement.addSqlClause(getRelationalDatabase().getClauseStringUpdate() + " ");
AttributeMap map = getAttributeMap(0);
if(map != null)
{
updateStatement.addSqlClause(map.getColumnMap().getTableMap().getName() + " ");
}
// Add 'SET' clause to the select statement
updateStatement.addSqlClause(getRelationalDatabase().getClauseStringSet() + " ");
// Add clauses for all attributes. Do not add ", " before the first attribute
for (int i = 0; i < getUpdateSize(); i++)
{
updateStatement.addSqlClause((i > 0 ? ", " : "") +
getUpdateAttributeMap(i).getColumnMap().getName() + "=?");
}
// Add 'WHERE key=?' to the select statement
updateStatement.addSqlClause(" " + getRelationalDatabase().getClauseStringWhere() + " ");
for(int i = 0; i < getKeySize(); i++)
{
updateStatement.addSqlClause((i > 0 ? " AND " : "") +
getKeyAttributeMap(i).getColumnMap().getName() + "=?");
}
//
// Init INSERT statement
//
insertStatement = new SqlStatement();
// Add 'INSERT INTO' clause to the select statement
insertStatement.addSqlClause(getRelationalDatabase().getClauseStringInsert() + " ");
if(map != null)
{
insertStatement.addSqlClause(map.getColumnMap().getTableMap().getName() + " ");
}
// Add clauses for all attributes. Do not add ", " before the first attribute
insertStatement.addSqlClause("(");
for (int i = 0; i < getSize(); i++)
{
insertStatement.addSqlClause((i > 0 ? ", " : "") + getAttributeMap(i).getColumnMap().getName());
}
insertStatement.addSqlClause(") ");
// Add 'VALUES' clause to the select statement
insertStatement.addSqlClause(getRelationalDatabase().getClauseStringValues() + " ");
insertStatement.addSqlClause("(");
for (int i = 0; i < attributeMaps.size(); i++)
{
insertStatement.addSqlClause((i > 0 ? ", " : "") + "?");
}
insertStatement.addSqlClause(") ");
//
// Init DELETE statement
//
deleteStatement = new SqlStatement();
// Add 'DELETE FROM' clause to the select statement
deleteStatement.addSqlClause(getRelationalDatabase().getClauseStringDelete() + " " + getRelationalDatabase().getClauseStringFrom() + " ");
if(map != null)
{
deleteStatement.addSqlClause(map.getColumnMap().getTableMap().getName() + " ");
}
// Add 'WHERE key=?' to the select statement
deleteStatement.addSqlClause(getRelationalDatabase().getClauseStringWhere() + " ");
for(int i = 0; i < getKeySize(); i++)
{
deleteStatement.addSqlClause((i > 0 ? " AND " : "") +
getKeyAttributeMap(i).getColumnMap().getName() + "=?");
}
isInited = true;
}
/**
* Adds new association map to this class map.
*
* @param map pl.map.UniDirectionalAssociationMap
*/
public void putAssociationMap(UniDirectionalAssociationMap map)
{
associationMaps.put(map.getTargetName(), map);
if(map.isInverse())
inverseAssociationMaps.add(map);
else
straightAssociationMaps.add(map);
}
/**
* Retrieves data from ResultSet and puts them to the object.
* @param object pl.PersistentObject
* @param rs java.sql.ResultSet
*/
public void retrieveObject(PersistentObject object, java.sql.ResultSet rs) throws PlException
{
ClassMap classMap = this;
Object value = null;
int index = 1;
do
{
for (int i = 0; i < classMap.getSize(); i++)
{
value = PlTypes.getValue(rs, index, classMap.getAttributeMap(i).getColumnMap().getPlType());
classMap.getAttributeMap(i).setValue(object,
classMap.getAttributeMap(i).getColumnMap().getConverter().convertTo(value));
index++;
}
classMap = classMap.getSuperClass();
}
while (classMap != null);
object.setPersistent(true);
object.setProxy(false);
}
/**
* Retrieves data from ResultSet and puts them to the object.
* @param object pl.PersistentObject
* @param rs java.sql.ResultSet
*/
public void retrieveProxyObject(PersistentObject object, java.sql.ResultSet rs) throws PlException
{
ClassMap classMap = this;
Object value = null;
int index = 1;
do
{
for (int i = 0; i < classMap.getProxySize(); i++)
{
value = PlTypes.getValue(rs, index, classMap.getProxyAttributeMap(i).getColumnMap().getPlType());
classMap.getProxyAttributeMap(i).setValue(object,
classMap.getProxyAttributeMap(i).getColumnMap().getConverter().convertTo(value));
index++;
}
classMap = classMap.getSuperClass();
}
while (classMap != null);
object.setPersistent(true);
object.setProxy(true);
}
/**
* Sets ClassMap for super class of this class.
*
* @param newSuperClass pl.map.ClassMap
*/
public void setSuperClass(ClassMap superClass)
{
this.superClass = superClass;
}
/**
* Sets attribute map for the timestamp attribute of this class map.
*
* @param timestampAttributeMap
*/
public void setTimestampAttributeMap(AttributeMap timestampAttributeMap)
{
this.timestampAttributeMap = timestampAttributeMap;
}
public void setXmlName(String xmlName)
{
this.xmlName = xmlName;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -