use of org.apache.commons.lang.exception.NestableRuntimeException in project otter by alibaba.
the class AbstractDbDialect method initTables.
// ================================ helper method ==========================
private void initTables(final JdbcTemplate jdbcTemplate) {
this.tables = OtterMigrateMap.makeSoftValueComputingMap(new Function<List<String>, Table>() {
public Table apply(List<String> names) {
Assert.isTrue(names.size() == 2);
try {
beforeFindTable(jdbcTemplate, names.get(0), names.get(0), names.get(1));
DdlUtilsFilter filter = getDdlUtilsFilter(jdbcTemplate, names.get(0), names.get(0), names.get(1));
Table table = DdlUtils.findTable(jdbcTemplate, names.get(0), names.get(0), names.get(1), filter);
afterFindTable(table, jdbcTemplate, names.get(0), names.get(0), names.get(1));
if (table == null) {
throw new NestableRuntimeException("no found table [" + names.get(0) + "." + names.get(1) + "] , pls check");
} else {
return table;
}
} catch (Exception e) {
throw new NestableRuntimeException("find table [" + names.get(0) + "." + names.get(1) + "] error", e);
}
}
});
}
use of org.apache.commons.lang.exception.NestableRuntimeException in project otter by alibaba.
the class MysqlDialect method initShardColumns.
private void initShardColumns() {
// soft引用设置,避免内存爆了
GenericMapMaker mapMaker = null;
mapMaker = new MapMaker().softValues().evictionListener(new MapEvictionListener<List<String>, Table>() {
public void onEviction(List<String> names, Table table) {
logger.warn("Eviction For Table:" + table);
}
});
this.shardColumns = mapMaker.makeComputingMap(new Function<List<String>, String>() {
public String apply(List<String> names) {
Assert.isTrue(names.size() == 2);
try {
String result = DdlUtils.getShardKeyByDRDS(jdbcTemplate, names.get(0), names.get(0), names.get(1));
if (StringUtils.isEmpty(result)) {
return "";
} else {
return result;
}
} catch (Exception e) {
throw new NestableRuntimeException("find table [" + names.get(0) + "." + names.get(1) + "] error", e);
}
}
});
}
use of org.apache.commons.lang.exception.NestableRuntimeException in project otter by alibaba.
the class DistributedLock method lock.
/**
* 尝试获取锁操作,阻塞式可被中断
*/
public void lock() throws InterruptedException, KeeperException {
// 可能初始化的时候就失败了
if (exception != null) {
throw exception;
}
if (interrupt != null) {
throw interrupt;
}
if (other != null) {
throw new NestableRuntimeException(other);
}
if (isOwner()) {
// 锁重入
return;
}
BooleanMutex mutex = new BooleanMutex();
acquireLock(mutex);
mutex.get();
if (exception != null) {
unlock();
throw exception;
}
if (interrupt != null) {
unlock();
throw interrupt;
}
if (other != null) {
unlock();
throw new NestableRuntimeException(other);
}
}
use of org.apache.commons.lang.exception.NestableRuntimeException in project applause by applause.
the class StringEscapeUtils method unescapeJava.
/**
* <p>Unescapes any Java literals found in the <code>String</code> to a
* <code>Writer</code>.</p>
*
* <p>For example, it will turn a sequence of <code>'\'</code> and
* <code>'n'</code> into a newline character, unless the <code>'\'</code>
* is preceded by another <code>'\'</code>.</p>
*
* <p>A <code>null</code> string input has no effect.</p>
*
* @param out the <code>Writer</code> used to output unescaped characters
* @param str the <code>String</code> to unescape, may be null
* @throws IllegalArgumentException if the Writer is <code>null</code>
* @throws IOException if error occurs on underlying Writer
*/
public static void unescapeJava(Writer out, String str) throws IOException {
if (out == null) {
throw new IllegalArgumentException("The Writer must not be null");
}
if (str == null) {
return;
}
int sz = str.length();
StringBuffer unicode = new StringBuffer(4);
boolean hadSlash = false;
boolean inUnicode = false;
for (int i = 0; i < sz; i++) {
char ch = str.charAt(i);
if (inUnicode) {
// if in unicode, then we're reading unicode
// values in somehow
unicode.append(ch);
if (unicode.length() == 4) {
// which represents our unicode character
try {
int value = Integer.parseInt(unicode.toString(), 16);
out.write((char) value);
unicode.setLength(0);
inUnicode = false;
hadSlash = false;
} catch (NumberFormatException nfe) {
throw new NestableRuntimeException("Unable to parse unicode value: " + unicode, nfe);
}
}
continue;
}
if (hadSlash) {
// handle an escaped value
hadSlash = false;
switch(ch) {
case '\\':
out.write('\\');
break;
case '\'':
out.write('\'');
break;
case '\"':
out.write('"');
break;
case 'r':
out.write('\r');
break;
case 'f':
out.write('\f');
break;
case 't':
out.write('\t');
break;
case 'n':
out.write('\n');
break;
case 'b':
out.write('\b');
break;
case 'u':
{
// uh-oh, we're in unicode country....
inUnicode = true;
break;
}
default:
out.write(ch);
break;
}
continue;
} else if (ch == '\\') {
hadSlash = true;
continue;
}
out.write(ch);
}
if (hadSlash) {
// then we're in the weird case of a \ at the end of the
// string, let's output it anyway.
out.write('\\');
}
}
use of org.apache.commons.lang.exception.NestableRuntimeException in project pentaho-platform by pentaho.
the class JcrCmsOutputHandler method getFileOutputContentItem.
@Override
public IContentItem getFileOutputContentItem() {
String contentName = getContentRef();
try {
Repository repository = getRepository();
if (repository == null) {
Logger.error(JcrCmsOutputHandler.class.getName(), Messages.getInstance().getString(// $NON-NLS-1$
"JcrCmsOutputHandler.ERROR_0001_GETTING_CMSREPO"));
return null;
}
Session jcrSession = getJcrSession(repository);
if (jcrSession == null) {
Logger.error(JcrCmsOutputHandler.class.getName(), Messages.getInstance().getString(// $NON-NLS-1$
"JcrCmsOutputHandler.ERROR_0002_GETTING_SESSION"));
return null;
}
// Use the root node as a starting point
Node root = jcrSession.getRootNode();
if (root == null) {
Logger.error(JcrCmsOutputHandler.class.getName(), Messages.getInstance().getString(// $NON-NLS-1$
"JcrCmsOutputHandler.ERROR_0003_GETTING_ROOT"));
return null;
}
Node node = root;
// parse the path
// $NON-NLS-1$
StringTokenizer tokenizer = new StringTokenizer(contentName, "/");
int levels = tokenizer.countTokens();
for (int idx = 0; idx < levels - 1; idx++) {
String folder = tokenizer.nextToken();
if (!node.hasNode(folder)) {
// Create an unstructured node under which to import the XML
// $NON-NLS-1$
node = node.addNode(folder, "nt:folder");
} else {
node = node.getNodes(folder).nextNode();
}
}
// we should be at the right level now
String fileName = tokenizer.nextToken();
Node fileNode = null;
Node contentNode = null;
Version version = null;
if (node.hasNode(fileName)) {
fileNode = node.getNode(fileName);
// $NON-NLS-1$
contentNode = fileNode.getNode("jcr:content");
if (contentNode.isLocked()) {
JcrCmsOutputHandler.logger.warn(Messages.getInstance().getString("JcrCmsOutputHandler.ERROR_0004_NODE_LOCKED", // $NON-NLS-1$
contentName));
return null;
}
if (contentNode.isCheckedOut()) {
JcrCmsOutputHandler.logger.warn(Messages.getInstance().getString("JcrCmsOutputHandler.ERROR_0005_NODE_CHECKED_OUT", // $NON-NLS-1$
contentName));
return null;
}
contentNode.checkout();
VersionHistory history = contentNode.getVersionHistory();
VersionIterator iterator = history.getAllVersions();
while (iterator.hasNext()) {
version = iterator.nextVersion();
JcrCmsOutputHandler.logger.trace(version.getPath() + "," + version.getName() + "," + version.getIndex() + "," + // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
version.getCreated().toString());
}
} else {
// $NON-NLS-1$
fileNode = node.addNode(fileName, "nt:file");
// $NON-NLS-1$
fileNode.addMixin("mix:versionable");
// create the mandatory child node - jcr:content
// $NON-NLS-1$ //$NON-NLS-2$
contentNode = fileNode.addNode("jcr:content", "nt:resource");
// $NON-NLS-1$
contentNode.addMixin("mix:versionable");
// $NON-NLS-1$
contentNode.addMixin("mix:filename");
// $NON-NLS-1$
contentNode.setProperty("jcr:mimeType", getMimeType());
// $NON-NLS-1$
contentNode.setProperty("jcr:name", fileName);
// $NON-NLS-1$
contentNode.setProperty("jcr:encoding", LocaleHelper.getSystemEncoding());
}
CmsContentListener listener = new CmsContentListener(contentNode, jcrSession);
BufferedContentItem contentItem = new BufferedContentItem(listener);
listener.setContentItem(contentItem);
if (false) {
// Disable faked search for now
// $NON-NLS-1$
search("test", jcrSession);
}
return contentItem;
} catch (LockException le) {
Logger.error(JcrCmsOutputHandler.class.getName(), Messages.getInstance().getString("JcrCmsOutputHandler.ERROR_0006_GETTING_OUTPUTHANDLER") + contentName, // $NON-NLS-1$
le);
} catch (NestableRuntimeException nre) {
Logger.error(JcrCmsOutputHandler.class.getName(), Messages.getInstance().getString("JcrCmsOutputHandler.ERROR_0006_GETTING_OUTPUTHANDLER") + contentName, // $NON-NLS-1$
nre);
} catch (RepositoryException re) {
Logger.error(JcrCmsOutputHandler.class.getName(), Messages.getInstance().getString("JcrCmsOutputHandler.ERROR_0006_GETTING_OUTPUTHANDLER") + contentName, // $NON-NLS-1$
re);
}
return null;
}
Aggregations