@Override public T get() { if (freeN == 0) { try { instancesN++; return factory.call(); } catch (Exception e) { throw U.rte(e); } } else { T obj = free[--freeN]; assert obj != null; return obj; } }
@SuppressWarnings("unchecked") @Override public <E> Class<E> getEntityTypeFor(Class<E> clazz) { if (IEntity.class.isAssignableFrom(clazz)) { if (Proxy.class.isAssignableFrom(clazz)) { for (Class<?> interf : clazz.getInterfaces()) { if (IEntity.class.isAssignableFrom(interf)) { return (Class<E>) interf; } } throw U.rte("Cannot find entity type for: %s!", clazz); } } return clazz; }
public Object invoke(Object target, Method method, Object[] args) throws Throwable { Class<?> methodClass = method.getDeclaringClass(); String name = method.getName(); Class<?> ret = method.getReturnType(); Class<?>[] paramTypes = method.getParameterTypes(); if (methodClass.equals(Object.class) || methodClass.equals(EntityImpl.class) || methodClass.equals(EntityCommons.class) || methodClass.equals(IEntityCommons.class) || methodClass.equals(IEntity.class)) { return method.invoke(entity, args); } boolean returnsCol = ret.equals(DbColumn.class); boolean returnsSet = ret.equals(DbSet.class); boolean returnsList = ret.equals(DbList.class); boolean returnsRef = ret.equals(DbRef.class); boolean has0arg = paramTypes.length == 0; if (has0arg) { if (returnsCol) { return entity.column(method); } else if (returnsSet) { return entity.set(method); } else if (returnsList) { return entity.list(method); } else if (returnsRef) { return entity.ref(method); } } // in case something is missed throw U.rte("Not implemented: " + name); }
if (SuccessException.isSuccess(e)) { success = true; throw U.rte(e); } else { Log.error("Error in transaction, rolling back", e);
public static Date date(String value) { if (U.isEmpty(value)) { return null; } String[] parts = value.split("(\\.|-|/)"); int a = parts.length > 0 ? U.num(parts[0]) : -1; int b = parts.length > 1 ? U.num(parts[1]) : -1; int c = parts.length > 2 ? U.num(parts[2]) : -1; switch (parts.length) { case 3: if (isDay(a) && isMonth(b) && isYear(c)) { return date(a, b, c); } else if (isYear(a) && isMonth(b) && isDay(c)) { return date(c, b, a); } break; case 2: if (isDay(a) && isMonth(b)) { return date(a, b, thisYear()); } break; default: } throw U.rte("Invalid date: " + value); }