code
stringlengths
73
34.1k
label
stringclasses
1 value
private void deleteAppProperties(ApplicationDefinition appDef) { Tenant tenant = Tenant.getTenant(appDef); DBTransaction dbTran = DBService.instance(tenant).startTransaction(); dbTran.deleteRow(SchemaService.APPS_STORE_NAME, appDef.getAppName()); DBService.instance(tenant).commit(dbT...
java
private void initializeApplication(ApplicationDefinition currAppDef, ApplicationDefinition appDef) { getStorageService(appDef).initializeApplication(currAppDef, appDef); storeApplicationSchema(appDef); }
java
private void storeApplicationSchema(ApplicationDefinition appDef) { String appName = appDef.getAppName(); Tenant tenant = Tenant.getTenant(appDef); DBTransaction dbTran = DBService.instance(tenant).startTransaction(); dbTran.addColumn(SchemaService.APPS_STORE_NAME, appName, COLNAME_A...
java
private ApplicationDefinition checkApplicationKey(ApplicationDefinition appDef) { Tenant tenant = Tenant.getTenant(appDef); ApplicationDefinition currAppDef = getApplication(tenant, appDef.getAppName()); if (currAppDef == null) { m_logger.info("Defining application: {}", appDef.g...
java
private StorageService verifyStorageServiceOption(ApplicationDefinition currAppDef, ApplicationDefinition appDef) { // Verify or assign StorageService String ssName = getStorageServiceOption(appDef); StorageService storageService = getStorageService(appDef); Utils.require(storageServ...
java
private ApplicationDefinition loadAppRow(Tenant tenant, Map<String, String> colMap) { ApplicationDefinition appDef = new ApplicationDefinition(); String appSchema = colMap.get(COLNAME_APP_SCHEMA); if (appSchema == null) { return null; // Not a real application definition row ...
java
private ApplicationDefinition getApplicationDefinition(Tenant tenant, String appName) { Iterator<DColumn> colIter = DBService.instance(tenant).getAllColumns(SchemaService.APPS_STORE_NAME, appName).iterator(); if (!colIter.hasNext()) { return null; } return l...
java
private Collection<ApplicationDefinition> findAllApplications(Tenant tenant) { List<ApplicationDefinition> result = new ArrayList<>(); Iterator<DRow> rowIter = DBService.instance(tenant).getAllRows(SchemaService.APPS_STORE_NAME).iterator(); while (rowIter.hasNext()) { ...
java
public SearchResultList objectQuery(TableDefinition tableDef, OlapQuery olapQuery) { checkServiceState(); return m_olap.search(tableDef.getAppDef(), tableDef.getTableName(), olapQuery); }
java
public AggregateResult aggregateQuery(TableDefinition tableDef, OlapAggregate request) { checkServiceState(); AggregationResult result = m_olap.aggregate(tableDef.getAppDef(), tableDef.getTableName(), request); return AggregateResultConverter.create(result, request); }
java
public BatchResult addBatch(ApplicationDefinition appDef, String shardName, OlapBatch batch) { return addBatch(appDef, shardName, batch, null); }
java
public void deleteShard(ApplicationDefinition appDef, String shard) { checkServiceState(); m_olap.deleteShard(appDef, shard); }
java
public UNode getStatistics(ApplicationDefinition appDef, String shard, Map<String, String> paramMap) { checkServiceState(); CubeSearcher searcher = m_olap.getSearcher(appDef, shard); String file = paramMap.get("file"); if(file != null) { return OlapStatistics.getFileData...
java
public Date getExpirationDate(ApplicationDefinition appDef, String shard) { checkServiceState(); return m_olap.getExpirationDate(appDef, shard); }
java
private boolean getOverwriteOption(Map<String, String> options) { boolean bOverwrite = true; if (options != null) { for (String name : options.keySet()) { if ("overwrite".equals(name.toLowerCase())) { bOverwrite = Boolean.parseBoolean(options.get(name...
java
private void validateApplication(ApplicationDefinition appDef) { boolean bSawAgingFreq = false; for (String optName : appDef.getOptionNames()) { String optValue = appDef.getOption(optName); switch (optName) { case CommonDefs.OPT_STORAGE_SERVICE: ...
java
private void validateTable(TableDefinition tableDef) { // No options are currently allowed: for (String optName : tableDef.getOptionNames()) { Utils.require(false, "Unknown option for OLAPService table: " + optName); } for (FieldDefinition fieldDef : tableDef.g...
java
public Collection<String> getKeyspaces(DBConn dbConn) { List<String> result = new ArrayList<>(); try { for (KsDef ksDef : dbConn.getClientSession().describe_keyspaces()) { result.add(ksDef.getName()); } } catch (Exception e) { String err...
java
public void createKeyspace(DBConn dbConn, String keyspace) { m_logger.info("Creating Keyspace '{}'", keyspace); try { KsDef ksDef = setKeySpaceOptions(keyspace); dbConn.getClientSession().system_add_keyspace(ksDef); waitForSchemaPropagation(dbConn); ...
java
public boolean keyspaceExists(DBConn dbConn, String keyspace) { try { dbConn.getClientSession().describe_keyspace(keyspace); return true; } catch (Exception e) { return false; // Notfound } }
java
public void dropKeyspace(DBConn dbConn, String keyspace) { m_logger.info("Deleting Keyspace '{}'", keyspace); try { dbConn.getClientSession().system_drop_keyspace(keyspace); waitForSchemaPropagation(dbConn); } catch (Exception ex) { String errMsg = "Fail...
java
public void createColumnFamily(DBConn dbConn, String keyspace, String cfName, boolean bBinaryValues) { m_logger.info("Creating ColumnFamily: {}:{}", keyspace, cfName); CfDef cfDef = new CfDef(); cfDef.setKeyspace(keyspace); cfDef.setName(cfName); cfDef.setColumn_ty...
java
public boolean columnFamilyExists(DBConn dbConn, String keyspace, String cfName) { KsDef ksDef = null; try { ksDef = dbConn.getClientSession().describe_keyspace(keyspace); } catch (Exception ex) { throw new RuntimeException("Failed to get keyspace definition for '" +...
java
public void deleteColumnFamily(DBConn dbConn, String cfName) { m_logger.info("Deleting ColumnFamily: {}", cfName); try { dbConn.getClientSession().system_drop_column_family(cfName); waitForSchemaPropagation(dbConn); } catch (Exception ex) { throw new Run...
java
private KsDef setKeySpaceOptions(String keyspace) { KsDef ksDef = new KsDef(); ksDef.setName(keyspace); Map<String, Object> ksDefs = m_service.getParamMap("ks_defaults"); if (ksDefs != null) { for (String name : ksDefs.keySet()) { Object value = ksDefs.g...
java
private void waitForSchemaPropagation(DBConn dbConn) { for(int i = 0; i < 5; i++) { try { Map<String, List<String>> versions = dbConn.getClientSession().describe_schema_versions(); if(versions.size() <= 1) return; m_logger.info("Schema versions are not synchronized yet. Retrying"); ...
java
public static OutputStream outputStream(File file) { try { return new FileOutputStream(file); } catch (FileNotFoundException e) { throw E.ioException(e); } }
java
public static Writer writer(File file) { try { return new FileWriter(file); } catch (IOException e) { throw E.ioException(e); } }
java
public static InputStream inputStream(File file) { // workaround http://stackoverflow.com/questions/36880692/java-file-does-not-exists-but-file-getabsolutefile-exists if (!file.exists()) { file = file.getAbsoluteFile(); } if (!file.exists()) { throw E.ioException(...
java
public static InputStream inputStream(URL url) { try { return url.openStream(); } catch (IOException e) { throw E.ioException(e); } }
java
public static Reader reader(File file) { E.illegalArgumentIfNot(file.canRead(), "file not readable: " + file.getPath()); try { return new FileReader(file); } catch (IOException e) { throw E.ioException(e); } }
java
public static String checksum(InputStream is) { try { MessageDigest md = MessageDigest.getInstance("SHA1"); byte[] dataBytes = new byte[1024]; int nread; while ((nread = is.read(dataBytes)) != -1) { md.update(dataBytes, 0, nread); } ...
java
public static Properties loadProperties(URL url) { if (null == url) { return new Properties(); } return loadProperties(inputStream(url)); }
java
@Deprecated public static void writeContent(CharSequence content, File file, String encoding) { write(content, file, encoding); }
java
public static void write(CharSequence content, File file, String encoding) { OutputStream os = null; try { os = new FileOutputStream(file); PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(os, encoding)); printWriter.print(content); printWr...
java
public static void write(CharSequence content, Writer writer, boolean closeOs) { try { writer.write(content.toString()); } catch (IOException e) { throw E.ioException(e); } finally { if (closeOs) { close(writer); } } }
java
public static int copy(InputStream is, OutputStream os, boolean closeOs) { if (closeOs) { return write(is).ensureCloseSink().to(os); } else { return write(is).to(os); } }
java
public static int write(InputStream is, File f) { try { return copy(is, new BufferedOutputStream(new FileOutputStream(f))); } catch (FileNotFoundException e) { throw E.ioException(e); } }
java
public static int copy(Reader reader, Writer writer, boolean closeWriter) { if (closeWriter) { return write(reader).ensureCloseSink().to(writer); } else { return write(reader).to(writer); } }
java
public static void write(byte b, OutputStream os) { try { os.write(b); } catch (IOException e) { throw E.ioException(e); } }
java
public static void write(byte[] data, File file) { try { write(new ByteArrayInputStream(data), new BufferedOutputStream(new FileOutputStream(file))); } catch (FileNotFoundException e) { throw E.ioException(e); } }
java
public static void write(byte[] data, OutputStream os, boolean closeSink) { try { os.write(data); } catch (IOException e) { throw E.ioException(e); } finally { if (closeSink) { close(os); } } }
java
public static void copyDirectory(File source, File target) { if (source.isDirectory()) { if (!target.exists()) { target.mkdir(); } for (String child : source.list()) { copyDirectory(new File(source, child), new File(target, child)); ...
java
public static ISObject zip(ISObject... objects) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ZipOutputStream zos = new ZipOutputStream(baos); try { for (ISObject obj : objects) { ZipEntry entry = new ZipEntry(obj.getAttribute(SObject.ATTR_FILE_NAME)); ...
java
public static File zip(File... files) { try { File temp = File.createTempFile("osgl", ".zip"); zipInto(temp, files); return temp; } catch (IOException e) { throw E.ioException(e); } }
java
public static void zipInto(File target, File... files) { ZipOutputStream zos = null; try { zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(target))); byte[] buffer = new byte[128]; for (File f : files) { ZipEntry entry = new Zip...
java
public static <T> T decode(String string, Class<T> targetType) { Type type = typeOf(targetType); return type.decode(string, targetType); }
java
public static String encode(Object o) { Type type = typeOf(o); return type.encode(o); }
java
public int lastIndexOf(java.util.List<Character> list) { return lastIndexOf((CharSequence) FastStr.of(list)); }
java
public static void addGlobalMappingFilters(String filterSpec, String ... filterSpecs) { addGlobalMappingFilter(filterSpec); for (String s : filterSpecs) { addGlobalMappingFilter(s); } }
java
public static void addGlobalMappingFilter(String filterSpec) { List<String> list = S.fastSplit(filterSpec, ","); for (String s : list) { if (S.blank(s)) { continue; } addSingleGlobalMappingFilter(s.trim()); } }
java
public static FastStr of(char[] ca) { if (ca.length == 0) return EMPTY_STR; char[] newArray = new char[ca.length]; System.arraycopy(ca, 0, newArray, 0, ca.length); return new FastStr(ca); }
java
public static FastStr of(CharSequence cs) { if (cs instanceof FastStr) { return (FastStr)cs; } return of(cs.toString()); }
java
public static FastStr of(String s) { int sz = s.length(); if (sz == 0) return EMPTY_STR; char[] buf = s.toCharArray(); return new FastStr(buf, 0, sz); }
java
public static FastStr of(StringBuilder sb) { int sz = sb.length(); if (0 == sz) return EMPTY_STR; char[] buf = new char[sz]; for (int i = 0; i < sz; ++i) { buf[i] = sb.charAt(i); } return new FastStr(buf, 0, sz); }
java
public static FastStr of(Iterable<Character> itr) { StringBuilder sb = new StringBuilder(); for (Character c : itr) { sb.append(c); } return of(sb); }
java
public static FastStr of(Collection<Character> col) { int sz = col.size(); if (0 == sz) return EMPTY_STR; char[] buf = new char[sz]; Iterator<Character> itr = col.iterator(); int i = 0; while (itr.hasNext()) { buf[i++] = itr.next(); } return ne...
java
public static FastStr of(Iterator<Character> itr) { StringBuilder sb = new StringBuilder(); while (itr.hasNext()) { sb.append(itr.next()); } return of(sb); }
java
public static FastStr unsafeOf(String s) { int sz = s.length(); if (sz == 0) return EMPTY_STR; char[] buf = bufOf(s); return new FastStr(buf, 0, sz); }
java
@SuppressWarnings("unused") public static FastStr unsafeOf(char[] buf) { E.NPE(buf); return new FastStr(buf, 0, buf.length); }
java
public static FastStr unsafeOf(char[] buf, int start, int end) { E.NPE(buf); E.illegalArgumentIf(start < 0 || end > buf.length); if (end < start) return EMPTY_STR; return new FastStr(buf, start, end); }
java
public StringValueResolver<T> attributes(Map<String, Object> attributes) { this.attributes.putAll(attributes); return this; }
java
public static SObject of(String key, File file) { if (file.canRead() && file.isFile()) { SObject sobj = new FileSObject(key, file); String fileName = file.getName(); sobj.setAttribute(ATTR_FILE_NAME, file.getName()); String fileExtension = S.fileExtension(fileName...
java
public static SObject loadResource(String url) { InputStream is = SObject.class.getResourceAsStream(url); if (null == is) { return null; } String filename = S.afterLast(url, "/"); if (S.blank(filename)) { filename = url; } return of(randomK...
java
public static SObject of(String key, String content, String... attrs) { SObject sobj = of(key, content); Map<String, String> map = C.Map(attrs); sobj.setAttributes(map); return sobj; }
java
public static SObject of(String key, byte[] buf, int len) { if (len <= 0) { return of(key, new byte[0]); } if (len >= buf.length) { return of(key, buf); } byte[] ba = new byte[len]; System.arraycopy(buf, 0, ba, 0, len); return of(key, ba); ...
java
public static String typeOfSuffix(String fileExtension) { MimeType mimeType = indexByFileExtension.get(fileExtension); return null == mimeType ? fileExtension : mimeType.type; }
java
public List<String> preview(int limit, boolean noHeaderLine) { E.illegalArgumentIf(limit < 1, "limit must be positive integer"); return fetch(noHeaderLine ? 1 : 0, limit); }
java
public String fetch(int lineNumber) { E.illegalArgumentIf(lineNumber < 0, "line number must not be negative number: " + lineNumber); E.illegalArgumentIf(lineNumber >= lines(), "line number is out of range: " + lineNumber); List<String> list = fetch(lineNumber, 1); return list.isEmpty() ?...
java
public List<String> fetch(int offset, int limit) { E.illegalArgumentIf(offset < 0, "offset must not be negative number"); E.illegalArgumentIf(offset >= lines(), "offset is out of range: " + offset); E.illegalArgumentIf(limit < 1, "limit must be at least 1"); BufferedReader reader = IO.bu...
java
public static Map<String, Class> buildTypeParamImplLookup(Class theClass) { Map<String, Class> lookup = new HashMap<>(); buildTypeParamImplLookup(theClass, lookup); return lookup; }
java
public static String encodeUrlSafeBase64(String value) { return new String(UrlSafeBase64.encode(value.getBytes(Charsets.UTF_8))); }
java
public static String hexMD5(String value) { try { MessageDigest messageDigest = MessageDigest.getInstance("MD5"); messageDigest.reset(); messageDigest.update(value.getBytes("utf-8")); byte[] digest = messageDigest.digest(); return byteToHexString(diges...
java
public static String hexSHA1(String value) { try { MessageDigest md; md = MessageDigest.getInstance("SHA-1"); md.update(value.getBytes("utf-8")); byte[] digest = md.digest(); return byteToHexString(digest); } catch (Exception ex) { ...
java
public static void NPE(Object o1, Object o2, Object o3, Object... objects) { NPE(o1, o2, o3); for (Object o : objects) { if (null == o) { throw new NullPointerException(); } } }
java
public static RuntimeException asRuntimeException(Exception e) { if (e instanceof RuntimeException) { return (RuntimeException) e; } return UnexpectedMethodInvocationException.triage(e); }
java
public Stream<JsonObject> parseJsonLines(Reader r) { return StreamSupport.stream(Spliterators.spliteratorUnknownSize(jsonLinesIterator(r), Spliterator.ORDERED), false); }
java
public static org.w3c.dom.Document getW3cDocument(JsonElement value, String rootName) { Element root = getElement(value, rootName); try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = ...
java
public @Nonnull JsonBuilder put(String key, String s) { object.put(key, primitive(s)); return this; }
java
public @Nonnull JsonBuilder put(String key, boolean b) { object.put(key, primitive(b)); return this; }
java
public @Nonnull JsonBuilder put(String key, Number n) { object.put(key, primitive(n)); return this; }
java
public @Nonnull JsonBuilder putArray(String key, String... values) { JsonArray jjArray = new JsonArray(); for (String string : values) { jjArray.add(primitive(string)); } object.put(key, jjArray); return this; }
java
public static @Nonnull Entry<String,JsonElement> field(String key, JsonElement value) { Entry<String, JsonElement> entry = new Entry<String,JsonElement>() { @Override public String getKey() { return key; } @Override public JsonElement...
java
public static @Nonnull Entry<String,JsonElement> field(String key, Object value) { return field(key, fromObject(value)); }
java
public JsonElement get(String label) { int i = 0; try{ for (JsonElement e : this) { if(e.isPrimitive() && e.asPrimitive().asString().equals(label)) { return e; } else if((e.isObject() || e.isArray()) && Integer.valueOf(label).equals(i)) { ...
java
public boolean replace(JsonElement e1, JsonElement e2) { int index = indexOf(e1); if(index>=0) { set(index, e2); return true; } else { return false; } }
java
public boolean replace(Object e1, Object e2) { return replace(fromObject(e1),fromObject(e2)); }
java
public boolean replaceObject(JsonObject e1, JsonObject e2, String...path) { JsonElement compareElement = e1.get(path); if(compareElement == null) { throw new IllegalArgumentException("specified path may not be null in object " + StringUtils.join(path)); } int i=0; for...
java
public @Nonnull Iterable<JsonObject> objects() { final JsonArray parent=this; return () -> { final Iterator<JsonElement> iterator = parent.iterator(); return new Iterator<JsonObject>() { @Override public boolean hasNext() { ret...
java
public @Nonnull Iterable<JsonArray> arrays() { final JsonArray parent=this; return () -> { final Iterator<JsonElement> iterator = parent.iterator(); return new Iterator<JsonArray>() { @Override public boolean hasNext() { return...
java
public @Nonnull Iterable<String> strings() { final JsonArray parent=this; return () -> { final Iterator<JsonElement> iterator = parent.iterator(); return new Iterator<String>() { @Override public boolean hasNext() { return iter...
java
public @Nonnull Iterable<Double> doubles() { final JsonArray parent=this; return () -> { final Iterator<JsonElement> iterator = parent.iterator(); return new Iterator<Double>() { @Override public boolean hasNext() { return iter...
java
@Override public void add(final String... elements) { for (String s : elements) { JsonPrimitive primitive = primitive(s); if (!contains(primitive)) { add(primitive); } } }
java
@Override public boolean add(final String s) { JsonPrimitive primitive = primitive(s); if (!contains(primitive)) { return add(primitive); } else { return false; } }
java
public JsonSet withIdStrategy(IdStrategy strategy) { this.strategy = strategy; if(size()>0) { JsonSet seen=new JsonSet().withIdStrategy(strategy); Iterator<JsonElement> iterator = this.iterator(); while (iterator.hasNext()) { JsonElement e = iterator.n...
java
public static WrappedRequest wrap(final HttpServletRequest request) throws IOException { if (request instanceof WrappedRequest) { return (WrappedRequest) request; } return new WrappedRequest(request); }
java
public boolean accept(Class<?> aClass) { try { return (testKryo.getRegistration(aClass) != null); } catch (IllegalArgumentException e) { return false; } }
java
public static String getNameSpaceName(String pageTitle) { Matcher matcher = namespacePattern.matcher(pageTitle); if (matcher.find()) { // LOGGER.log(Level.INFO,pageTitle); return matcher.group(1); } return null; }
java
@XmlElementWrapper(name="revisions") @XmlElement(name="rev", type=Rev.class) public List<Rev> getRevisions() { return revisions; }
java
@XmlElementWrapper(name="images") @XmlElement(name="im", type=Im.class) public List<Im> getImages() { return images; }
java