@Override public String toString() { final TokenBuilder tb = new TokenBuilder().add(var.toString()).add(' ').add(ASSIGN); tb.add(' ').add(expr.toString()); if (coll != null) tb.add(' ').add(COLLATION).add(" \"").add(coll.uri()).add('"'); return tb.toString(); }
@Override public final int diff(final Item it, final Collation coll, final InputInfo ii) throws QueryException { return it.type.isUntyped() ? coll == null ? Token.diff(string(), it.string(ii)) : coll.compare(string(), it.string(ii)) : -it.diff(this, coll, ii); }
/** * @param books This array will NOT be modified. * @return a new array of books already sorted. */ public static Book[] sortAlphabetically(Book[] books) { class Collation { Book book; String base; int number; } Collation[] cols = new Collation[books.length]; for (int i = 0; i < books.length; i++) { Collation c = new Collation(); Book book = books[i]; c.book = book; c.base = book.shortName; // default c.number = 0; // default int numberedBookCategory = book.bookId >= numberedBookMap.length ? 0 : numberedBookMap[book.bookId]; if (numberedBookCategory > 0) { String startsWith = numberedBookStartsWiths[numberedBookCategory]; if (book.shortName.startsWith(startsWith)) { c.base = book.shortName.substring(startsWith.length()).trim(); c.number = numberedBookCategory; } else { String startsWithNumber = numberedBookStartsWithNumbers[numberedBookCategory]; if (book.shortName.startsWith(startsWithNumber)) { c.base = book.shortName.substring(startsWithNumber.length()).trim(); c.number = numberedBookCategory; } } } cols[i] = c; } Arrays.sort( cols, new Comparator<Collation>() { @Override public int compare(Collation a, Collation b) { int compare = a.base.compareToIgnoreCase(b.base); if (compare != 0) return compare; return a.number - b.number; } }); Book[] res = new Book[books.length]; for (int i = 0; i < cols.length; i++) { res[i] = cols[i].book; } return res; }
@Override public final boolean eq( final Item it, final Collation coll, final StaticContext sc, final InputInfo ii) throws QueryException { return it.type.isUntyped() ? coll == null ? Token.eq(string(), it.string(ii)) : coll.compare(string(), it.string(ii)) == 0 : it.eq(this, coll, sc, ii); }
/** * Opens this database. The database should be opened after construction. or reopened by the * close(int closemode) method during a "shutdown compact". Closes the log if there is an error. */ void reopen() { boolean isNew = false; setState(DATABASE_OPENING); try { nameManager = new HsqlNameManager(this); granteeManager = new GranteeManager(this); userManager = new UserManager(this); schemaManager = new SchemaManager(this); persistentStoreCollection = new PersistentStoreCollectionDatabase(); isReferentialIntegrity = true; sessionManager = new SessionManager(this); collation = collation.getDefaultInstance(); dbInfo = DatabaseInformation.newDatabaseInformation(this); txManager = new TransactionManager2PL(this); lobManager.createSchema(); logger.openPersistence(); isNew = logger.isNewDatabase; if (isNew) { userManager.createSAUser(); schemaManager.createPublicSchema(); lobManager.initialiseLobSpace(); logger.checkpoint(false); } lobManager.open(); dbInfo.setWithContent(true); } catch (Throwable e) { logger.closePersistence(Database.CLOSEMODE_IMMEDIATELY); logger.releaseLock(); setState(DATABASE_SHUTDOWN); clearStructures(); DatabaseManager.removeDatabase(this); if (!(e instanceof HsqlException)) { e = Error.error(ErrorCode.GENERAL_ERROR, e); } logger.logSevereEvent("could not reopen database", e); throw (HsqlException) e; } setState(DATABASE_ONLINE); }
public String[] getSettingsSQL() { HsqlArrayList list = new HsqlArrayList(); if (!getCatalogName().name.equals(HsqlNameManager.DEFAULT_CATALOG_NAME)) { String name = getCatalogName().statementName; list.add("ALTER CATALOG PUBLIC RENAME TO " + name); } if (collation.collator != null) { String name = collation.getName().statementName; list.add("SET DATABASE COLLATION " + name); } String[] array = new String[list.size()]; list.toArray(array); return array; }