public void setEventListenerClass(String className) { if (className == null || className.length() == 0) { eventListener = null; } else { try { eventListener = (DatabaseEventListener) Utils.loadUserClass(className).newInstance(); eventListener.init(name); } catch (Throwable e) { throw DbException.get(ErrorCode.ERROR_SETTING_DATABASE_EVENT_LISTENER_2, e, className, e.toString()); } } }
@Override public void reset() { if (sort != null) { for (ResultDiskTape tape : tapes) { tape.pos = tape.start; tape.buffer = Utils.newSmallArrayList(); } } else { mainTape.pos = FileStorage.HEADER_LENGTH; mainTape.buffer = Utils.newSmallArrayList(); } }
@Override public Object getObject() { if (javaObject == null) { javaObject = Utils.deserialize(value); } return javaObject; }
/** * Constructs an instance of the given class, which must have a no-arg or default constructor. * @param classname Fully qualified classname. * @param readable Descriptive noun for the role the class plays. * @throws ConfigException If the class cannot be found. */ public static <T> T construct(String classname, String readable) throws ConfigException { Class<T> cls = Utils.classForName(classname, readable); return construct(cls, classname, readable); }
ArrayList<Row> rows = Utils.newSmallArrayList(); String catalog = identifier(database.getShortName()); boolean admin = session.getUser().isAdmin(); "user.country", "user.language", "user.variant", "file.encoding" }; for (String s : settings) { add(rows, "property." + s, Utils.getProperty(s, "")); String resource = Constants.RESOURCES_DIR + "help.csv"; try { Reader reader = Utils.getResourceAsReader(resource); Csv csv = new Csv(); csv.setLineCommentCharacter('#');
private static boolean getProperty(String key, boolean defaultValue) { return Utils.getProperty(Constants.PROJECT_NAME_PREFIX + key, defaultValue); } }
/** * Check if the file password hash is correct. * * @param testCipher the cipher algorithm * @param testHash the hash code * @return true if the cipher algorithm and the password match */ boolean validateFilePasswordHash(String testCipher, byte[] testHash) { if (!StringUtils.equals(testCipher, dbSettings.cipher)) { return false; } return Utils.compareSecure(testHash, dbSettings.filePasswordHash); }
private static void loadConfig() { ConfigLoader loader; String loaderClass = Config.getProperty("config.loader"); if (loaderClass != null && Lealone.class.getResource("/" + loaderClass.replace('.', '/') + ".class") != null) { loader = Utils.<ConfigLoader> construct(loaderClass, "configuration loading"); } else { loader = new YamlConfigLoader(); } config = loader.loadConfig(); }
/** * Calls an instance method via reflection. This will try to use the method * where the most parameter classes match exactly (this algorithm is simpler * than the one in the Java specification, but works well for most cases). * * @param instance the instance on which the call is done * @param methodName a string with the method name * @param params the method parameters * @return the return value from this call */ public static Object callMethod(Object instance, String methodName, Object... params) throws Exception { return callMethod(instance, instance.getClass(), methodName, params); }
private static String getProperty(String key, String defaultValue) { return Utils.getProperty(Constants.PROJECT_NAME_PREFIX + key, defaultValue); }
/** * Verify the HMAC. * * @param hmac the message authentication code * @param lobId the lobId * @throws DbException if the HMAC does not match */ public void verifyLobMac(byte[] hmac, long lobId) { byte[] result = calculateLobMac(lobId); if (!Utils.compareSecure(hmac, result)) { throw DbException.get(ErrorCode.CONNECTION_BROKEN_1, "Invalid lob hmac; possibly the connection was re-opened internally"); } }
/** * Calls a static method via reflection. This will try to use the method * where the most parameter classes match exactly (this algorithm is simpler * than the one in the Java specification, but works well for most cases). * * @param classAndMethod a string with the entire class and method name, eg. * "java.lang.System.gc" * @param params the method parameters * @return the return value from this call */ public static Object callStaticMethod(String classAndMethod, Object... params) throws Exception { int lastDot = classAndMethod.lastIndexOf('.'); String className = classAndMethod.substring(0, lastDot); String methodName = classAndMethod.substring(lastDot + 1); return callMethod(null, Class.forName(className), methodName, params); }
/** * This constructor is used if the result set is later populated with addRow. */ public SimpleResultSet() { rows = Utils.newSmallArrayList(); }
public Aggregate getInstance() { if (javaClass == null) { javaClass = Utils.loadUserClass(className); } Object obj; try { obj = javaClass.newInstance(); Aggregate agg; if (obj instanceof Aggregate) { agg = (Aggregate) obj; } else { agg = new AggregateWrapper((AggregateFunction) obj); } return agg; } catch (Exception e) { throw DbException.convert(e); } }
@Override public void set(PreparedStatement prep, int parameterIndex) throws SQLException { Object obj = Utils.deserialize(getBytesNoCopy()); prep.setObject(parameterIndex, obj, Types.JAVA_OBJECT); }
private static int getProperty(String key, int defaultValue) { return Utils.getProperty(Constants.PROJECT_NAME_PREFIX + key, defaultValue); }
/** * Check the password of this user. * * @param userPasswordHash the password data (the user password hash) * @return true if the user password hash is correct */ public boolean validateUserPasswordHash(byte[] userPasswordHash) { if (userPasswordHash.length == 0 && passwordHash.length == 0) { return true; } if (userPasswordHash.length == 0) { userPasswordHash = SHA256.getKeyPasswordHash(getName(), new char[0]); } byte[] hash = SHA256.getHashWithSalt(userPasswordHash, salt); return Utils.compareSecure(hash, passwordHash); }
/** * Add a column to the natural join key column list. * * @param c the column to add */ public void addNaturalJoinColumn(Column c) { if (naturalJoinColumns == null) { naturalJoinColumns = Utils.newSmallArrayList(); } naturalJoinColumns.add(c); }
Class<?> d = Utils.loadUserClass(driver); if (java.sql.Driver.class.isAssignableFrom(d)) { return DriverManager.getConnection(url, prop);
Object o = SysProperties.SERIALIZE_JAVA_OBJECT ? Utils.deserialize(v.getBytes()) : v.getObject(); if (paramClass.isAssignableFrom(o.getClass())) { return o;