本文整理汇总了Java中wherehows.common.utils.PreparedStatementUtil.prepareInsertTemplateWithColumn方法的典型用法代码示例。如果您正苦于以下问题:Java PreparedStatementUtil.prepareInsertTemplateWithColumn方法的具体用法?Java PreparedStatementUtil.prepareInsertTemplateWithColumn怎么用?Java PreparedStatementUtil.prepareInsertTemplateWithColumn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wherehows.common.utils.PreparedStatementUtil
的用法示例。
在下文中一共展示了PreparedStatementUtil.prepareInsertTemplateWithColumn方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: insert
import wherehows.common.utils.PreparedStatementUtil; //导入方法依赖的package包/类
/**
* use JDBC template PreparedStatement to insert records
* require record to have getAllValues() and optional getDbColumnNames() method
* @return boolean if the insert is successful
* @throws SQLException
*/
public boolean insert() throws SQLException, IllegalAccessException {
if (records.size() == 0 || !(records.get(0) instanceof AbstractRecord)) {
logger.debug("DatabaseWriter no record to insert or unknown record Class.");
System.out.println("DatabaseWriter no record or unknown record Class: " + records.size() + " | " + records.get(0) + " | " + (records.get(0) instanceof AbstractRecord));
return false;
}
final AbstractRecord record0 = (AbstractRecord) records.get(0);
final String[] columnNames = record0.getDbColumnNames();
final String sql =
(columnNames != null) ? PreparedStatementUtil.prepareInsertTemplateWithColumn(tableName, columnNames)
: PreparedStatementUtil.prepareInsertTemplateWithoutColumn(tableName, record0.getAllFields().length);
logger.info("sql string: " + sql);
logger.error("columnNames: " + columnNames);
System.out.println("sql: " + sql + " | " + columnNames);
//logger.debug("DatabaseWriter template for " + record0.getClass() + " : " + sql);
for (final Record record : records) {
jdbcTemplate.update(sql, ((AbstractRecord) record).getAllValuesToString());
}
records.clear();
return true;
}
示例2: insert
import wherehows.common.utils.PreparedStatementUtil; //导入方法依赖的package包/类
/**
* use JDBC template PreparedStatement to insert records
* require record to have getAllValues() and optional getDbColumnNames() method
* @return boolean if the insert is successful
* @throws SQLException
*/
public boolean insert()
throws SQLException {
if (records.size() == 0 || !(records.get(0) instanceof AbstractRecord)) {
logger.debug("DatabaseWriter no record to insert or unknown record Class.");
return false;
}
final AbstractRecord record0 = (AbstractRecord) records.get(0);
final String[] columnNames = record0.getDbColumnNames();
final String sql =
(columnNames != null) ? PreparedStatementUtil.prepareInsertTemplateWithColumn(tableName, columnNames)
: PreparedStatementUtil.prepareInsertTemplateWithoutColumn(tableName, record0.getAllFields().length);
//logger.debug("DatabaseWriter template for " + record0.getClass() + " : " + sql);
for (final Record record : records) {
try {
jdbcTemplate.update(sql, ((AbstractRecord) record).getAllValuesToString());
/* jdbcTemplate.update(sql, new PreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps)
throws SQLException {
record.setPreparedStatementValues(ps);
}
}); */
} catch (IllegalAccessException | DataAccessException ae) {
logger.error("DatabaseWriter insert error: " + ae);
}
}
records.clear();
return true;
}
示例3: insert
import wherehows.common.utils.PreparedStatementUtil; //导入方法依赖的package包/类
/**
* use JDBC template PreparedStatement to insert records
* require record to have getAllValues() and optional getDbColumnNames() method
* @return boolean if the insert is successful
* @throws SQLException
*/
public boolean insert()
throws SQLException {
if (records.size() == 0 || !(records.get(0) instanceof AbstractRecord)) {
log.debug("DatabaseWriter no record to insert or unknown record Class.");
return false;
}
final AbstractRecord record0 = (AbstractRecord) records.get(0);
final String[] columnNames = record0.getDbColumnNames();
final String sql =
(columnNames != null) ? PreparedStatementUtil.prepareInsertTemplateWithColumn(tableName, columnNames)
: PreparedStatementUtil.prepareInsertTemplateWithoutColumn(tableName, record0.getAllFields().length);
//logger.debug("DatabaseWriter template for " + record0.getClass() + " : " + sql);
for (final Record record : records) {
try {
jdbcTemplate.update(sql, ((AbstractRecord) record).getAllValuesToString());
/* jdbcTemplate.update(sql, new PreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps)
throws SQLException {
record.setPreparedStatementValues(ps);
}
}); */
} catch (IllegalAccessException | DataAccessException ae) {
log.error("DatabaseWriter insert error: " + ae);
}
}
records.clear();
return true;
}
示例4: updateDatasetOwner
import wherehows.common.utils.PreparedStatementUtil; //导入方法依赖的package包/类
public static void updateDatasetOwner(JsonNode root)
throws Exception {
final JsonNode owners = root.path("owners");
if (owners.isMissingNode() || !owners.isArray()) {
throw new IllegalArgumentException(
"Dataset owner info update fail, missing necessary fields: " + root.toString());
}
final JsonNode ownerSourceNode = root.path("source");
String ownerSource = null;
if (!ownerSourceNode.isNull() && !ownerSourceNode.isMissingNode()) {
ownerSource = ownerSourceNode.asText();
}
final Integer datasetId;
final String urn;
final Object[] idUrn = findDataset(root);
if (idUrn[0] == null || idUrn[1] == null) {
datasetId = 0;
urn = root.path("datasetProperties").path("uri").asText();
} else {
datasetId = (Integer) idUrn[0];
urn = (String) idUrn[1];
}
final JsonNode auditHeader = root.path("auditHeader");
final Long eventTime = auditHeader != null ? auditHeader.path("time").asLong() / 1000 : null;
ObjectMapper om = new ObjectMapper();
List<DatasetOwnerRecord> ownerList = new ArrayList<>();
for (final JsonNode owner : owners) {
DatasetOwnerRecord record = om.convertValue(owner, DatasetOwnerRecord.class);
record.setDatasetId(datasetId);
record.setDatasetUrn(urn);
record.setSourceTime(eventTime);
record.setCreatedTime(eventTime);
record.setModifiedTime(System.currentTimeMillis() / 1000);
final String ownerString = record.getOwner();
int lastIndex = ownerString.lastIndexOf(':');
if (lastIndex >= 0) {
record.setOwner(ownerString.substring(lastIndex + 1));
record.setNamespace(ownerString.substring(0, lastIndex));
} else {
record.setNamespace("");
}
Map<String, Object> ownerInfo = getOwnerByOwnerId(record.getOwner());
Integer appId = 0;
String isActive = "N";
if (ownerInfo.containsKey("app_id")) {
appId = StringUtil.toInt(ownerInfo.get("app_id"));
isActive = appId == 301 ? "Y" : appId == 300 ? (String) ownerInfo.get("is_active") : "N";
}
record.setAppId(appId);
record.setIsActive(isActive);
String ownerTypeString = record.getOwnerType();
record.setIsGroup(ownerTypeString != null && ownerTypeString.equalsIgnoreCase("group") ? "Y" : "N");
if (datasetId == 0 || appId == 0) {
String sql = PreparedStatementUtil.prepareInsertTemplateWithColumn(DATASET_OWNER_UNMATCHED_TABLE,
record.getDbColumnForUnmatchedOwner());
OWNER_UNMATCHED_WRITER.execute(sql, record.getValuesForUnmatchedOwner());
} else {
ownerList.add(record);
}
}
mergeDatasetOwners(ownerList, datasetId, urn, ownerSource);
}
示例5: updateDatasetOwner
import wherehows.common.utils.PreparedStatementUtil; //导入方法依赖的package包/类
public static void updateDatasetOwner(JsonNode root)
throws Exception {
final JsonNode owners = root.path("owners");
if (owners.isMissingNode() || !owners.isArray()) {
throw new IllegalArgumentException(
"Dataset owner info update fail, missing necessary fields: " + root.toString());
}
final JsonNode ownerSourceNode = root.path("source");
String ownerSource = null;
if (!ownerSourceNode.isNull() && !ownerSourceNode.isMissingNode()) {
ownerSource = ownerSourceNode.asText();
}
final Integer datasetId;
final String urn;
final Object[] idUrn = findDataset(root);
if (idUrn[0] == null || idUrn[1] == null) {
datasetId = 0;
urn = root.path("datasetProperties").path("uri").asText();
} else {
datasetId = (Integer) idUrn[0];
urn = (String) idUrn[1];
}
final JsonNode auditHeader = root.path("auditHeader");
final Long eventTime = auditHeader != null ? auditHeader.path("time").asLong() / 1000 : null;
ObjectMapper om = new ObjectMapper();
List<DatasetOwnerRecord> ownerList = new ArrayList<>();
for (final JsonNode owner : owners) {
DatasetOwnerRecord record = om.convertValue(owner, DatasetOwnerRecord.class);
record.setDatasetId(datasetId);
record.setDatasetUrn(urn);
record.setSourceTime(eventTime);
record.setCreatedTime(eventTime);
record.setModifiedTime(System.currentTimeMillis() / 1000);
final String ownerString = record.getOwner();
int lastIndex = ownerString.lastIndexOf(':');
if (lastIndex >= 0) {
record.setOwner(ownerString.substring(lastIndex + 1));
record.setNamespace(ownerString.substring(0, lastIndex));
} else {
record.setNamespace("");
}
Map<String, Object> ownerInfo = getOwnerByOwnerId(record.getOwner());
Integer appId = 0;
String isActive = "N";
if (ownerInfo.containsKey("app_id")) {
appId = StringUtil.toInt(ownerInfo.get("app_id"));
isActive = appId == 301 ? "Y" : appId == 300 ? (String) ownerInfo.get("is_active") : "N";
}
record.setAppId(appId);
record.setIsActive(isActive);
String ownerTypeString = record.getOwnerType();
record.setIsGroup(ownerTypeString != null && ownerTypeString.equalsIgnoreCase("group") ? "Y" : "N");
if (datasetId == 0 || appId == 0) {
String sql = PreparedStatementUtil.prepareInsertTemplateWithColumn("REPLACE", DATASET_OWNER_UNMATCHED_TABLE,
record.getDbColumnForUnmatchedOwner());
OWNER_UNMATCHED_WRITER.execute(sql, record.getValuesForUnmatchedOwner());
} else {
ownerList.add(record);
}
}
mergeDatasetOwners(ownerList, datasetId, urn, ownerSource);
}