code
stringlengths
73
34.1k
label
stringclasses
1 value
public static void setSyncCache(String name, Cache cache) { if (null == name || "".equals(name.trim()) || null == cache) { return; } GlobalSyncRedis.caches.put(name, cache); }
java
public static void removeSyncCache(String name) { if (StrKit.isBlank(name)) { return; } if (GlobalSyncRedis.caches.containsKey(name)) { GlobalSyncRedis.caches.remove(name); } }
java
public static Cache getSyncCache(String name) { if (StrKit.isBlank(name) || !GlobalSyncRedis.caches.containsKey(name)) { return Redis.use(); } return GlobalSyncRedis.caches.get(name); }
java
private String redisColumnKey(SqlpKit.FLAG flag) { StringBuilder key = new StringBuilder(this._getUsefulClass().toGenericString()); String[] attrs = this._getAttrNames(); Object val; for (String attr : attrs) { val = this.get(attr); if (null == val) { continue; } key.append(val.toString()); } ...
java
private List<M> fetchDatasFromRedis(String... columns) { // redis key String key = this.redisColumnKey(SqlpKit.FLAG.ALL); // fetch from redis List<M> fetchDatas = this.redis().get(key); if (null == fetchDatas) { // fetch ids from db. fetchDatas = this.find(SqlpKit.select(this, this.primaryKeys())); } ...
java
public Class<?> attrType(String attr) { Table table = this.table(); if (null != table) { return table.getColumnType(attr); } Method[] methods = this._getUsefulClass().getMethods(); String methodName; for (Method method : methods) { methodName = method.getName(); if (methodName.startsWith("set") ...
java
public List<String> attrNames() { String[] names = this._getAttrNames(); if (null != names && names.length != 0) { return Arrays.asList(names); } Method[] methods = this._getUsefulClass().getMethods(); String methodName; List<String> attrs = new ArrayList<String>(); for (Method method : methods) { m...
java
public Map<Object, Object> attrsCp() { Map<Object, Object> attrs = new HashMap<Object, Object>(); String[] attrNames = this._getAttrNames(); for (String attr : attrNames) { attrs.put(attr, this.get(attr)); } return attrs; }
java
public void shotCacheName(String cacheName) { //reset cache if (StrKit.notBlank(cacheName) && !cacheName.equals(this.cacheName)) { GlobalSyncRedis.removeSyncCache(this.cacheName); } this.cacheName = cacheName; //auto open sync to redis this.syncToRedis = true; //update model redis mapping ModelRedisM...
java
@Override public boolean save() { for (CallbackListener callbackListener : this.callbackListeners) { callbackListener.beforeSave(this); } boolean ret = super.save(); if (this.syncToRedis && ret) { this.saveToRedis(); } for (CallbackListener callbackListener : this.callbackListeners) { callbackList...
java
@Override public boolean delete() { for (CallbackListener callbackListener : this.callbackListeners) { callbackListener.beforeDelete(this); } boolean ret = super.delete(); if (this.syncToRedis && ret) { //delete from Redis this.redis().del(this.redisKey(this)); } for (Ca...
java
@Override public boolean update() { for (CallbackListener callbackListener : this.callbackListeners) { callbackListener.beforeUpdate(this); } boolean ret = super.update(); if (this.syncToRedis && ret) { this.saveToRedis(); } for (CallbackListener callbackListener : this.cal...
java
public int hcode() { final int prime = 31; int result = 1; Table table = this.table(); Set<Entry<String, Object>> attrsEntrySet = this._getAttrsEntrySet(); for (Entry<String, Object> entry : attrsEntrySet) { String key = entry.getKey(); Object value = entry.getValue(); Class<?> clazz = table.getColum...
java
public static Class<?> define(ClassLoader loader) { try { SecurityManager sm = System.getSecurityManager(); if (sm != null) { String packageName = DriverManagerAccessor.class.getPackage().getName(); RuntimePermission permission = new RuntimePermission("de...
java
public synchronized ValidationMessage[] validate( int type, String prefix, String uri, PageData page) { try { this.tlvType = type; this.uri = uri; // initialize messageVector = new Vector(); // save the prefix this.prefix = pre...
java
protected boolean isTag(String tagUri, String tagLn, String matchUri, String matchLn) { if (tagUri == null || tagUri.length() == 0 || tagLn == null || matchUri == null ...
java
protected boolean condition() throws JspTagException { try { Object r = ExpressionEvaluatorManager.evaluate( "test", test, Boolean.class, this, pageContext); if (r == null) { throw new NullAttributeException("when", "test"); } else { ...
java
public String logicalColumnName(String columnName, String propertyName) { return ! isNullOrEmpty( columnName ) ? columnName : unqualify( propertyName ); }
java
static DataSource getDataSource(Object rawDataSource, PageContext pc) throws JspException { DataSource dataSource = null; if (rawDataSource == null) { rawDataSource = Config.find(pc, Config.SQL_DATA_SOURCE); } if (rawDataSource == null) { return null; } /* * ...
java
private static DataSource getDataSource(String params) throws JspException { DataSourceWrapper dataSource = new DataSourceWrapper(); String[] paramString = new String[4]; int escCount = 0; int aryCount = 0; int begin = 0; for (int index = 0; index < params.l...
java
public static void main(String args[]) throws ParseException { SPathParser parser = new SPathParser(System.in); Path p = parser.expression(); java.util.List l = p.getSteps(); // output for simple testing System.out.println(); if (p instanceof AbsolutePath) System.out.println("Root: /"...
java
final public Path expression() throws ParseException { Path expr; if (jj_2_1(2147483647)) { expr = absolutePath(); jj_consume_token(0); } else { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case QNAME: case NSWILDCARD: case SLASH: case STAR: expr = relativePath(); ...
java
final public RelativePath relativePath() throws ParseException { RelativePath relPath = null; Step step; step = step(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case SLASH: jj_consume_token(SLASH); relPath = relativePath(); break; default: jj_la1[1] = jj_gen; ; } ...
java
public static DocumentBuilder newDocumentBuilder() { try { return PARSER_FACTORY.newDocumentBuilder(); } catch (ParserConfigurationException e) { throw (Error) new AssertionError().initCause(e); } }
java
public static Transformer newTransformer(Source source, JstlUriResolver uriResolver) throws TransformerConfigurationException { TRANSFORMER_FACTORY.setURIResolver(uriResolver); Transformer transformer = TRANSFORMER_FACTORY.newTransformer(source); // Although newTansformer() is not allowed to ret...
java
public static InputSource newInputSource(Reader reader, String systemId) { InputSource source = new InputSource(reader); source.setSystemId(wrapSystemId(systemId)); return source; }
java
public static XMLReader newXMLReader(JstlEntityResolver entityResolver) throws ParserConfigurationException, SAXException { XMLReader xmlReader = SAXPARSER_FACTORY.newSAXParser().getXMLReader(); xmlReader.setEntityResolver(entityResolver); return xmlReader; }
java
public static SAXSource newSAXSource(Reader reader, String systemId, JstlEntityResolver entityResolver) throws ParserConfigurationException, SAXException { SAXSource source = new SAXSource(newXMLReader(entityResolver), new InputSource(reader)); source.setSystemId(wrapSystemId(systemId)); ...
java
private static <T, E extends Exception> T runWithOurClassLoader(final Callable<T> action, Class<E> allowed) throws E { PrivilegedExceptionAction<T> actionWithClassloader = new PrivilegedExceptionAction<T>() { public T run() throws Exception { ClassLoader original = Thread.currentThre...
java
public SelectRootClauseBuilder<? extends QueryForNumber> count() { //TODO its hard to know whether or not to innerjoin to get an accurate count here. StringBuilder sb = new StringBuilder(); sb.append("SELECT count(*)"); sb.append(" FROM ").append(definition.getSqlName()); //definition.innerJoin(sb); SelectR...
java
@Override protected void prepare() throws JspTagException { // produce the right sort of ForEachIterator if (rawItems == null) { // if no items were specified, iterate from begin to end items = new ToEndIterator(end); } else if (rawItems instanceof ValueExpression) { ...
java
void exportToVariable(Object result) throws JspTagException { /* * Store the result, letting an IllegalArgumentException * propagate back if the scope is invalid (e.g., if an attempt * is made to store something in the session without any * HttpSession existing). */ ...
java
void exportToMapProperty(Object target, String property, Object result) { @SuppressWarnings("unchecked") Map<Object, Object> map = (Map<Object, Object>) target; if (result == null) { map.remove(property); } else { map.put(property, result); } }
java
void exportToBeanProperty(Object target, String property, Object result) throws JspTagException { PropertyDescriptor[] descriptors; try { descriptors = Introspector.getBeanInfo(target.getClass()).getPropertyDescriptors(); } catch (IntrospectionException ex) { throw new Js...
java
private Object convertToExpectedType(final Object value, Method m) throws ELException { if (value == null) { return null; } Class<?> expectedType = m.getParameterTypes()[0]; return getExpressionFactory().coerceToType(value, expectedType); }
java
private static Class<?>[] types(Object... values) { if (values == null) { return new Class[0]; } Class<?>[] result = new Class[values.length]; for (int i = 0; i < values.length; i++) { Object value = values[i]; result[i] = value == null ? Object.clas...
java
@Override public ValidationMessage[] validate( String prefix, String uri, PageData page) { return super.validate(TYPE_CORE, prefix, uri, page); }
java
@SuppressWarnings("unchecked") public static <K,V> Map<K,V> jsonToMap(String json){ return FastJsonKit.parse(json, HashMap.class); }
java
public static Record jsonToRecord(String json){ Map<String,Object> map = jsonToMap(json); return new Record().setColumns(map); }
java
public static Object coerce(Object pValue, Class pClass, Logger pLogger) throws ELException { if (pClass == String.class) { return coerceToString(pValue, pLogger); } else if (isPrimitiveNumberClass(pClass)) { ...
java
static boolean isPrimitiveNumberClass(Class pClass) { return pClass == Byte.class || pClass == Byte.TYPE || pClass == Short.class || pClass == Short.TYPE || pClass == Integer.class || ...
java
public static String coerceToString(Object pValue, Logger pLogger) throws ELException { if (pValue == null) { return ""; } else if (pValue instanceof String) { return (String) pValue; } else { try { ...
java
public static Number coerceToPrimitiveNumber(Object pValue, Class pClass, Logger pLogger) throws ELException { if (pValue == null || "".equals(pValue)) { return coerceToPrimi...
java
public static Integer coerceToInteger(Object pValue, Logger pLogger) throws ELException { if (pValue == null) { return null; } else if (pValue instanceof Character) { return PrimitiveObjects.getInteger ((in...
java
static Number coerceToPrimitiveNumber(long pValue, Class pClass) throws ELException { if (pClass == Byte.class || pClass == Byte.TYPE) { return PrimitiveObjects.getByte((byte) pValue); } else if (pClass == Short.class || pClass == Short.T...
java
static Number coerceToPrimitiveNumber(Number pValue, Class pClass) throws ELException { if (pClass == Byte.class || pClass == Byte.TYPE) { return PrimitiveObjects.getByte(pValue.byteValue()); } else if (pClass == Short.class || pClass == ...
java
static Number coerceToPrimitiveNumber(String pValue, Class pClass) throws ELException { if (pClass == Byte.class || pClass == Byte.TYPE) { return Byte.valueOf(pValue); } else if (pClass == Short.class || pClass == Short.TYPE) { ...
java
public static Character coerceToCharacter(Object pValue, Logger pLogger) throws ELException { if (pValue == null || "".equals(pValue)) { return PrimitiveObjects.getCharacter((char) 0); } else if (pValue instanceof Char...
java
public static Boolean coerceToBoolean(Object pValue, Logger pLogger) throws ELException { if (pValue == null || "".equals(pValue)) { return Boolean.FALSE; } else if (pValue instanceof Boolean) { return (Boolean...
java
public static Object coerceToObject(Object pValue, Class pClass, Logger pLogger) throws ELException { if (pValue == null) { return null; } else if (pClass.isAssignableFrom(pValue.getClass())) { ...
java
public static boolean isFloatingPointType(Class pClass) { return pClass == Float.class || pClass == Float.TYPE || pClass == Double.class || pClass == Double.TYPE; }
java
public static boolean isFloatingPointString(Object pObject) { if (pObject instanceof String) { String str = (String) pObject; int len = str.length(); for (int i = 0; i < len; i++) { char ch = str.charAt(i); if (ch == '.' || ...
java
public static boolean isIntegerType(Class pClass) { return pClass == Byte.class || pClass == Byte.TYPE || pClass == Short.class || pClass == Short.TYPE || pClass == Character.class || ...
java
public List<UploadFile> getFilesSaveToDatePath(Integer maxPostSize, String encoding) { return super.getFiles(UploadPathKit.getDatePath(), maxPostSize, encoding); }
java
public BigInteger getParaToBigInteger(String name,BigInteger defaultValue){ return this.toBigInteger(getPara(name), defaultValue); }
java
public Object resolveVariable(String pName, Object pContext) throws ELException { PageContext ctx = (PageContext) pContext; // Check for implicit objects if ("pageContext".equals(pName)) { return ctx; } else if ("pageScope".equal...
java
public List getSteps() { // simply merge our 'step' with our 'next' List l; if (next != null) l = next.getSteps(); else l = new Vector(); l.add(0, step); return l; }
java
public static String marshal(Object jaxbElement) { StringWriter sw ; try { Marshaller fm = JAXBContext.newInstance(jaxbElement.getClass()).createMarshaller(); fm.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); sw = new StringWriter(); fm.marshal(jaxbE...
java
@Override public void setInitParameters(Map<java.lang.String, java.lang.Object> initParms) { super.setInitParameters(initParms); String declarationsParm = (String) initParms.get("allowDeclarations"); String scriptletsParm = (String) initParms.get("allowScriptlets"); String expression...
java
@Override public ValidationMessage[] validate(String prefix, String uri, PageData page) { try { MyContentHandler handler = new MyContentHandler(); parser.parse(page, handler); return handler.reportResults(); } catch (ParserConfigurationException e) { r...
java
public boolean apply(String pLeft, String pRight, Logger pLogger) { return pLeft.compareTo(pRight) <= 0; }
java
@Before("@within(org.audit4j.core.annotation.Audit) || @annotation(org.audit4j.core.annotation.Audit)") public void audit(final JoinPoint jointPoint) throws Throwable { MethodSignature methodSignature = (MethodSignature) jointPoint.getSignature(); Method method = methodSignature.getMethod(); ...
java
final public Expression ValuePrefix() throws ParseException { Expression ret; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case INTEGER_LITERAL: case FLOATING_POINT_LITERAL: case STRING_LITERAL: case TRUE: case FALSE: case NULL: ret = Literal(); break; case LPAREN: jj_cons...
java
public Object evaluate(String pExpressionString, Object pContext, Class pExpectedType, Map functions, String defaultPrefix) throws ELException { return evaluate(pExpressionString, ...
java
Object evaluate(String pExpressionString, Object pContext, Class pExpectedType, Map functions, String defaultPrefix, Logger pLogger) throws ELException { // Check for null expression strings i...
java
Object convertToExpectedType(Object pValue, Class pExpectedType, Logger pLogger) throws ELException { return Coercions.coerce(pValue, pExpectedType, pLogger); }
java
Object convertStaticValueToExpectedType(String pValue, Class pExpectedType, Logger pLogger) throws ELException { // See if the value is already of the expected type if (pExpectedType == String.class || ...
java
static Map getOrCreateExpectedTypeMap(Class pExpectedType) { synchronized (sCachedExpectedTypes) { Map ret = (Map) sCachedExpectedTypes.get(pExpectedType); if (ret == null) { ret = Collections.synchronizedMap(new HashMap()); sCachedExpectedTypes.put(pExpec...
java
private synchronized void createExpressionStringMap() { if (sCachedExpressionStrings != null) { return; } final int maxSize; if ((pageContext != null) && (pageContext.getServletContext() != null)) { String value = pageContext.getServletContext().getInitParameter(...
java
static String formatParseException(String pExpressionString, ParseException pExc) { // Generate the String of expected tokens StringBuffer expectedBuf = new StringBuffer(); int maxSize = 0; boolean printedOne = false; if (pExc.expectedToken...
java
public String parseAndRender(String pExpressionString) throws ELException { Object val = parseExpressionString(pExpressionString); if (val instanceof String) { return (String) val; } else if (val instanceof Expression) { return "${" + ((Expression) val).getExp...
java
Source getSourceFromXmlAttribute() throws JspTagException, SAXException, ParserConfigurationException { Object xml = this.xml; if (xml == null) { throw new JspTagException(Resources.getMessage("TRANSFORM_XML_IS_NULL")); } // other JSTL XML tags may produce a list if ...
java
Source getSourceFromBodyContent() throws JspTagException, SAXException, ParserConfigurationException { if (bodyContent == null) { throw new JspTagException(Resources.getMessage("TRANSFORM_BODY_IS_NULL")); } String s = bodyContent.getString(); if (s == null) { thro...
java
public String validate(String pAttributeName, String pAttributeValue) { try { sEvaluator.setBypassCache(true); sEvaluator.parseExpressionString(pAttributeValue); sEvaluator.setBypassCache(false); return null; } catch (ELE...
java
public Object evaluate(String pAttributeName, String pAttributeValue, Class pExpectedType, Tag pTag, PageContext pPageContext, Map functions, String defaultPr...
java
public Object evaluate(String pAttributeName, String pAttributeValue, Class pExpectedType, Tag pTag, PageContext pPageContext) throws JspException { return evaluate(pAttributeName, ...
java
public static String parseAndRender(String pAttributeValue) throws JspException { try { return sEvaluator.parseAndRender(pAttributeValue); } catch (ELException exc) { throw new JspException (MessageFormat.format ...
java
@Override public VariableInfo[] getVariableInfo(TagData data) { // construct the relevant VariableInfo object VariableInfo id = new VariableInfo( data.getAttributeString("id"), data.getAttributeString("type") == null ? "java.lang.Object" : data...
java
public void setScope(String scopeName) { if ("page".equals(scopeName)) { scope = PageContext.PAGE_SCOPE; } else if ("request".equals(scopeName)) { scope = PageContext.REQUEST_SCOPE; } else if ("session".equals(scopeName)) { scope = PageContext....
java
@Override public void afterPropertiesSet() throws Exception { Configuration configuration = Configuration.INSTANCE; configuration.setLayout(layout); configuration.setHandlers(handlers); configuration.setFilters(filters); configuration.setCommands(commands); configurat...
java
public static String escape(String src) { // first pass to determine the length of the buffer so we only allocate once int length = 0; for (int i = 0; i < src.length(); i++) { char c = src.charAt(i); String escape = getEscape(c); if (escape != null) { ...
java
public static void emit(Object src, boolean escapeXml, JspWriter out) throws IOException { if (src instanceof Reader) { emit((Reader) src, escapeXml, out); } else { emit(String.valueOf(src), escapeXml, out); } }
java
public static void emit(String src, boolean escapeXml, JspWriter out) throws IOException { if (escapeXml) { emit(src, out); } else { out.write(src); } }
java
public static void emit(Reader src, boolean escapeXml, JspWriter out) throws IOException { int bufferSize = out.getBufferSize(); if (bufferSize == 0) { bufferSize = 4096; } char[] buffer = new char[bufferSize]; int count; while ((count = src.read(buffer)) > 0)...
java
public void addSQLParameter(Object o) { if (parameters == null) { parameters = new ArrayList(); } parameters.add(o); }
java
public Object evaluate(Object pContext, VariableResolver pResolver, Map functions, String defaultPrefix, Logger pLogger) throws ELException { Object ret = mPrefix.evaluate(pContext, pResolver,...
java
public void configInterceptor(Interceptors me) { // add excetion interceptor me.add(new ExceptionInterceptor()); if (this.getHttpPostMethod()) { me.add(new POST()); } // config others configMoreInterceptors(me); }
java
@Override public int doStartTag() throws JspException { try { XPathContext context = XalanUtil.getContext(this, pageContext); String result = select.execute(context, context.getCurrentNode(), null).str(); EscapeXML.emit(result, escapeXml, pageContext.getOut()); retur...
java
public static ImplicitObjects getImplicitObjects(PageContext pContext) { ImplicitObjects objs = (ImplicitObjects) pContext.getAttribute(sAttributeName, PageContext.PAGE_SCOPE); if (objs == null) { objs = new Implicit...
java
public static Map createSessionScopeMap(PageContext pContext) { final PageContext context = pContext; return new EnumeratedMap() { public Enumeration enumerateKeys() { return context.getAttributeNamesInScope (PageContext.SESSIO...
java
public static Map createParamMap(PageContext pContext) { final HttpServletRequest request = (HttpServletRequest) pContext.getRequest(); return new EnumeratedMap() { public Enumeration enumerateKeys() { return request.getParameterNames()...
java
public static Map createHeaderMap(PageContext pContext) { final HttpServletRequest request = (HttpServletRequest) pContext.getRequest(); return new EnumeratedMap() { public Enumeration enumerateKeys() { return request.getHeaderNames();...
java
public static Map createHeadersMap(PageContext pContext) { final HttpServletRequest request = (HttpServletRequest) pContext.getRequest(); return new EnumeratedMap() { public Enumeration enumerateKeys() { return request.getHeaderNames()...
java
public static Map createInitParamMap(PageContext pContext) { final ServletContext context = pContext.getServletContext(); return new EnumeratedMap() { public Enumeration enumerateKeys() { return context.getInitParameterNames(); } ...
java
public int doStartTag() throws JspException { try { SPathFilter s = new SPathFilter(new SPathParser(select).expression()); pageContext.setAttribute(var, s); return SKIP_BODY; } catch (ParseException ex) { throw new JspTagException(ex.toString(), ex); } }
java
public boolean isMatchingName(String uri, String localPart) { // check and normalize arguments if (localPart == null) throw new IllegalArgumentException("need non-null localPart"); if (uri != null && uri.equals("")) uri = null; // split name into uri/localPart if we haven't done so already if (this.loca...
java
private void parseStepName() { String prefix; int colonIndex = name.indexOf(":"); if (colonIndex == -1) { // no colon, so localpart is simply name (even if it's "*") prefix = null; localPart = name; } else { prefix = name.substring(0, colonIndex); localPart = name.substring(colonIndex + 1)...
java
public static XPathContext getContext(Tag child, PageContext pageContext) { // if within a forEach tag, use its context ForEachTag forEachTag = (ForEachTag) TagSupport.findAncestorWithClass(child, ForEachTag.class); if (forEachTag != null) { return forEachTag.getContext(); } ...
java
static Object coerceToJava(XObject xo) throws TransformerException { if (xo instanceof XBoolean) { return xo.bool(); } else if (xo instanceof XNumber) { return xo.num(); } else if (xo instanceof XString) { return xo.str(); } else if (xo instanceof XNod...
java
@Override public int doStartTag() throws JspException { if (end != -1 && begin > end) { // JSTL 1.1. We simply do not execute the loop. return SKIP_BODY; } // we're beginning a new iteration, so reset our counts (etc.) index = 0; count = 1; la...
java