Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* PlasmaSDO™ License
*
* This is a community release of PlasmaSDO™, a dual-license
* Service Data Object (SDO) 2.1 implementation.
* This particular copy of the software is released under the
* version 2 of the GNU General Public License. PlasmaSDO™ was developed by
* TerraMeta Software, Inc.
*
* Copyright (c) 2013, TerraMeta Software, Inc. All rights reserved.
*
* General License information can be found below.
*
* This distribution may include materials developed by third
* parties. For license and attribution notices for these
* materials, please refer to the documentation that accompanies
* this distribution (see the "Licenses for Third-Party Components"
* appendix) or view the online documentation at
* .
*
*/
package org.plasma.sdo.jdbc.service;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.plasma.sdo.DataFlavor;
import org.plasma.sdo.PlasmaDataObject;
import org.plasma.sdo.PlasmaProperty;
import org.plasma.sdo.PlasmaType;
import org.plasma.sdo.access.DataAccessException;
import org.plasma.sdo.access.provider.common.PropertyPair;
import org.plasma.sdo.access.provider.jdbc.AliasMap;
import org.plasma.sdo.core.CoreDataObject;
import org.plasma.sdo.jdbc.filter.FilterAssembler;
import org.plasma.sdo.profile.ConcurrencyType;
import org.plasma.sdo.profile.ConcurrentDataFlavor;
import org.plasma.sdo.profile.KeyType;
import commonj.sdo.Property;
public abstract class JDBCSupport {
private static Log log = LogFactory.getFactory().getInstance(JDBCSupport.class);
protected RDBDataConverter converter = RDBDataConverter.INSTANCE;
protected JDBCSupport() {
}
protected StringBuilder createSelectForUpdate(PlasmaType type, List keyValues,
int waitSeconds) {
StringBuilder sql = new StringBuilder();
sql.append("SELECT ");
List props = new ArrayList();
for (PropertyPair pair : keyValues)
props.add(pair.getProp());
Property lockingUserProperty = type.findProperty(ConcurrencyType.pessimistic,
ConcurrentDataFlavor.user);
if (lockingUserProperty != null)
props.add(lockingUserProperty);
else if (log.isDebugEnabled())
log.debug("could not find locking user property for type, " + type.getURI() + "#"
+ type.getName());
Property lockingTimestampProperty = type.findProperty(ConcurrencyType.pessimistic,
ConcurrentDataFlavor.time);
if (lockingTimestampProperty != null)
props.add(lockingTimestampProperty);
else if (log.isDebugEnabled())
log.debug("could not find locking timestamp property for type, " + type.getURI() + "#"
+ type.getName());
Property concurrencyUserProperty = type.findProperty(ConcurrencyType.optimistic,
ConcurrentDataFlavor.user);
if (concurrencyUserProperty != null)
props.add(concurrencyUserProperty);
else if (log.isDebugEnabled())
log.debug("could not find optimistic concurrency (username) property for type, "
+ type.getURI() + "#" + type.getName());
Property concurrencyTimestampProperty = type.findProperty(ConcurrencyType.optimistic,
ConcurrentDataFlavor.time);
if (concurrencyTimestampProperty != null)
props.add(concurrencyTimestampProperty);
else if (log.isDebugEnabled())
log.debug("could not find optimistic concurrency timestamp property for type, "
+ type.getURI() + "#" + type.getName());
int i = 0;
for (Property p : props) {
PlasmaProperty prop = (PlasmaProperty) p;
if (prop.isMany() && !prop.getType().isDataType())
continue;
if (i > 0)
sql.append(", ");
sql.append("t0.");
sql.append(prop.getPhysicalName());
i++;
}
sql.append(" FROM ");
sql.append(getQualifiedPhysicalName(type));
sql.append(" t0 ");
sql.append(" WHERE ");
for (int k = 0; k < keyValues.size(); k++) {
if (k > 0)
sql.append(", ");
PropertyPair propValue = keyValues.get(k);
sql.append("t0.");
sql.append(propValue.getProp().getPhysicalName());
sql.append(" = ");
try {
appendValue(propValue, sql);
} catch (SQLException e) {
throw new JDBCServiceException(e);
}
}
// FIXME: vendor specific checks
// if Oracle
// sql.append(" FOR UPDATE WAIT ");
// sql.append(String.valueOf(waitSeconds));
// if MySql
sql.append(" FOR UPDATE");
return sql;
}
protected String getQualifiedPhysicalName(PlasmaType type) {
String packageName = type.getPackagePhysicalName();
if (packageName != null)
return packageName + "." + type.getPhysicalName();
else
return type.getPhysicalName();
}
protected StringBuilder createSelect(PlasmaType type, List names,
List keyValues) throws SQLException {
StringBuilder sql = new StringBuilder();
sql.append("SELECT ");
int count = 0;
// always select pk props where not found in given list
List pkProps = type.findProperties(KeyType.primary);
for (Property pkProp : pkProps) {
if (names.contains(pkProp.getName()))
continue;
if (count > 0)
sql.append(", ");
sql.append("t0.");
sql.append(((PlasmaProperty) pkProp).getPhysicalName());
count++;
}
for (String name : names) {
PlasmaProperty prop = (PlasmaProperty) type.getProperty(name);
if (prop.isMany() && !prop.getType().isDataType())
continue;
if (count > 0)
sql.append(", ");
sql.append("t0.");
sql.append(prop.getPhysicalName());
count++;
}
sql.append(" FROM ");
sql.append(getQualifiedPhysicalName(type));
sql.append(" t0 ");
sql.append(" WHERE ");
for (count = 0; count < keyValues.size(); count++) {
if (count > 0)
sql.append(" AND ");
PropertyPair propValue = keyValues.get(count);
sql.append("t0.");
sql.append(propValue.getProp().getPhysicalName());
sql.append(" = ");
appendValue(propValue, sql);
}
return sql;
}
protected StringBuilder createSelect(PlasmaType type, List names,
List keyValues, FilterAssembler filterAssembler, List