private String getStandardizedPassword(String password) { if(StringUtils.stringEmpty(password)) { return STANDARD_EMPTY_PASS; } else { return password; } }
private static boolean isClientRequest(String requestContext) { if(StringUtils.stringNotEmpty(requestContext)) { if(requestContext.equals("grid")) { return false; } } return true; }
public static String resolveResourcePath(String resourcePath) { if(resourcePath.startsWith("classpath:")) { String strippedPath = resourcePath.replace("classpath:", ""); return loadResource(strippedPath).toString(); } else { return resourcePath; } }
private PropertyMetadata loadProperty(PropertyDescriptor propertyDescriptor) throws JasDBStorageException { Method readMethod = propertyDescriptor.getReadMethod(); Method writeMethod = propertyDescriptor.getWriteMethod(); if(readMethod != null && writeMethod != null) { Optional<JasDBProperty> readAnnotation = getOptionalAnnotation(readMethod, JasDBProperty.class); Optional<JasDBProperty> writeAnnotation = getOptionalAnnotation(writeMethod, JasDBProperty.class); Optional<Id> idAnnotation = getOptionalAnnotation(readMethod, Id.class); if (readAnnotation.isPresent() || writeAnnotation.isPresent()) { TypeMapper typeMapper = getTypeMapper(readMethod); //here a number of override for the property name, first check read method, next write else default to property bean name String propertyName = readAnnotation.isPresent() ? readAnnotation.get().name() : ""; propertyName = StringUtils.stringEmpty(propertyName) ? writeAnnotation.isPresent() ? writeAnnotation.get().name() : "" : propertyName; propertyName = StringUtils.stringEmpty(propertyName) ? propertyDescriptor.getName() : propertyName; boolean nullable = readAnnotation.isPresent() ? readAnnotation.get().nullable() : writeAnnotation.get().nullable(); LOG.debug("Found Entity property: {} nullable: {}", propertyDescriptor.getName(), nullable); return new PropertyMetadataImpl(typeMapper, readMethod, writeMethod, propertyName, idAnnotation.isPresent(), nullable); } } else { LOG.debug("Read or Write method not defined for property: {}", propertyDescriptor.getName()); } return null; }
public void remove(String instanceId, String bagName) throws JasDBStorageException { File writerPath = getWriterPath(instanceId, bagName); RecordWriter recordWriter = recordWriters.get(writerPath.toString()); recordWriter.closeWriter(); File indexLocation = new File(removeExtension(writerPath.toString()) + ".idx"); deleteSafely(indexLocation); deleteSafely(writerPath); recordWriters.remove(writerPath.toString()); }
public static Configuration loadConfiguration(String fileName) throws CoreConfigException { LOG.info("Loading configuration: {}", fileName); Document document = XMLReader.getDocument(fileName); return new XMLConfiguration(document.getDocumentElement()); }
public static String toString(RecordResult result) throws JasDBStorageException { InputStream inputStream = result.getStream(); return toString(inputStream); }
public static <T extends Annotation> T getAnnotation(AnnotatedElement type, Class<T> annotationType) throws JasDBStorageException { Optional<T> annotation = getOptionalAnnotation(type, annotationType); if(annotation.isPresent()) { return annotation.get(); } else { throw new JasDBStorageException("Unable to get annotation: " + annotationType); } }
public TransactionalRecordWriter(File recordLocation) { this.indexLocation = new File(FileUtils.removeExtension(recordLocation.toString()) + ".idx"); this.writer = new FSWriter(recordLocation); }
public static <T> T loadClass(Class<T> expectedSubtype, String className, Object[] args) throws ReflectionException { List<Class<?>> argumentTypes = new ArrayList<Class<?>>(); for(Object argument : args) { argumentTypes.add(argument.getClass()); } return loadClass(expectedSubtype, className, argumentTypes.toArray(new Class<?>[0]), args); }
private void handleCreateNewPidFile() throws JasDBStorageException { File pidFile = new File(datastoreLocation, PID_FILE); lastShutdownClean = !pidFile.exists(); LOG.info("Last shutdown clean: {}", lastShutdownClean); try { if(datastoreLocation.exists() || datastoreLocation.mkdirs()) { FileUtils.writeToFile(pidFile, "JasDB Instance Started, " + PID); LOG.info("Created JasDB pid file: {}", pidFile); } else { throw new JasDBStorageException("Unable to create database path, directories could not be created: " + datastoreLocation) ; } } catch(IOException e) { throw new JasDBStorageException("Unable to open JasDB metadata store, pid file: " + pidFile.toString() + " could not be created"); } }
public static Document getDocument(String configFile) throws CoreConfigException { URL resourceUrl = Thread.currentThread().getContextClassLoader().getResource(configFile); if(resourceUrl != null) { LOG.debug("Reading XML file: " + resourceUrl.toString()); return parseDocument(resourceUrl); } else { throw new ConfigurationNotFoundException("Unable to load configuration, could not be found on classpath"); } }
@Override public boolean hasInstance(String instanceId) { return StringUtils.stringNotEmpty(instanceId) && instances.containsKey(instanceId); }
public static boolean stringNotEmpty(String string) { return !stringEmpty(string); }
private static KeyFactory loadKeyFactory(String keyFactoryClass, String[] keyArgs) { try { return ReflectionLoader.loadClass(KeyFactory.class, keyFactoryClass, keyArgs); } catch(ReflectionException e) { LOG.error("Unable to load KeyFactory: {}", e.getMessage()); return null; } }
@Override public DBSession createSession() throws JasDBException { if(StringUtils.stringNotEmpty(instance)) { return new LocalDBSession(instance); } else { return new LocalDBSession(); } }
@Override public DBInstance getInstance(String instanceId) throws ConfigurationException { if(StringUtils.stringEmpty(instanceId)) { return getInstance(); } else { if(instances.containsKey(instanceId)) { return instances.get(instanceId); } else { throw new ConfigurationException("No instance was found for id: " + instanceId); } } }
@Override public Entity deserializeEntity(String serializedEntity) throws MetadataParseException { if(StringUtils.stringNotEmpty(serializedEntity)) { try { JsonParser parser = factory.createParser(serializedEntity); return deserializeEntity(parser); } catch(IOException e) { throw new MetadataParseException("Unable to parse entity", e); } } throw new MetadataParseException("Unable to parse entity metadata, empty content"); }
@Override public void removeEntity(RequestContext context, Entity entity) throws JasDBStorageException { resourceLockManager.sharedLock(); try { if(StringUtils.stringNotEmpty(entity.getInternalId())) { bagRemoveOperation.doDataOperation(instanceId, bagName, entity); } else { throw new JasDBStorageException("Unable to remove record, entity has no id specified"); } } finally { resourceLockManager.sharedUnlock(); } }
@Override public void updateEntity(RequestContext context, Entity entity) throws JasDBStorageException { resourceLockManager.sharedLock(); try { if(StringUtils.stringNotEmpty(entity.getInternalId())) { bagUpdateOperation.doDataOperation(instanceId, bagName, entity); } else { throw new JasDBStorageException("Unable to update record, entity has no id specified"); } } finally { resourceLockManager.sharedUnlock(); } }