List of usage examples for org.apache.commons.logging Log error
void error(Object message);
From source file:de.ingrid.iplug.csw.dsc.cache.impl.AbstractUpdateStrategy.java
/** * Fetch all records that satisfy the given filter using the GetRecords and * return the ids and put them into the cache * @note This method guarantees to query the server without a constraint, if the * provided filter set is empty /*from www . j a va2 s.c o m*/ * * @param client The CSWClient to use * @param elementSetName The ElementSetName of the records to fetch * @param filterSet The filter set used to select the records * @param doCache Determines wether to cache the record or not * @return A list of ids of the fetched records * @throws Exception */ protected List<String> fetchRecords(CSWClient client, ElementSetName elementSetName, Set<Document> filterSet, boolean doCache) throws Exception { CSWFactory factory = client.getFactory(); Log log = this.getLog(); // if the filter set is empty, we add a null a least // this causes execution of the iteration below, but // but will not add a constraint definition to the request if (filterSet == null) filterSet = new HashSet<Document>(); if (filterSet.size() == 0) filterSet.add(null); // variables for complete fetch process // int numTotal = 0; List<String> fetchedRecordIds = new CopyOnWriteArrayList<String>(); // iterate over all filters int filterIndex = 1; for (Document filter : filterSet) { if (log.isDebugEnabled()) log.debug("Processing filter " + filterIndex + ": " + StringUtils.nodeToString(filter).replace("\n", "") + "."); // variables for current fetch process (current filter) int numRecordsTotal = 0; int numRecordsFetched = 0; List<String> currentFetchedRecordIds = new ArrayList<String>(); // create the query CSWQuery query = factory.createQuery(); query.setConstraint(filter); query.setResultType(ResultType.RESULTS); query.setElementSetName(elementSetName); query.setMaxRecords(this.recordsPerCall); query.setStartPosition(1); // do requests // do first request CSWSearchResult result = client.getRecords(query); numRecordsFetched += result.getNumberOfRecords(); numRecordsTotal = result.getNumberOfRecordsTotal(); if (log.isInfoEnabled()) log.info(numRecordsTotal + " record(s) from filter " + filterIndex + ":"); if (numRecordsTotal > 0) { if (log.isInfoEnabled()) { log.info("\nPARAMETERS OF FETCHING PROCESS:" + "\nrecords per chunk (request): " + recordsPerCall + "\ngeneral pause between requesting next chunk (msec): " + requestPause + "\nnum retries per chunk: " + cswConfig.numRetriesPerRequest + "\npause between retries (msec): " + cswConfig.timeBetweenRetries + "\nmax number of lost chunks: " + cswConfig.maxNumSkippedRequests); } // process currentFetchedRecordIds.addAll(processResult(result, doCache)); int numSkippedRequests = 0; String logLostRecordChunks = ""; int numLostRecords = 0; while (numRecordsFetched < numRecordsTotal) { if (cswConfig.maxNumSkippedRequests > -1) { // fetching should end when a maximum number of failures (in a row) is reached. if (numSkippedRequests > cswConfig.maxNumSkippedRequests) { log.error("Problems fetching records. Total number of skipped requests reached (" + cswConfig.maxNumSkippedRequests + " requests without results). We end fetching process for this filter."); statusProvider.addState( "ERROR_FETCH", "Error during fetch, since more than " + cswConfig.maxNumSkippedRequests + " records have been skipped.", Classification.ERROR); break; } } // generic pause between requests, set via spring Thread.sleep(this.requestPause); String logCurrRecordChunk = ""; try { // prepare next request // Just for safety: get number of last fetched records from last result, if we have a result and records. int numLastFetch = query.getMaxRecords(); if (result != null && (result.getNumberOfRecords() > 0)) { numLastFetch = result.getNumberOfRecords(); } numRecordsFetched += numLastFetch; statusProvider.addState("FETCH", "Fetching record " + (numRecordsFetched - numLastFetch + 1) + "-" + numRecordsFetched + " / " + numRecordsTotal + " from " + client.getFactory().getServiceUrl()); query.setStartPosition(query.getStartPosition() + numLastFetch); // for logging below logCurrRecordChunk = "" + query.getStartPosition() + " - " + (query.getStartPosition() + query.getMaxRecords()); // do next request, if problems retry with increasing pause in between int numRetries = 0; while (true) { try { result = null; result = client.getRecords(query); break; } catch (Exception e) { if (numRetries == cswConfig.numRetriesPerRequest) { log.error("Retried " + numRetries + " times ! We skip records " + logCurrRecordChunk, e); break; } numRetries++; int timeBetweenRetry = numRetries * cswConfig.timeBetweenRetries; log.error("Error fetching records " + logCurrRecordChunk + ". We retry " + numRetries + ". time after " + timeBetweenRetry + " msec !", e); Thread.sleep(timeBetweenRetry); } } // process if (result == null || result.getNumberOfRecords() == 0) { // no result from this query, we count the failures to check whether fetching process should be ended ! numSkippedRequests++; numLostRecords += query.getMaxRecords(); logLostRecordChunks += logCurrRecordChunk + "\n"; } else { currentFetchedRecordIds.addAll(processResult(result, doCache)); } } catch (Exception e) { statusProvider.addState("ERROR_FETCH_PROCESS", "Error during processing record: " + logCurrRecordChunk, Classification.ERROR); log.error("Error processing records " + logCurrRecordChunk); log.error(ExceptionUtils.getStackTrace(e)); } } if (numLostRecords > 0) { statusProvider.addState("ERROR_FETCH_PROCESS", "Error during fetching of record: " + logLostRecordChunks, Classification.ERROR); log.error("\nWe had failed GetRecords requests !!!" + "\nThe following " + numLostRecords + " records were NOT fetched and are \"lost\":" + "\n" + logLostRecordChunks); } } // collect record ids fetchedRecordIds.addAll(currentFetchedRecordIds); // numTotal += currentFetchedRecordIds.size(); filterIndex++; } return fetchedRecordIds; }
From source file:com.swordlord.gozer.datatypeformat.DataTypeHelper.java
/** * Return compatible class for typedValue based on untypedValueClass * /*ww w. j a va2s . c o m*/ * @param untypedValueClass * @param typedValue * @return */ public static Object fromDataType(Class<?> untypedValueClass, Object typedValue) { Log LOG = LogFactory.getLog(DataTypeHelper.class); if (typedValue == null) { return null; } if (untypedValueClass == null) { return typedValue; } if (ClassUtils.isAssignable(typedValue.getClass(), untypedValueClass)) { return typedValue; } String strTypedValue = null; boolean isStringTypedValue = typedValue instanceof String; Number numTypedValue = null; boolean isNumberTypedValue = typedValue instanceof Number; Boolean boolTypedValue = null; boolean isBooleanTypedValue = typedValue instanceof Boolean; Date dateTypedValue = null; boolean isDateTypedValue = typedValue instanceof Date; if (isStringTypedValue) { strTypedValue = (String) typedValue; } if (isNumberTypedValue) { numTypedValue = (Number) typedValue; } if (isBooleanTypedValue) { boolTypedValue = (Boolean) typedValue; } if (isDateTypedValue) { dateTypedValue = (Date) typedValue; } Object v = null; if (String.class.equals(untypedValueClass)) { v = ObjectUtils.toString(typedValue); } else if (BigDecimal.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = NumberUtils.createBigDecimal(strTypedValue); } else if (isNumberTypedValue) { v = new BigDecimal(numTypedValue.doubleValue()); } else if (isBooleanTypedValue) { v = new BigDecimal(BooleanUtils.toInteger(boolTypedValue.booleanValue())); } else if (isDateTypedValue) { v = new BigDecimal(dateTypedValue.getTime()); } } else if (Boolean.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = BooleanUtils.toBooleanObject(strTypedValue); } else if (isNumberTypedValue) { v = BooleanUtils.toBooleanObject(numTypedValue.intValue()); } else if (isDateTypedValue) { v = BooleanUtils.toBooleanObject((int) dateTypedValue.getTime()); } } else if (Byte.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = Byte.valueOf(strTypedValue); } else if (isNumberTypedValue) { v = new Byte(numTypedValue.byteValue()); } else if (isBooleanTypedValue) { v = new Byte((byte) BooleanUtils.toInteger(boolTypedValue.booleanValue())); } else if (isDateTypedValue) { v = new Byte((byte) dateTypedValue.getTime()); } } else if (byte[].class.equals(untypedValueClass)) { if (isStringTypedValue) { v = strTypedValue.getBytes(); } } else if (Double.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = NumberUtils.createDouble(strTypedValue); } else if (isNumberTypedValue) { v = new Double(numTypedValue.doubleValue()); } else if (isBooleanTypedValue) { v = new Double(BooleanUtils.toInteger(boolTypedValue.booleanValue())); } else if (isDateTypedValue) { v = new Double(dateTypedValue.getTime()); } } else if (Float.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = NumberUtils.createFloat(strTypedValue); } else if (isNumberTypedValue) { v = new Float(numTypedValue.floatValue()); } else if (isBooleanTypedValue) { v = new Float(BooleanUtils.toInteger(boolTypedValue.booleanValue())); } else if (isDateTypedValue) { v = new Float(dateTypedValue.getTime()); } } else if (Short.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = NumberUtils.createInteger(strTypedValue); } else if (isNumberTypedValue) { v = new Integer(numTypedValue.intValue()); } else if (isBooleanTypedValue) { v = BooleanUtils.toIntegerObject(boolTypedValue.booleanValue()); } else if (isDateTypedValue) { v = new Integer((int) dateTypedValue.getTime()); } } else if (Integer.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = NumberUtils.createInteger(strTypedValue); } else if (isNumberTypedValue) { v = new Integer(numTypedValue.intValue()); } else if (isBooleanTypedValue) { v = BooleanUtils.toIntegerObject(boolTypedValue.booleanValue()); } else if (isDateTypedValue) { v = new Integer((int) dateTypedValue.getTime()); } } else if (Long.class.equals(untypedValueClass)) { if (isStringTypedValue) { v = NumberUtils.createLong(strTypedValue); } else if (isNumberTypedValue) { v = new Long(numTypedValue.longValue()); } else if (isBooleanTypedValue) { v = new Long(BooleanUtils.toInteger(boolTypedValue.booleanValue())); } else if (isDateTypedValue) { v = new Long(dateTypedValue.getTime()); } } else if (java.sql.Date.class.equals(untypedValueClass)) { if (isNumberTypedValue) { v = new java.sql.Date(numTypedValue.longValue()); } else if (isDateTypedValue) { v = new java.sql.Date(dateTypedValue.getTime()); } } else if (java.sql.Time.class.equals(untypedValueClass)) { if (isNumberTypedValue) { v = new java.sql.Time(numTypedValue.longValue()); } else if (isDateTypedValue) { v = new java.sql.Time(dateTypedValue.getTime()); } } else if (java.sql.Timestamp.class.equals(untypedValueClass)) { if (isNumberTypedValue) { v = new java.sql.Timestamp(numTypedValue.longValue()); } else if (isDateTypedValue) { v = new java.sql.Timestamp(dateTypedValue.getTime()); } } else if (Date.class.equals(untypedValueClass)) { if (isNumberTypedValue) { v = new Date(numTypedValue.longValue()); } else if (isStringTypedValue) { try { v = DateFormat.getDateInstance().parse(strTypedValue); } catch (ParseException e) { LOG.error("Unable to parse the date : " + strTypedValue); LOG.debug(e.getMessage()); } } } return v; }
From source file:edu.cornell.mannlib.vitro.webapp.visualization.utilities.UtilitiesRequestHandler.java
public Object generateAjaxVisualization(VitroRequest vitroRequest, Log log, Dataset dataset) throws MalformedQueryParametersException { String individualURI = vitroRequest.getParameter(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY); String visMode = vitroRequest.getParameter(VisualizationFrameworkConstants.VIS_MODE_KEY); /*//from w ww. j a v a 2s .c om * If the info being requested is about a profile which includes the name, moniker * & image url. * */ if (VisualizationFrameworkConstants.PROFILE_INFO_UTILS_VIS_MODE.equalsIgnoreCase(visMode)) { String filterRule = "?predicate = j.2:mainImage " + " || ?predicate = rdfs:label " + " || ?predicate = <http://www.w3.org/2006/vcard/ns#title>"; QueryRunner<GenericQueryMap> profileQueryHandler = new AllPropertiesQueryRunner(individualURI, filterRule, dataset, log); GenericQueryMap profilePropertiesToValues = profileQueryHandler.getQueryResult(); Gson profileInformation = new Gson(); return profileInformation.toJson(profilePropertiesToValues); } else if (VisualizationFrameworkConstants.IMAGE_UTILS_VIS_MODE.equalsIgnoreCase(visMode)) { /* * If the url being requested is about a standalone image, which is used when we * want to render an image & other info for a co-author OR ego for that matter. * */ Map<String, String> fieldLabelToOutputFieldLabel = new HashMap<String, String>(); fieldLabelToOutputFieldLabel.put("downloadLocation", QueryFieldLabels.THUMBNAIL_LOCATION_URL); fieldLabelToOutputFieldLabel.put("fileName", QueryFieldLabels.THUMBNAIL_FILENAME); String whereClause = "<" + individualURI + "> j.2:thumbnailImage ?thumbnailImage . " + "?thumbnailImage j.2:downloadLocation " + "?downloadLocation ; j.2:filename ?fileName ."; QueryRunner<ResultSet> imageQueryHandler = new GenericQueryRunner(fieldLabelToOutputFieldLabel, "", whereClause, "", dataset); return getThumbnailInformation(imageQueryHandler.getQueryResult(), fieldLabelToOutputFieldLabel, vitroRequest); } else if (VisualizationFrameworkConstants.ARE_PUBLICATIONS_AVAILABLE_UTILS_VIS_MODE .equalsIgnoreCase(visMode)) { Map<String, String> fieldLabelToOutputFieldLabel = new HashMap<String, String>(); String aggregationRules = "(count(DISTINCT ?document) AS ?numOfPublications)"; String whereClause = "<" + individualURI + "> rdf:type foaf:Person ;" + " core:relatedBy ?authorshipNode . \n" + "?authorshipNode rdf:type core:Authorship ;" + " core:relates ?document . \n" + "?document rdf:type bibo:Document ."; String groupOrderClause = "GROUP BY ?" + QueryFieldLabels.AUTHOR_URL + " \n"; QueryRunner<ResultSet> numberOfPublicationsQueryHandler = new GenericQueryRunner( fieldLabelToOutputFieldLabel, aggregationRules, whereClause, groupOrderClause, dataset); Gson publicationsInformation = new Gson(); return publicationsInformation.toJson( getNumberOfPublicationsForIndividual(numberOfPublicationsQueryHandler.getQueryResult())); } else if (VisualizationFrameworkConstants.ARE_GRANTS_AVAILABLE_UTILS_VIS_MODE.equalsIgnoreCase(visMode)) { Map<String, String> fieldLabelToOutputFieldLabel = new HashMap<String, String>(); String aggregationRules = "(count(DISTINCT ?Grant) AS ?numOfGrants)"; String grantType = "http://vivoweb.org/ontology/core#Grant"; ObjectProperty predicate = ModelUtils.getPropertyForRoleInClass(grantType, vitroRequest.getWebappDaoFactory()); String roleToGrantPredicate = "<" + predicate.getURI() + ">"; String whereClause = "{ <" + individualURI + "> rdf:type foaf:Person ;" + " <http://purl.obolibrary.org/obo/RO_0000053> ?Role . \n" + "?Role rdf:type core:PrincipalInvestigatorRole . \n" + "?Role " + roleToGrantPredicate + " ?Grant . }" + "UNION \n" + "{ <" + individualURI + "> rdf:type foaf:Person ;" + " <http://purl.obolibrary.org/obo/RO_0000053> ?Role . \n" + "?Role rdf:type core:CoPrincipalInvestigatorRole . \n" + "?Role " + roleToGrantPredicate + " ?Grant . }" + "UNION \n" + "{ <" + individualURI + "> rdf:type foaf:Person ;" + " <http://purl.obolibrary.org/obo/RO_0000053> ?Role . \n" + "?Role rdf:type core:InvestigatorRole. \n" + "?Role vitro:mostSpecificType ?subclass . \n" + "?Role " + roleToGrantPredicate + " ?Grant . \n" + "FILTER (?subclass != core:PrincipalInvestigatorRole && " + "?subclass != core:CoPrincipalInvestigatorRole)}"; QueryRunner<ResultSet> numberOfGrantsQueryHandler = new GenericQueryRunner(fieldLabelToOutputFieldLabel, aggregationRules, whereClause, "", dataset); Gson grantsInformation = new Gson(); return grantsInformation .toJson(getNumberOfGrantsForIndividual(numberOfGrantsQueryHandler.getQueryResult())); } else if (VisualizationFrameworkConstants.COAUTHOR_UTILS_VIS_MODE.equalsIgnoreCase(visMode)) { String individualLocalName = UtilityFunctions.getIndividualLocalName(individualURI, vitroRequest); if (StringUtils.isNotBlank(individualLocalName)) { return UrlBuilder.getUrl(VisualizationFrameworkConstants.SHORT_URL_VISUALIZATION_REQUEST_PREFIX) + "/" + VisualizationFrameworkConstants.COAUTHORSHIP_VIS_SHORT_URL + "/" + individualLocalName; } ParamMap coAuthorProfileURLParams = new ParamMap(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY, individualURI, VisualizationFrameworkConstants.VIS_TYPE_KEY, VisualizationFrameworkConstants.PERSON_LEVEL_VIS, VisualizationFrameworkConstants.VIS_MODE_KEY, VisualizationFrameworkConstants.COAUTHOR_VIS_MODE); return UrlBuilder.getUrl(VisualizationFrameworkConstants.FREEMARKERIZED_VISUALIZATION_URL_PREFIX, coAuthorProfileURLParams); } else if (VisualizationFrameworkConstants.COPI_UTILS_VIS_MODE.equalsIgnoreCase(visMode)) { String individualLocalName = UtilityFunctions.getIndividualLocalName(individualURI, vitroRequest); if (StringUtils.isNotBlank(individualLocalName)) { return UrlBuilder.getUrl(VisualizationFrameworkConstants.SHORT_URL_VISUALIZATION_REQUEST_PREFIX) + "/" + VisualizationFrameworkConstants.COINVESTIGATOR_VIS_SHORT_URL + "/" + individualLocalName; } /* * By default we will be generating profile url else some specific url like * coPI vis url for that individual. * */ ParamMap coInvestigatorProfileURLParams = new ParamMap( VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY, individualURI, VisualizationFrameworkConstants.VIS_TYPE_KEY, VisualizationFrameworkConstants.PERSON_LEVEL_VIS, VisualizationFrameworkConstants.VIS_MODE_KEY, VisualizationFrameworkConstants.COPI_VIS_MODE); return UrlBuilder.getUrl(VisualizationFrameworkConstants.FREEMARKERIZED_VISUALIZATION_URL_PREFIX, coInvestigatorProfileURLParams); } else if (VisualizationFrameworkConstants.PERSON_LEVEL_UTILS_VIS_MODE.equalsIgnoreCase(visMode)) { /* * By default we will be generating profile url else some specific url like * coAuthorShip vis url for that individual. * */ ParamMap personLevelURLParams = new ParamMap(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY, individualURI, VisualizationFrameworkConstants.VIS_TYPE_KEY, VisualizationFrameworkConstants.PERSON_LEVEL_VIS, VisualizationFrameworkConstants.RENDER_MODE_KEY, VisualizationFrameworkConstants.STANDALONE_RENDER_MODE); return UrlBuilder.getUrl(VisualizationFrameworkConstants.FREEMARKERIZED_VISUALIZATION_URL_PREFIX, personLevelURLParams); } else if (VisualizationFrameworkConstants.HIGHEST_LEVEL_ORGANIZATION_VIS_MODE.equalsIgnoreCase(visMode)) { String staffProvidedHighestLevelOrganization = ConfigurationProperties.getBean(vitroRequest) .getProperty("visualization.topLevelOrg"); /* * First checking if the staff has provided highest level organization in * deploy.properties if so use to temporal graph vis. * */ if (StringUtils.isNotBlank(staffProvidedHighestLevelOrganization)) { /* * To test for the validity of the URI submitted. * */ IRIFactory iRIFactory = IRIFactory.jenaImplementation(); IRI iri = iRIFactory.create(staffProvidedHighestLevelOrganization); if (iri.hasViolation(false)) { String errorMsg = ((Violation) iri.violations(false).next()).getShortMessage(); log.error("Highest Level Organization URI provided is invalid " + errorMsg); } else { ParamMap highestLevelOrganizationTemporalGraphVisURLParams = new ParamMap( VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY, staffProvidedHighestLevelOrganization, VisualizationFrameworkConstants.VIS_TYPE_KEY, VisualizationFrameworkConstants.ENTITY_COMPARISON_VIS); return UrlBuilder.getUrl( VisualizationFrameworkConstants.FREEMARKERIZED_VISUALIZATION_URL_PREFIX, highestLevelOrganizationTemporalGraphVisURLParams); } } Map<String, String> fieldLabelToOutputFieldLabel = new HashMap<String, String>(); fieldLabelToOutputFieldLabel.put("organization", QueryFieldLabels.ORGANIZATION_URL); fieldLabelToOutputFieldLabel.put("organizationLabel", QueryFieldLabels.ORGANIZATION_LABEL); String aggregationRules = "(count(?organization) AS ?numOfChildren)"; String whereClause = "?organization rdf:type foaf:Organization ;" + " rdfs:label ?organizationLabel . \n" + "OPTIONAL { ?organization core:http://purl.obolibrary.org/obo/BFO_0000051 ?subOrg . \n" + " ?subOrg rdf:type foaf:Organization } . \n" + "OPTIONAL { ?organization core:http://purl.obolibrary.org/obo/BFO_0000050 ?parent } . \n" + " ?parent rdf:type foaf:Organization } . \n" + "FILTER ( !bound(?parent) ). \n"; String groupOrderClause = "GROUP BY ?organization ?organizationLabel \n" + "ORDER BY DESC(?numOfChildren)\n" + "LIMIT 1\n"; QueryRunner<ResultSet> highestLevelOrganizationQueryHandler = new GenericQueryRunner( fieldLabelToOutputFieldLabel, aggregationRules, whereClause, groupOrderClause, dataset); return getHighestLevelOrganizationTemporalGraphVisURL( highestLevelOrganizationQueryHandler.getQueryResult(), fieldLabelToOutputFieldLabel, vitroRequest); } else { ParamMap individualProfileURLParams = new ParamMap(VisualizationFrameworkConstants.INDIVIDUAL_URI_KEY, individualURI); return UrlBuilder.getUrl(VisualizationFrameworkConstants.INDIVIDUAL_URL_PREFIX, individualProfileURLParams); } }
From source file:net.timewalker.ffmq4.utils.ErrorTools.java
/** * Log a JMS exception with an error level * @param e/* w ww . j a v a2 s . co m*/ * @param log */ public static void log(String context, JMSException e, Log log) { StringBuilder message = new StringBuilder(); if (context != null) { message.append("["); message.append(context); message.append("] "); } if (e.getErrorCode() != null) { message.append("error={"); message.append(e.getErrorCode()); message.append("} "); } message.append(e.getMessage()); log.error(message.toString()); if (e.getLinkedException() != null) log.error("Linked exception was :", e.getLinkedException()); }
From source file:och.util.exception.BaseExpectedException.java
public static void logError(Log log, Throwable t, String msg) { NoLog noLog = t.getClass().getAnnotation(NoLog.class); if (noLog != null) { return;// w ww . j av a 2 s .com } if (t instanceof BaseExpectedException) { log.error(msg + ": " + t); return; } IOException socketEx = SocketUtil.findSocketException(t); if (socketEx != null) { log.error(msg + ": " + new ExpectedSocketException(socketEx, t)); return; } //not ExpectedException log.error(msg, t); }
From source file:oracle.kv.hadoop.hive.table.TableFieldTypeEnum.java
public static boolean kvHiveTypesMatch(FieldDef kvFieldDef, TypeInfo hiveColumnType) { final Log LOG = LogFactory.getLog(TableFieldTypeEnum.class.getName()); /* Compare top-level types. */ final FieldDef.Type kvFieldType = kvFieldDef.getType(); if (!fromKvType(kvFieldType).equals(fromHiveType(hiveColumnType, kvFieldType))) { /* Special case: KV type ENUM & Hive type STRING handled below. */ if (!(TABLE_FIELD_ENUM.equals(fromKvType(kvFieldType)) && TABLE_FIELD_STRING.equals(fromHiveType(hiveColumnType)))) { LOG.error("Field type MISMATCH: " + fromKvType(kvFieldType) + " != " + fromHiveType(hiveColumnType, kvFieldType)); return false; }//from w w w.j av a 2 s.c o m } /* If top-level types are primitive and match, then it's a match. */ if (isPrimitive(kvFieldType) && isPrimitive(hiveColumnType)) { return true; } /* Top-level types match, but neither are primitive; deep dive. */ switch (kvFieldType) { /* If kvType is ENUM, then Hive type must be STRING */ case ENUM: if (!TABLE_FIELD_STRING.equals(fromHiveType(hiveColumnType))) { LOG.error("Field type MISMATCH: for KV ENUM field type, " + "expected Hive STRING column type, but Hive " + "column type is " + hiveColumnType.getTypeName()); return false; } return true; /* * If kvType is ARRAY, then Hive type must be LIST, and must have * matching element type. */ case ARRAY: if (!Category.LIST.equals(hiveColumnType.getCategory())) { LOG.error("Field type MISMATCH: for KV ARRAY field " + "type, expected Hive LIST column type, but " + "Hive column type is " + hiveColumnType.getCategory()); return false; } final TypeInfo hiveElementType = ((ListTypeInfo) hiveColumnType).getListElementTypeInfo(); final ArrayValue kvArrayValue = kvFieldDef.createArray(); final ArrayDef kvArrayDef = kvArrayValue.getDefinition(); final FieldDef kvElementDef = kvArrayDef.getElement(); LOG.debug("KV ARRAY field type and Hive LIST column type: " + "comparing KV ARRAY element type [" + kvElementDef.getType() + "] with Hive LIST " + "element type [" + hiveElementType + "]"); return kvHiveTypesMatch(kvElementDef, hiveElementType); /* * If kvType is MAP, then Hive type must be MAP<STRING, type>, and * must have matching value types. */ case MAP: if (!Category.MAP.equals(hiveColumnType.getCategory())) { LOG.error( "Field type MISMATCH: for KV MAP field type, " + "expected Hive MAP column type, but Hive " + "column type is " + hiveColumnType.getCategory()); return false; } final TypeInfo hiveMapKeyType = ((MapTypeInfo) hiveColumnType).getMapKeyTypeInfo(); final TypeInfo hiveMapValType = ((MapTypeInfo) hiveColumnType).getMapValueTypeInfo(); /* Hive key type must be STRING. */ if (!TABLE_FIELD_STRING.equals(fromHiveType(hiveMapKeyType))) { LOG.error( "Field type MISMATCH: for KV MAP field type " + "and Hive MAP column type, expected STRING " + "key type, but Hive MAP column's key type is " + fromHiveType(hiveMapKeyType)); return false; } /* Hive value type must match kv value type. */ final MapValue kvMapValue = kvFieldDef.createMap(); final MapDef kvMapDef = kvMapValue.getDefinition(); final FieldDef kvMapValueDef = kvMapDef.getElement(); LOG.debug("KV MAP field type and Hive MAP column type: " + "comparing KV MAP value type [" + kvMapValueDef.getType() + "] with Hive MAP " + "value type [" + hiveMapValType + "]"); return kvHiveTypesMatch(kvMapValueDef, hiveMapValType); /* * If kvType is RECORD, then Hive type must be STRUCT, and must * have same element types. */ case RECORD: if (!Category.STRUCT.equals(hiveColumnType.getCategory())) { LOG.error( "Field type MISMATCH: for KV RECORD field " + "type, expected Hive STRUCT column type, but " + "Hive column type is " + hiveColumnType.getCategory()); return false; } /* * Hive STRUCT field names and corresponding field types must * match KV RECORD field names. * * -- NOTE -- * * KV field names (and table and index names), as well as * the names of the elements of a RECORD field, are case * INSENSITIVE, but case PRESERVING. For example, if a * KV table is created with a RECORD field having two elements * named "MY_ELEMENT_1" and "MY_ELEMENT_2", those elements * can be referenced using the Strings "my_element_1" and * "my_element_2" (or "mY_eLEment_1" and "MY_element_2", etc.). * But when the element names are retrieved (via * RecordDef.getFields() for example), the names returned * for the desired elements will always be in the case * used when the RECORD was originally created; that is, * "MY_ELEMENT_1" and "MY_ELEMENT_2". Compare this with how * Hive handles case in its STRUCT data type. * * Recall that the Hive SerDeParameters.getColumnNames() * method returns the names of a Hive table's columns (which * correspond to a KV table's top-level fields) all in * LOWER CASE. Unfortunately, Hive seems to handle case for the * names of the elements of a Hive STRUCT differently. When the * names of the elements of a Hive STRUCT are retrieved using * the Hive StructTypeInfo.getAllStructFieldNames() method, * the case of those names appears to be PRESERVED, rather * than changed to all lower case; as is done for the column * names. That is, if the element names of a Hive STRUCT * are, for example, "mY_eLEment_1" and "MY_element_2", then * StructTypeInfo.getAllStructFieldNames() will return * "mY_eLEment_1" and "MY_element_2"; rather than * "my_element_1" and "my_element_2" (or "MY_ELEMENT_1" and * "MY_ELEMENT_2"). As a result, when validating the element * names of the KV RECORD with the corresponding Hive STRUCT * element names below, the retrieved element names for both * the KV RECORD and the Hive STRUCT are all converted to * lower case before performing the comparison. */ final List<String> hiveRecFieldNames = ((StructTypeInfo) hiveColumnType).getAllStructFieldNames(); final RecordValue kvRecValue = kvFieldDef.createRecord(); final RecordDef kvRecDef = kvRecValue.getDefinition(); final List<String> kvRecFieldNames = kvRecDef.getFieldNames(); /* Validate number of RECORD elements & STRUCT elements. */ if (hiveRecFieldNames.size() != kvRecFieldNames.size()) { LOG.error("Field type MISMATCH: for KV RECORD field " + "type and Hive STRUCT column type, number of " + "KV RECORD elements [" + kvRecFieldNames.size() + "] != number of " + "Hive STRUCT elements [" + hiveRecFieldNames.size() + "]. " + "\nKV RECORD element names = " + kvRecFieldNames + "\nHive STRUCT element names = " + hiveRecFieldNames); return false; } /* Validate RECORD & STRUCT element NAMES (use lower case). */ final List<String> hiveNamesLower = new ArrayList<String>(); for (String name : hiveRecFieldNames) { hiveNamesLower.add(name.toLowerCase()); } for (String kvRecFieldName : kvRecFieldNames) { /* Validate the current KV and Hive Record field names. */ final String kvFieldLower = kvRecFieldName.toLowerCase(); if (!hiveNamesLower.contains(kvFieldLower)) { LOG.error("Field type MISMATCH: for KV RECORD field " + "type and Hive STRUCT column type, " + "KV RECORD element name [" + kvFieldLower + "] does NOT MATCH any Hive STRUCT element " + "names " + hiveNamesLower); return false; } /* * The current KV element name matches one of the element * names in the Hive STRUCT. Get the corresponding KV and * Hive data types and compare them. * * Note that the method * StructTypeInfo.getStructFieldTypeInfo(<fieldname>) * appears to have a bug (see below). Therefore, a local * version of that method is defined in this class and * used here. * * Note also that because FieldDef.getField(<fieldname>) * is NOT case sensitive, the corresponding values of * hiveRecFieldNames can be used when retrieving the * element types of the KV RECORD. */ final TypeInfo hiveRecFieldType = getStructFieldTypeInfo(kvRecFieldName, (StructTypeInfo) hiveColumnType); final FieldDef kvRecFieldDef = kvRecDef.getFieldDef(kvRecFieldName); if (!kvHiveTypesMatch(kvRecFieldDef, hiveRecFieldType)) { LOG.error("Field type MISMATCH: for KV RECORD field " + "type and Hive STRUCT column type, " + "KV RECORD element type [" + kvRecFieldDef.getType() + "] does " + "NOT MATCH the corresponding Hive STRUCT " + "element type [" + hiveRecFieldType + "]"); return false; } } return true; default: LOG.error("Field type MISMATCH: UNKNOWN KV field type " + "[" + kvFieldType + "]"); return false; } }
From source file:org.acmsl.queryj.api.TemplateUtils.java
/** * Retrieves the custom results.//from www .j a v a2 s .c om * @param tableName the table name, or <code>null</code> for * repository-wide results. * @param customSqlProvider the {@link CustomSqlProvider} instance. * @param sqlDAO the {@link SqlDAO} instance. * @param resultDAO the {@link SqlResultDAO} instance. * @param metadataManager the {@link MetadataManager} instance. * @param decoratorFactory the {@link DecoratorFactory} instance. * @param daoTemplateUtils the {@link DAOTemplateUtils} instance. * @return the custom results. * @throws QueryJBuildException if the custom results cannot be retrieved. */ @NotNull public List<Result<String>> retrieveCustomResults(@Nullable final String tableName, @NotNull final CustomSqlProvider customSqlProvider, @NotNull final SqlDAO sqlDAO, @NotNull final SqlResultDAO resultDAO, @NotNull final MetadataManager metadataManager, @NotNull final DecoratorFactory decoratorFactory, @NotNull final DAOTemplateUtils daoTemplateUtils) throws QueryJBuildException { @NotNull final List<Result<String>> result = new ArrayList<>(); @Nullable ResultRef t_ResultRef; @Nullable Result<String> t_ResultElement; @Nullable String t_strDao; boolean t_bMatches; if (tableName != null) { result.addAll(buildImplicitResults(tableName, metadataManager.getTableDAO(), customSqlProvider, metadataManager, decoratorFactory)); } for (@Nullable final Sql<String> t_Sql : sqlDAO.findAll()) { if (t_Sql != null) { t_strDao = t_Sql.getDao(); if ((t_strDao != null) && (tableName != null)) { t_bMatches = daoTemplateUtils.matches(tableName, t_strDao); } else { t_bMatches = (t_Sql.getRepositoryScope() != null); } if (t_bMatches) { t_bMatches = Sql.SELECT.equals(t_Sql.getType()) || Sql.SELECT_FOR_UPDATE.equals(t_Sql.getType()); } if (t_bMatches) { t_ResultRef = t_Sql.getResultRef(); if (t_ResultRef != null) { t_ResultElement = resultDAO.findByPrimaryKey(t_ResultRef.getId()); if (t_ResultElement != null) { if (!result.contains(t_ResultElement)) { result.add(t_ResultElement); } } else { try { @Nullable final Log t_Log = UniqueLogFactory.getLog(TemplateUtils.class); if (t_Log != null) { t_Log.error(Literals.REFERENCED_RESULT_NOT_FOUND + t_ResultRef.getId()); } } catch (@NotNull final Throwable throwable) { // class-loading problem. System.err.println(Literals.REFERENCED_RESULT_NOT_FOUND + t_ResultRef.getId()); } throw new ReferencedResultNotFoundException(t_ResultRef, t_Sql); } } } } } return result; }
From source file:org.acmsl.queryj.api.TemplateUtils.java
/** * Builds the implicit results for given table. * @param tableName the table name./*from w w w .j a v a 2 s.c o m*/ * @param tableDAO the {@link TableDAO} instance. * @param customSqlProvider the {@link CustomSqlProvider} instance. * @param metadataManager the {@link MetadataManager} instance. * @param decoratorFactory the {@link DecoratorFactory} instance. * @return the implicit results. */ @NotNull protected List<Result<String>> buildImplicitResults(@NotNull final String tableName, @NotNull final TableDAO tableDAO, @NotNull final CustomSqlProvider customSqlProvider, @NotNull final MetadataManager metadataManager, @NotNull final DecoratorFactory decoratorFactory) { @NotNull final List<Result<String>> result = new ArrayList<>(2); @Nullable final Table<String, Attribute<String>, List<Attribute<String>>> table = tableDAO.findByName(tableName); if (table != null) { @Nullable final TableDecorator tableDecorator = decoratorFactory.createTableDecorator(table.getName(), metadataManager, customSqlProvider); @Nullable final String classValue = (tableDecorator != null) ? tableDecorator.getName().getVoName().getValue() : null; @NotNull final Result<String> singleResult = new ResultElement<>( "_" + tableName.toLowerCase(Locale.getDefault()) + Literals.RESULT_SUFFIX, classValue); result.add(singleResult); } else { try { @Nullable final Log t_Log = UniqueLogFactory.getLog(TemplateUtils.class); if (t_Log != null) { t_Log.error(Literals.TABLE_NOT_FOUND + tableName); } } catch (@NotNull final Throwable throwable) { // class-loading problem. System.err.println(Literals.TABLE_NOT_FOUND + tableName); } } return result; }
From source file:org.acmsl.queryj.metadata.AbstractTableDecorator.java
/** * Retrieves the foreign keys.//from ww w. j a v a 2 s. co m * @param name the table name. * @param metadataManager the {@link MetadataManager} instance. * @param decoratorFactory the {@link DecoratorFactory} instance. * @param customSqlProvider the {@link CustomSqlProvider} instnace. * @return such list. */ @NotNull protected List<ForeignKey<DecoratedString>> getForeignKeys(@NotNull final DecoratedString name, @NotNull final MetadataManager metadataManager, @NotNull final DecoratorFactory decoratorFactory, @NotNull final CustomSqlProvider customSqlProvider) { @Nullable List<ForeignKey<DecoratedString>> result = immutableGetForeignKeys(); if ((result == null) || (!areDecorated(result))) { result = decorate(retrieveForeignKeys(name, metadataManager), metadataManager, decoratorFactory, customSqlProvider); setForeignKeys(result); } try { Collections.sort(result); } catch (@NotNull final Throwable error) { @Nullable final Log t_Log = UniqueLogFactory.getLog(AbstractTableDecorator.class); if (t_Log != null) { t_Log.error(error); } } return result; }
From source file:org.alfresco.extension.bulkimport.util.LogUtils.java
public final static void error(final Log log, final String message) { log.error(PREFIX + message); }