Ranides Atterwim 10 năm trước cách đây
mục cha
commit
c06aa32246

+ 0 - 57
assira.drafts/src/main/java/net/ranides/assira/generic/IntPair.java

@@ -1,57 +0,0 @@
-/*
- * @author Ranides Atterwim <ranides@gmail.com>
- * @copyright Ranides Atterwim
- * @license WTFPL
- * @url http://ranides.net/projects/assira
- */
-package net.ranides.assira.generic;
-
-import java.io.Serializable;
-import java.util.Map;
-import java.util.Map.Entry;
-import net.ranides.assira.collection.lookups.Lookup.LookupEntry;
-import net.ranides.assira.collection.maps.IntMap.IntEntry;
-
-public class IntPair implements LookupEntry<Integer>, IntEntry<Integer>, Serializable {
-
-    private static final long serialVersionUID = 2L;
-
-    private final int key;
-    
-	private final int value;
-
-    public IntPair(int key, int value) {
-        this.key = key;
-        this.value = value;
-    }
-
-    @Override
-    public int hashCode() {
-         return key ^ value;
-    }
-
-    @Override
-    public boolean equals(Object object) {
-        if (object instanceof Entry) {
-            Map.Entry<?,?> other = (Map.Entry<?,?>)object;
-            return CompareUtils.equals(other.getKey(), key) && CompareUtils.equals(other.getValue(), value);
-        }
-	    return false;
-    }
-
-    @Override
-    public int setValue(int value) {
-        throw new UnsupportedOperationException("Immutable");
-    }
-
-    @Override
-    public int getIntValue() {
-        return value;
-    }
-
-    @Override
-    public int getIntKey() {
-        return key;
-    }
-
-}

+ 0 - 26
assira.drafts/src/main/java/net/ranides/assira/generic/Pair.java

@@ -1,26 +0,0 @@
-/*
- * @author Ranides Atterwim <ranides@gmail.com>
- * @copyright Ranides Atterwim
- * @license WTFPL
- * @url http://ranides.net/projects/assira
- */
-package net.ranides.assira.generic;
-
-import java.util.AbstractMap;
-import java.util.Map.Entry;
-
-/**
- * Immutable implementation of {@link Entry} interface.
- * @author ranides
- * @param <K>
- * @param <V>
- */
-public class Pair<K,V> extends AbstractMap.SimpleImmutableEntry<K, V> {
-
-    private static final long serialVersionUID = 2L;
-
-    public Pair(K key, V value) {
-        super(key, value);
-    }
-
-}

+ 0 - 33
assira.drafts/src/main/java/net/ranides/assira/reflection/Hello.java

@@ -1,33 +0,0 @@
-/*
- * @author Ranides Atterwim <ranides@gmail.com>
- * @copyright Ranides Atterwim
- * @license WTFPL
- * @url http://ranides.net/projects/assira.drafts
- */
-
-package net.ranides.assira.reflection;
-
-import java.util.function.Function;
-
-/**
- *
- * @author Ranides Atterwim <ranides@gmail.com>
- */
-final class Hello implements Function<Float, Double> {
-
-	private final double i;
-
-	public Hello(double i) {
-		this.i = i;
-	}
-
-	@Override
-	public Double apply(Float t) {
-		return i * t;
-	}
-
-	public double getI() {
-		return i;
-	}
-
-}

+ 0 - 192
assira.drafts/src/main/java/net/ranides/assira/reflection/LambdaParams.java

@@ -1,192 +0,0 @@
-/*
- * @author Ranides Atterwim <ranides@gmail.com>
- * @copyright Ranides Atterwim
- * @license WTFPL
- * @url http://ranides.net/projects/assira.drafts
- */
-
-package net.ranides.assira.reflection;
-
-import java.lang.reflect.Array;
-import java.lang.reflect.Method;
-import java.lang.reflect.ParameterizedType;
-import java.util.function.Function;
-import net.ranides.asm.Type;
-import net.ranides.assira.trace.ExceptionUtils;
-import sun.reflect.ConstantPool;
-
-/**
- *
- * @author Ranides Atterwim <ranides@gmail.com>
- */
-public class LambdaParams {
-
-	public static void main(String[] args) throws Exception {
-		LambdaParams that = new LambdaParams();
-		System.out.printf("(Integer a) -> String %n");
-		that.runme( (Integer a) -> "A" );
-		System.out.printf("%n%n");
-		
-		System.out.printf("(int[] a) -> Float %n");
-		that.runme( (int[] a) -> 11.0f );
-		System.out.printf("%n%n");
-		
-		System.out.printf("(String a) -> Character %n");
-		that.runme( OtherLambda::flow );
-		System.out.printf("%n%n");
-		
-		System.out.printf("(Params2 a) -> Integer %n");
-		that.runme( (Param2 v) -> 3*OtherLambda.flow("s") );
-		System.out.printf("%n%n");
-		
-		System.out.printf("(String) -> Integer %n");
-		that.runme( new Function<String, Integer>() {
-			@Override
-			public Integer apply(String t) {
-				return 0;
-			}
-			
-		});
-		System.out.printf("%n%n");
-		
-		System.out.printf("(Float) -> Double %n");
-		that.runme( new Hello(22));
-		System.out.printf("%n%n");
-		
-		Function<Integer, ?> f31 = (Integer a) -> "A";
-		Function f32 = f31;
-		
-		System.out.printf("(Integer) -> String %n");
-		that.runme(f32);
-		System.out.printf("%n%n");
-	}
-		
-	public <T,R> void runme(Function<T,R> function) throws Exception {
-		System.out.printf("type = %s%n", typeof(function));
-	}
-	
-	public static Class<?> typeof(Function function) throws Exception {
-		if(!function.getClass().isSynthetic()) {
-			return typeof_generic(function);
-		} else {
-			return typeof_lambda(function);
-		}
-	}
-	
-	private static Class<?> typeof_lambda(Function function) {
-		ConstantPool cp = Li.get(function.getClass());
-		
-		for(int i=0; i<cp.getSize(); i++) {
-			String[] info;
-			try {
-				info = cp.getMemberRefInfoAt(i);
-			} catch(Exception ex) {
-				continue;
-			}
-			
-			String parent = info[0];
-			if("java/lang/Object".equals(parent) || "java/lang/Class".equals(parent)) {
-				continue;
-			}
-			try {
-				if(1 != Type.getArgumentTypes(info[2]).length) {
-					continue;
-				}
-			} catch(Exception ex) {
-				continue;
-			}
-			
-			return vm2class(function.getClass().getClassLoader(), Type.getReturnType(info[2]).getDescriptor());
-		}
-		throw new AssertionError("Deduction of return type failed. Unsupported lambda: " + function);
-	}
-	
-	@SuppressWarnings("PMD")
-    private static Class<?> vm2class(ClassLoader loader, String vmtype) {
-		try {
-			if(vmtype.startsWith("[")) {
-				return Array.newInstance(vm2class(loader, vmtype.substring(1)), 0).getClass();
-			}
-			if(vmtype.startsWith("L") && vmtype.endsWith(";")) {
-				return Class.forName(vmtype.substring(1,vmtype.length()-1).replace('/', '.'), false, loader);
-			}
-			if("Z".equals(vmtype)) {
-				return boolean.class;
-			}
-			if("B".equals(vmtype)) {
-				return byte.class;
-			}
-			if("C".equals(vmtype)) {
-				return char.class;
-			}
-			if("S".equals(vmtype)) {
-				return short.class;
-			}
-			if("I".equals(vmtype)) {
-				return int.class;
-			}
-			if("J".equals(vmtype)) {
-				return long.class;
-			}
-			if("F".equals(vmtype)) {
-				return float.class;
-			}
-			if("D".equals(vmtype)) {
-				return double.class;
-			}
-			if("V".equals(vmtype)) {
-				return void.class;
-			}
-		} catch(ClassNotFoundException cause) {
-			throw ExceptionUtils.rethrow(cause);
-		}
-		throw new AssertionError("Unknown type: " + vmtype);
-    }
-	
-	private static Class<?> typeof_generic(Object function) {
-		ParameterizedType it = getGenericInterface(function.getClass(), Function.class);
-		java.lang.reflect.Type pt = it.getActualTypeArguments()[1];
-        if(pt instanceof Class<?>) {
-            return (Class<?>)pt;
-        }
-        if(pt instanceof ParameterizedType) {
-            return (Class<?>)(((ParameterizedType)pt).getRawType());
-        }
-        throw new AssertionError("Deduction of return type failed. Unsupported function: " + function);
-	}
-	
-	private static ParameterizedType getGenericInterface(Class<?> type, Class<?> intface) {
-		for(java.lang.reflect.Type t : type.getGenericInterfaces()) {
-			ParameterizedType pt = (ParameterizedType)t;
-			if( intface.equals(pt.getRawType()) ) {
-				return pt;
-			}
-		}
-		throw new AssertionError(type.getName() + " does not implement " + intface.getName());
-	}
-	
-	
-	private static final class Li { // NOPMD - lazy init idiom
-		
-		public static final Method GET_CONSTANT_POOL;
-		
-		static {
-			try {
-				GET_CONSTANT_POOL = Class.class.getDeclaredMethod("getConstantPool");
-				GET_CONSTANT_POOL.setAccessible(true);
-			} catch(ReflectiveOperationException cause) {
-				throw ExceptionUtils.rethrow(cause);
-			}
-		}
-		
-		public static ConstantPool get(Class<?> type) {
-			try {
-				return (ConstantPool) GET_CONSTANT_POOL.invoke(type);
-			} catch (ReflectiveOperationException cause) {
-				throw ExceptionUtils.rethrow(cause);
-			}
-		}
-		
-	}
-	
-}

+ 0 - 28
assira.drafts/src/main/java/net/ranides/assira/reflection/Param2.java

@@ -1,28 +0,0 @@
-/*
- * @author Ranides Atterwim <ranides@gmail.com>
- * @copyright Ranides Atterwim
- * @license WTFPL
- * @url http://ranides.net/projects/assira.drafts
- */
-
-package net.ranides.assira.reflection;
-
-/**
- *
- * @author Ranides Atterwim <ranides@gmail.com>
- */
-public class Param2 {
-
-	public int apply() {
-		return 0;
-	}
-	
-	public float print(String message) {
-		return 0;
-	}
-	
-	protected String append(char[] data) {
-		return "";
-	}
-	
-}

+ 46 - 0
assira.drafts/src/main/java/net/ranides/assira/trace/EQException.java

@@ -0,0 +1,46 @@
+/*
+ * @author Ranides Atterwim <ranides@gmail.com>
+ * @copyright Ranides Atterwim
+ * @license WTFPL
+ * @url http://ranides.net/projects/assira.drafts
+ */
+
+package net.ranides.assira.trace;
+
+import java.lang.management.ManagementFactory;
+import java.text.MessageFormat;
+import java.time.Instant;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ *
+ * @author Ranides Atterwim <ranides@gmail.com>
+ */
+public class EQException extends NSTException {
+    
+    private static final AtomicInteger COUNTER = new AtomicInteger(0);
+    
+    private static final class Li { // NOPMD - lazy init idiom
+        
+        public static final String VMNAME = ManagementFactory.getRuntimeMXBean().getName();
+        
+    }
+    
+    private final String uid;
+    private final String text;
+
+    public EQException(String pattern, Object... params) {
+        text = MessageFormat.format(pattern, params);
+        uid = Li.VMNAME + "@" + COUNTER.incrementAndGet();
+    }
+
+    @Override
+    public String toString() {
+        return "EMException{ " + uid + " : " + text + " }";
+    }
+
+    public String getUid() {
+        return uid;
+    }
+
+}

+ 57 - 0
assira.drafts/src/main/java/net/ranides/esb/query/EQList.java

@@ -0,0 +1,57 @@
+/*
+ * @author Ranides Atterwim <ranides@gmail.com>
+ * @copyright Ranides Atterwim
+ * @license WTFPL
+ * @url http://ranides.net/projects/assira.drafts
+ */
+
+package net.ranides.esb.query;
+
+import java.util.List;
+import java.util.stream.Stream;
+import net.ranides.assira.collection.query.CQuery;
+
+/**
+ * Idea jest taka:
+ * Odpowiedzią na zapytanie do szyny jest EQList, która zawiera pola "origin" oraz "qid". 
+ * Na serwerze odpowiedni DAO (patrz: origin) przechowuje informację o SQLu czy innym URLu 
+ * wygenerowanym dla zapytania (patrz: qid). Dane nie są jeszcze transportowane, nie zostało
+ * nawet wykonane zapytanie do żadnej bazy.
+ * 
+ * Jeśli poprosimy o dane (#list, #stream, #cstream) to do szyny idzie kolejny request (FETCH origin,qid).
+ * Teraz w odpowiednich bazach rusza zapytanie, a wyniki są transportowane do klienta.
+ * 
+ * Każdy DAO oferuje funkcje: mapowania, filtrowania, joinowania. 
+ * Każda taka funkcja ma nazwę oraz może pobierać argumenty. 
+ * Część usług może być używana przez szynę podczas generowania query planu, np podczas joinowania szyna może użyć 
+ * dostępnych filtrów, aby wstępnie ograniczyć zbiory. 
+ * 
+ * 
+ * Czyli np katalog użytkowników może mieć filtry: 
+ *      "id", 
+ * "name", "age", "location". Z czego 
+ * 
+ * 
+ * @author Ranides Atterwim <ranides@gmail.com>
+ */
+public interface EQList {
+    
+    EQOrigin origin();
+    
+    long qid();
+    
+    List<Object> list();
+    
+    Stream<Object> stream();
+    
+    CQuery<Object> cstream();
+    
+    EQList filter(String name, Object... params);
+
+    EQList map(String name, Object... params);
+    
+    EQList join(EQList list);
+    
+    EQList join(String name, EQList list);
+    
+}

+ 5 - 6
assira.drafts/src/main/java/net/ranides/assira/reflection/OtherLambda.java

@@ -5,16 +5,15 @@
  * @url http://ranides.net/projects/assira.drafts
  */
 
-package net.ranides.assira.reflection;
+package net.ranides.esb.query;
 
 /**
  *
  * @author Ranides Atterwim <ranides@gmail.com>
  */
-public class OtherLambda {
+public interface EQOrigin {
 
-	public static Character flow(String v) {
-		return 'a';
-	}
-	
+    String name();
+    
+    
 }